Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
No such thing as a small change
 
PerlMonks  

Re: Best practices for modifying a file in place: q's about opening files, file locking, and using the rename function

by fmerges (Chaplain)
on Nov 02, 2006 at 20:14 UTC ( [id://581986]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Best practices for modifying a file in place: q's about opening files, file locking, and using the rename function

Hi,

If you write all the programs that write to the files, you can use locks, but take care, file locks is not a real restriction, you can ignore it if you want

The temporary file, is the $new one, which after doing the stuff you need to do is renamed to the same name as the old. This is not very clean, I would use some control version system, the well known RCS would be enough, you don't need CVS or SVN for simple stuff.

For this kind of problem, take a look at some wiki, for example kwiki, they needed also to solve this issue, mean, more than one client wants to make an update.

Here you can read more info about file locking with perl.

Regards,

fmerges at irc.freenode.net
  • Comment on Re: Best practices for modifying a file in place: q's about opening files, file locking, and using the rename function

Replies are listed 'Best First'.
Re^2: Best practices for modifying a file in place: q's about opening files, file locking, and using the rename function
by ikegami (Patriarch) on Nov 02, 2006 at 23:34 UTC

    If you write all the programs that write to the files, you can use locks, but take care, file locks is not a real restriction, you can ignore it if you want

    Not necessarily. Some OSes (Windows, for example) have mandatory locks (as opposed to advisory locks).

      Hi,

      You're right, but I wasn't talking in general sense, 'cause the code snippet pasted was written in some UN*X... ;-)

      Regards,

      fmerges at irc.freenode.net

      Even the "mandatory" locks on Windows' aren't infallible when you get into network shared filesystems, especially SMB/Samba connections, because the whole modification stack isn't under one machine's control. You are right: they profess to be mandatory and cause you grief if you ignore them, but they cause you grief anyway when the remote system does unexpected things.

      --
      [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://581986]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.