Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^6: Writing to a file atomically without renaming

by waswas-fng (Curate)
on Jun 30, 2005 at 23:22 UTC ( #471509=note: print w/replies, xml ) Need Help??

in reply to Re^5: Writing to a file atomically without renaming
in thread Writing to a file atomically without renaming

backup_file has different perms because you copied the file to a new file as a different user. I am not saying backup_file is gone if you hit that case -- only that you end up in a situation where your app or the other apps that use that file are looking at corrupt data (they don't know about backup_file). cat backup_file > file does the following:
trunc file. # this is where you have the race condition. redirects the data in backup_file to file. closes file


Replies are listed 'Best First'.
Re^7: Writing to a file atomically without renaming
by Transient (Hermit) on Jul 01, 2005 at 02:45 UTC
    Quite right... which is what I stated here, no argument from me.

    Worst case scenario the cat of the backup_file to temp_file fails and you're left with a corrupt "file" and the extra "backup_file" which would have to be moved back manually.

    Although moving the file over is another option in the case that this exception handling fails.. even if it does clobber the options, you can chmod it to at the least be group rw (or whatever it was before).


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-02-08 07:41 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.