1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 20:54:51 +00:00

check for copy return value

This commit is contained in:
deadc0de6
2023-11-14 21:26:15 +01:00
parent 2712eb5368
commit 6d2c5ea59f
3 changed files with 20 additions and 9 deletions

View File

@@ -249,15 +249,19 @@ class Importer:
if not os.path.isdir(in_fs):
# is a file
self.log.dbg(f'{in_fs} is file')
copyfile(in_fs, srcf, debug=self.debug)
if not copyfile(in_fs, srcf, debug=self.debug):
self.log.err(f'importing \"{in_fs}\" failed')
return False
else:
# is a dir
if os.path.exists(srcf):
shutil.rmtree(srcf)
self.log.dbg(f'{in_fs} is dir')
copytree_with_ign(in_fs, srcf,
ignore_func=self._ignore,
debug=self.debug)
if not copytree_with_ign(in_fs, srcf,
ignore_func=self._ignore,
debug=self.debug):
self.log.err(f'importing \"{in_fs}\" failed')
return False
except shutil.Error as exc:
in_dotpath = exc.args[0][0][0]
why = exc.args[0][0][2]

View File

@@ -484,7 +484,8 @@ class Installer:
# remove symlink
if self.backup and not os.path.isdir(dst):
self._backup(dst)
if not self._backup(dst):
return False, f'could not backup {dst}'
overwrite = True
try:
removepath(dst)
@@ -770,7 +771,8 @@ class Installer:
overwrite = True
if self.backup:
self._backup(dst)
if not self._backup(dst):
return False, f'could not backup {dst}'
else:
self.log.dbg(f'file does not exist on filesystem: {dst}')
@@ -869,16 +871,20 @@ class Installer:
def _backup(self, path):
"""backup file pointed by path"""
if self.dry:
return
return True
dst = path.rstrip(os.sep) + self.backup_suffix
self.log.log(f'backup {path} to {dst}')
# os.rename(path, dst)
# copy to preserve mode on chmod=preserve
# since we expect dotfiles this shouldn't have
# such a big impact but who knows.
copyfile(path, dst, debug=self.debug)
if not copyfile(path, dst, debug=self.debug):
return False
if not os.path.exists(dst):
return False
stat = os.stat(path)
os.chown(dst, stat.st_uid, stat.st_gid)
return True
def _exec_pre_actions(self, actionexec):
"""execute action executor"""

View File

@@ -333,8 +333,9 @@ def copyfile(src, dst, debug=False):
"""
copy file from src to dst
no dir expected!
returns True if file was copied
"""
_cp(src, dst, debug=debug)
return _cp(src, dst, debug=debug) == 1
def copytree_with_ign(src, dst, ignore_func=None, debug=False):