/etc versioning (was Re: [patch] Cross-dev error, /etc versioning)
John Arbash Meinel
john at arbash-meinel.com
Tue Dec 16 18:27:45 GMT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Barry Warsaw wrote:
> On Dec 15, 2008, at 9:43 PM, Martin Pool wrote:
>
>>> P.S. If someone wants to know details about correct /etc versioning,
>>> with
>>> permissions handling, feel free to ask (preferably using this list).
>
> I'm interested. I currently version all my /etc with svn, which was a
> royal pain to set up, but done years ago. I've been meaning to convert
> to bzr so any tips you have would be appreciated.
>
> -Barry
>
I'll just mention that doing open(foo, 'wb').write(open(source,
'rb').read()) also breaks the atomicity of the action. If you cancel
while that is happening the target file will have half of the data
written, and all of the original data will be lost.
So, for example, if you had a file with some local uncommitted changes,
and did "bzr update" it would then attempt to merge the upstream changes
in with your uncommitted changes, and then write that back to the file.
If you interrupted it, you would not have any way to get back the
uncommitted changes.
shutil.move() also behaves the same way. If you follow the code, using
shutil.move() would actually try os.rename() again, which is a bit
superfluous. So I would recommend using just shutil.copyfile() or
shutil.copy2().
Anyway, the reason we didn't support cross-mount-point was because there
isn't a way to do it atomically (where either you have the original or
the final, but you are never in a situation where you have partial-data
written that would be corrupted if you cancelled in the middle.)
Doing it only on EXDEV at least means we preserve atomicity in all other
cases, so I'm ok with this, but I'm not particularly happy.
If we really wanted, we could copy the file over into the target device,
and then use rename again.
So as a conclusion...
At a minimum we should be using shutil.copy... instead of doing it
directly (it appropriately uses try/finally statements to avoid leaking
file handles, etc).
I'd also like it clearly stated (possibly just in NEWS) that
cross-devices updates are now supported, but they are not atomic like
single-device is.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAklH8yEACgkQJdeBCYSNAAPJkACffjb4T76TVO9mIKXSmqCQu5c2
tHkAnRvAoPbkhpyxoEvY/1lUrVy2jA0F
=yYQe
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list