From 6d2c5ea59f177b1a2b14835c46b4c63048308b85 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 14 Nov 2023 21:26:15 +0100 Subject: [PATCH] check for copy return value --- dotdrop/importer.py | 12 ++++++++---- dotdrop/installer.py | 14 ++++++++++---- dotdrop/utils.py | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dotdrop/importer.py b/dotdrop/importer.py index 7ecf61c..cd9388f 100644 --- a/dotdrop/importer.py +++ b/dotdrop/importer.py @@ -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] diff --git a/dotdrop/installer.py b/dotdrop/installer.py index 39a2b18..22666a6 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -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""" diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 2704dbb..968eb4a 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -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):