Mercurial > public > mercurial-scm > hg-stable
diff hgext/largefiles/lfutil.py @ 26823:45e8bd2f36f0 stable
largefiles: check hash of files in the store before copying to working dir
If the store somehow got corrupted, users could end up in weird situations that
were very hard to recover from or lead to propagation of the corruption.
Instead, spend the extra time checking the hash when copying to the working
directory. If it doesn't match, emit a warning, and don't put wrong content in
the working directory.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 23 Oct 2015 21:27:29 +0200 |
parents | b68797f244e4 |
children | 512a814c5595 |
line wrap: on
line diff
--- a/hgext/largefiles/lfutil.py Fri Oct 23 21:27:29 2015 +0200 +++ b/hgext/largefiles/lfutil.py Fri Oct 23 21:27:29 2015 +0200 @@ -10,7 +10,6 @@ import os import platform -import shutil import stat import copy @@ -207,7 +206,15 @@ util.makedirs(os.path.dirname(repo.wjoin(filename))) # The write may fail before the file is fully written, but we # don't use atomic writes in the working copy. - shutil.copy(path, repo.wjoin(filename)) + dest = repo.wjoin(filename) + with open(path, 'rb') as srcfd: + with open(dest, 'wb') as destfd: + gothash = copyandhash(srcfd, destfd) + if gothash != hash: + repo.ui.warn(_('%s: data corruption in %s with hash %s\n') + % (filename, path, gothash)) + util.unlink(dest) + return False return True def copytostore(repo, rev, file, uploaded=False):