# HG changeset patch # User Martin Geisler # Date 2011-11-24 17:13:18 # Node ID 926bc23d0b6ab47803497e9977b1945340d7e574 # Parent 809788118aa26d6220815d5d2239305428b8e609 largefiles: copy files into .hg/largefiles atomically Copying from the user cache into .hg/largefiles could fail halfway though with a partially written file. diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py --- a/hgext/largefiles/lfutil.py +++ b/hgext/largefiles/lfutil.py @@ -77,8 +77,11 @@ def link(src, dest): try: util.oslink(src, dest) except OSError: - # if hardlinks fail, fallback on copy - shutil.copyfile(src, dest) + # if hardlinks fail, fallback on atomic copy + dst = util.atomictempfile(dest) + for chunk in util.filechunkiter(open(src)): + dst.write(chunk) + dst.close() os.chmod(dest, os.stat(src).st_mode) def usercachepath(ui, hash): diff --git a/tests/test-largefiles-small-disk.t b/tests/test-largefiles-small-disk.t --- a/tests/test-largefiles-small-disk.t +++ b/tests/test-largefiles-small-disk.t @@ -15,6 +15,10 @@ Test how largefiles abort in case the di > yield f.read(4) > raise IOError(errno.ENOSPC, os.strerror(errno.ENOSPC)) > util.filechunkiter = filechunkiter + > # + > def oslink(src, dest): + > raise OSError("no hardlinks, try copying instead") + > util.oslink = oslink > EOF $ echo "[extensions]" >> $HGRCPATH @@ -37,3 +41,28 @@ The user cache is not even created: >>> import os; os.path.exists("$HOME/.cache/largefiles/") False + +Make the commit with space on the device: + + $ hg commit -m big + +Now make a clone with a full disk, and make sure lfutil.link function +makes copies instead of hardlinks: + + $ cd .. + $ hg --config extensions.criple=$TESTTMP/criple.py clone --pull alice bob + requesting all changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 1 changes to 1 files + updating to branch default + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + getting changed largefiles + abort: No space left on device + [255] + +The largefile is not created in .hg/largefiles: + + $ ls bob/.hg/largefiles + dirstate