terrasync.py: two improvements
- Refuse to recursively delete a directory that does not contain a .dirindex file. This will protect users against data loss in case they inadvertently use the --remove-orphan option with the wrong target directory. - Correctly handle the case where we have a file on disk that is now listed as a directory on the server: remove the file if we are in 'sync' mode, so that the directory can be created and sync'ed from the server.
This commit is contained in:
parent
3f2ee2de04
commit
c5e45f2b49
1 changed files with 6 additions and 1 deletions
|
@ -80,7 +80,10 @@ def removeDirectoryTree(base, whatToRemove):
|
||||||
"Unexpected base path for removeDirectoryTree(): {!r}".format(base)
|
"Unexpected base path for removeDirectoryTree(): {!r}".format(base)
|
||||||
absPath = os.path.abspath(whatToRemove)
|
absPath = os.path.abspath(whatToRemove)
|
||||||
|
|
||||||
if _removeDirectoryTree_dangerous_cre.match(absPath):
|
if not os.path.isfile(join(absPath, ".dirindex")):
|
||||||
|
raise UserError("refusing to recursively delete '{}' because "
|
||||||
|
"it does not contain a .dirindex file".format(absPath))
|
||||||
|
elif _removeDirectoryTree_dangerous_cre.match(absPath):
|
||||||
raise UserError("in order to protect your data, refusing to "
|
raise UserError("in order to protect your data, refusing to "
|
||||||
"recursively delete '{}'".format(absPath))
|
"recursively delete '{}'".format(absPath))
|
||||||
else:
|
else:
|
||||||
|
@ -540,6 +543,8 @@ class TerraSync:
|
||||||
if not self.quick:
|
if not self.quick:
|
||||||
self.handleDirindexFile(localDirIndex)
|
self.handleDirindexFile(localDirIndex)
|
||||||
elif self.inSyncMode():
|
elif self.inSyncMode():
|
||||||
|
if os.path.isfile(localFullPath):
|
||||||
|
os.unlink(localFullPath) # file on server became a directory
|
||||||
if not os.path.exists(localFullPath):
|
if not os.path.exists(localFullPath):
|
||||||
os.makedirs(localFullPath)
|
os.makedirs(localFullPath)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue