[issue2351] hg update should write-to-tmp-then-rename for working files

Javi bugs at mercurial.selenic.com
Fri Aug 27 18:55:39 UTC 2010


New submission from Javi <cibervicho at gmail.com>:

Hi, this was reported in the debian BTS
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=495779):

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>

----------
messages: 13507
nosy: vicho
priority: wish
status: unread
title: hg update should write-to-tmp-then-rename for working files

____________________________________________________
Mercurial issue tracker <bugs at mercurial.selenic.com>
<http://mercurial.selenic.com/bts/issue2351>
____________________________________________________


More information about the Mercurial-devel mailing list