From 23b5b787caac930d3b408fc03f19fa51ba9051c4 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Wed, 18 Sep 2024 20:57:59 +0200 Subject: [PATCH] fix condition in copy_file when hitting PermissionError when copying read-only file --- easybuild/tools/filetools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/easybuild/tools/filetools.py b/easybuild/tools/filetools.py index 30d4ec34c4..973f83e1f5 100644 --- a/easybuild/tools/filetools.py +++ b/easybuild/tools/filetools.py @@ -2443,11 +2443,11 @@ def copy_file(path, target_path, force_in_dry_run=False): # see https://bugs.python.org/issue24538 shutil.copy2(path, target_path) _log.info("%s copied to %s", path, target_path) + # catch the more general OSError instead of PermissionError, + # since Python 2.7 doesn't support PermissionError except OSError as err: - # catch the more general OSError instead of PermissionError, since python2 doesn't support - # PermissionError - if not os.stat(path).st_mode & stat.S_IWUSR: - # failure not due to read-only file + # if file is writable (not read-only), then we give up since it's not a simple permission error + if os.path.exists(target_path) and os.stat(target_path).st_mode & stat.S_IWUSR: raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err) pyver = LooseVersion(platform.python_version())