cedric-vincent/PRoot — pull request #28 by corbinlc (2013-10-30 16:42:03+00:00)
Title: make link2symlink clean up after itself

1) switch to a file prefix naming scheme, with a prefix of ".l2s.". This makes the response to "ls" less cluttered and hides the nuts and bolts of this from the user.

2) make it so there is an intermediate file and a final file. All hard links will point at the intermediate file and the intermediate file will point at the final one. The final one will get renamed based on the number of links to it. When a link is added, this count is incremented. When a link is deleted, this count is decremented. If that count is 1 and it is being decremented, the intermediate and final files are also deleted.
This makes it so, it cleans up after itself. This is nice, but it is also necessary. If it doesn't clean up after itself and some does this:
echo "hi" > testln1
ln testln1 testln2
rm testln*
echo "hi" > testln1
ln testln1 testln2
It will fail because it will try to move testln1 to .l2s.testln1, but there is already a file there.