Merge pull request #1752 from ei-grad/unprotect-improvement

unprotect: copy should preceed the move
This commit is contained in:
Ruslan Kuprieiev
2019-03-19 19:36:34 +02:00
committed by GitHub
+7 -4
View File
@@ -13,13 +13,16 @@ from dvc.exceptions import DvcException
def _unprotect_file(path):
if System.is_symlink(path) or System.is_hardlink(path):
logger.debug("Unprotecting '{}'".format(path))
tmp = os.path.join(os.path.dirname(path), "." + str(uuid.uuid4()))
move(path, tmp)
copyfile(tmp, path)
# The operations order is important here - if some application would
# access the file during the process of copyfile then it would get
# only the part of file. So, at first, the file should be copied with
# the temporary name, and then original file should be replaced by new.
copyfile(path, tmp)
remove(path)
move(tmp, path)
remove(tmp)
else:
logger.debug(
"Skipping copying for '{}', since it is not "