Code factorisation
parent
b473e698f1
commit
310535f2b3
|
@ -147,30 +147,7 @@ def copy_file_or_directory(logger, path_dst, path_src, overwrite=True):
|
||||||
# Everything went well, time to remove the backup
|
# Everything went well, time to remove the backup
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
if overwrite:
|
if overwrite:
|
||||||
# As before, try it as a dir first
|
delete_file_or_dir((dst + ".bak"), logger)
|
||||||
try:
|
|
||||||
logger.info("Removing backup directory %s" % (dst + ".bak"))
|
|
||||||
shutil.rmtree(dst + ".bak")
|
|
||||||
|
|
||||||
except FileNotFoundError:
|
|
||||||
logger.warning("Backup file %s seems to be already gone"
|
|
||||||
% (dst + ".bak"))
|
|
||||||
except PermissionError:
|
|
||||||
logger.warning("Cannot remove backup dir %s, you will have to " \
|
|
||||||
"do it manually"
|
|
||||||
% (dst + ".bak"))
|
|
||||||
|
|
||||||
# If not, try it as a file
|
|
||||||
except NotADirectoryError:
|
|
||||||
try:
|
|
||||||
logger.info("Removing backup file %s" % (dst + ".bak"))
|
|
||||||
os.remove(dst + ".bak")
|
|
||||||
|
|
||||||
except PermissionError:
|
|
||||||
logger.warning("Cannot remove backup file %s, you will have " \
|
|
||||||
"to do it manually"
|
|
||||||
% (dst + ".bak"))
|
|
||||||
|
|
||||||
|
|
||||||
# The End.
|
# The End.
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue