in reply to How does rename() work on read-only files?
For the benefit of everyone else, here's the description of the foo and bar files in the doc:
Look at this. Assume you are the owner of all files and directories listed, and that your umask (creation mask) is 022. directory filename file inode perms ---------- --------- ----------- ------ alpha . 100 0755 alpha foo 101 0644 alpha bar 102 0444 beta . 200 0555 beta foo 201 0644 beta bar 102 0444 Consider two directories, alpha and beta, each of which have the same two filenames, foo and bar. alpha/foo is really file #101, but beta/foo is really file #201 -- different files. However, the two bar filenames both refer to the same file, because both #102. It's just two links (filenames) to the same file.
When you run the command on foo, you can write to it (0644) so perl puts a copy in foo.bak and then overwrites what was in foo.*
When you run the command on bar, you cannot write to it (0444) so it requires a different strategy. Instead it renames bar to bar.bak as the backup and then writes to a brand new file bar with what would be the changes.
Does that help at all?
* Edit: having tested this myself it is not what I see for foo. I see that foo.bak has the inode of the old foo. Are you sure of your result?
Edit 2: Both operations proceed in the same way: rename the file to .bak and then create the new file.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How does rename() work on read-only files?
by j41r (Beadle) on Dec 11, 2018 at 10:30 UTC | |
by haukex (Archbishop) on Dec 11, 2018 at 10:59 UTC | |
by j41r (Beadle) on Dec 12, 2018 at 00:21 UTC | |
by hippo (Archbishop) on Dec 11, 2018 at 11:06 UTC | |
by j41r (Beadle) on Dec 12, 2018 at 00:28 UTC | |
by hippo (Archbishop) on Dec 12, 2018 at 09:26 UTC | |
by j41r (Beadle) on Dec 12, 2018 at 09:51 UTC |