1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 06:33:59 +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): if not os.path.isdir(in_fs):
# is a file # is a file
self.log.dbg(f'{in_fs} is 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: else:
# is a dir # is a dir
if os.path.exists(srcf): if os.path.exists(srcf):
shutil.rmtree(srcf) shutil.rmtree(srcf)
self.log.dbg(f'{in_fs} is dir') self.log.dbg(f'{in_fs} is dir')
copytree_with_ign(in_fs, srcf, if not copytree_with_ign(in_fs, srcf,
ignore_func=self._ignore, ignore_func=self._ignore,
debug=self.debug) debug=self.debug):
self.log.err(f'importing \"{in_fs}\" failed')
return False
except shutil.Error as exc: except shutil.Error as exc:
in_dotpath = exc.args[0][0][0] in_dotpath = exc.args[0][0][0]
why = exc.args[0][0][2] why = exc.args[0][0][2]

View File

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

View File

@@ -333,8 +333,9 @@ def copyfile(src, dst, debug=False):
""" """
copy file from src to dst copy file from src to dst
no dir expected! 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): def copytree_with_ign(src, dst, ignore_func=None, debug=False):