Mercurial > public > mercurial-scm > hg
diff hgext/largefiles/lfutil.py @ 15572:926bc23d0b6a stable
largefiles: copy files into .hg/largefiles atomically
Copying from the user cache into .hg/largefiles could fail halfway
though with a partially written file.
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Thu, 24 Nov 2011 18:13:18 +0100 |
parents | 809788118aa2 |
children | c9328c829cd9 971c55ce03b8 |
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py Thu Nov 24 18:12:13 2011 +0100 +++ b/hgext/largefiles/lfutil.py Thu Nov 24 18:13:18 2011 +0100 @@ -77,8 +77,11 @@ 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):