[Python-apps-team] Bug#495779: hg update should write-to-tmp-then-rename for working files

Ian Jackson Ian.Jackson at eu.citrix.com
Wed Aug 20 11:33:07 UTC 2008


Package: mercurial
Version: 0.9.1-1+etch1

When mercurial updates files in the working tree, it should write the
new version to a temporary file and rename it into place (taking care
to copy permissions appropriately).

This would be useful:

 * To ensure that if the working tree is actually a deployed and
   executing copy of the code, programs running in that working tree
   will not have the files which they have open change under their
   feet.  This is particularly relevant for shell scripts, since the
   shell will not just read the whole file at startup.

 * To make more graceful failures when the disk is full.  I don't know
   what hg does right now if its attempt to update the working file
   fails.  There is obviously a risk that a truncated file might be
   committed, and attempts to `manually' recover from such things
   can be fraught with problems.

 * To avoid leaving truncated files if hg should get a fatal signal.

etc.

See transcript below for a demonstration.  For this test I just picked
an arbitrary hg tree I had lying around and an arbitrary recent
change.  The transcript shows that hg is overwriting the file in place
and demonstrates how a program (in this case the very shell I'm using)
which has the file open before the update can get unexpected results.

I hope that the fact that this is unfortunate is obvious without a
further demonstration but I can probably produce recipes for lossage
if necessary.

Ian.

mariner:xen-unstable.hg> ll -i xen/arch/x86/hvm/svm/svm.c 
98522 -rw-rw-r-- 1 iwj iwj 39898 Aug 20 12:23 xen/arch/x86/hvm/svm/svm.c
mariner:xen-unstable.hg> hg update 18330
8 files updated, 0 files merged, 0 files removed, 0 files unresolved
mariner:xen-unstable.hg> ll -i xen/arch/x86/hvm/svm/svm.c 
98522 -rw-rw-r-- 1 iwj iwj 39641 Aug 20 12:24 xen/arch/x86/hvm/svm/svm.c
mariner:xen-unstable.hg> exec 4<xen/arch/x86/hvm/svm/svm.c
mariner:xen-unstable.hg> cat <&4 | tail -2
 * End:
 */
mariner:xen-unstable.hg> cat <&4 | tail -2
mariner:xen-unstable.hg> hg update tip
8 files updated, 0 files merged, 0 files removed, 0 files unresolved
mariner:xen-unstable.hg> ll -i xen/arch/x86/hvm/svm/svm.c 
98522 -rw-rw-r-- 1 iwj iwj 39898 Aug 20 12:24 xen/arch/x86/hvm/svm/svm.c
mariner:xen-unstable.hg> cat <&4 | head -2
 >> 4;
}
mariner:xen-unstable.hg>





More information about the Python-apps-team mailing list