Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(Guildenstern) RE: RE (tilly) 1: Creating a file with Open

by Guildenstern (Deacon)
on Oct 03, 2000 at 17:58 UTC ( #35099=note: print w/replies, xml ) Need Help??


in reply to RE (tilly) 1: Creating a file with Open
in thread Creating a file with Open

And btw that code for flocking will not give you the protection you want, open it "+<$user_name" or else it gets wiped out before you try to lock it.
I'm confused here. Everyone else has been saying "+>$user_name" which makes sense to me. Is your suggestion a typo, or am I missing something fundamental here?

Guildenstern
Negaterd character class uber alles!
  • Comment on (Guildenstern) RE: RE (tilly) 1: Creating a file with Open

Replies are listed 'Best First'.
RE (tilly) 3: Creating a file with Open
by tilly (Archbishop) on Oct 03, 2000 at 18:12 UTC
    My point is not a typo.

    Both "+<$user_name" and "+>$user_name" open the file for both reading and writing, but the first opens it for reading, and you can also write, while the second opens it for writing, but you can also read. Therefore the second wipes out the possibly existing file for you, while the first does not.

    Wiping out the file before you lock it and ensure it is not in use is unlikely to be desired. I call that, ERACE. (Sorry, didn't even try to hold that one back. :-)

    If this confuses you, just use sentinel files as in Simple Locking since I already dealt with all of this there.

    EDIT
    Somehow I said "suggestion" where I meant "typo". Fixed.

    EDIT 2
    Some days I should not post. Thanks isotope for pointing out I meant "while the first does not". *sigh*

RE: (Guildenstern) RE: RE (tilly) 1: Creating a file with Open
by merlyn (Sage) on Oct 03, 2000 at 18:12 UTC
    I'm confused here. Everyone else has been saying "+>$user_name" which makes sense to me. Is your suggestion a typo, or am I missing something fundamental here?
    No, not a typo. If you open something with +>, you are saying "zero out this file" before anything else happens. At that point, if someone else has the flock already, you are now erasing their work. You must open in a way that preserves any existing data, but if you're also going to write to it, you must use two-way mode, like +< or +>>.

    -- Randal L. Schwartz, Perl hacker

RE: (Guildenstern) RE: RE (tilly) 1: Creating a file with Open
by ncw (Friar) on Oct 03, 2000 at 23:46 UTC
    Opening the file "+>" will wipe it out, so flocking it is then pretty pointless - you destroy the file before you've gained the lock on it.

    You need to open the file "+<", if that failed then open it "+>" then flock it then truncate it if you want to be safe with your flocking in the presence of other readers.

    Note that if you want to read the file back in with flocking you need to use "+<" so that you open the file with write intent otherwise the flocking may not work properly (I don't understand the reasons for this but that is what it says in the man pages!)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://35099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2022-05-25 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (90 votes). Check out past polls.

    Notices?