[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Safe File Update (atomic)

On 30/12/10 17:17, Olaf van der Spek wrote:
On Thu, Dec 30, 2010 at 4:12 PM, Shachar Shemesh<shachar@debian.org>  wrote:
No. I was doing it as code to accompany an article on my company's site
about how it should be done. I was originally out to write the article, and
then decided to add code. A good thing, too, as recursively resolving
symbolic links is not trivial. There is an extremely simple way to do it on
Linux, but it will not work on all platforms (the *BSD platforms, including
Mac, do not have /proc by default).
Depending on /proc is probably not reasonable.
Are you sure it will be atomic? ;)

open old file, get fd (we'll assume it's 5). Do readlink on /proc/self/fd/5, and get file's real path. Do everything in said path. It's atomic, in the sense that the determining point in time is the point in which you opened the old file.

How do you preserve owner (as non-root)?

I thought I answered that. Best effort. You perform the chown, but do not bother with the return code. If it succeeded, great. If not, well, you did your best.

The reason I asked for a kernelland solution is because it's hard if
not impossible to do properly in userland. But some kernel devs (Ted
and others) don't agree. They reason that the desire to preserve all
meta-data isn't reasonable by itself.
I'm with Henrique on that one. I am more concerned with the amount of non-Posix code that needs to go into this than preserving all attributes.


Shachar Shemesh
Lingnu Open Source Consulting Ltd.

Reply to: