Skip to content

Commit 9d84741

Browse files
authored
Merge pull request easybuilders#5142 from ocaisa/less_strict_copy
Be a bit more forgiving with `copy_file`
2 parents a33270f + 4543743 commit 9d84741

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

easybuild/tools/filetools.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import itertools
5050
import os
5151
import pathlib
52-
import platform
5352
import re
5453
import shutil
5554
import signal
@@ -65,7 +64,6 @@
6564
import urllib.request as std_urllib
6665

6766
from easybuild.base import fancylogger
68-
from easybuild.tools import LooseVersion
6967
# import build_log must stay, to use of EasyBuildLog
7068
from easybuild.tools.build_log import EasyBuildError, EasyBuildExit, CWD_NOTFOUND_ERROR
7169
from easybuild.tools.build_log import dry_run_msg, print_msg, print_warning
@@ -2550,14 +2548,12 @@ def copy_file(path, target_path, force_in_dry_run=False):
25502548
if os.path.exists(target_path) and os.stat(target_path).st_mode & stat.S_IWUSR:
25512549
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err)
25522550

2553-
pyver = LooseVersion(platform.python_version())
2554-
if pyver >= LooseVersion('3.7'):
2551+
# If we have anything other than a PermissionError we bail out
2552+
if not isinstance(err, PermissionError):
25552553
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err)
2556-
elif LooseVersion('3.7') > pyver >= LooseVersion('3'):
2557-
if not isinstance(err, PermissionError):
2558-
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err)
25592554

2560-
# double-check whether the copy actually succeeded
2555+
# double-check whether the copy actually succeeded (or may have already happened
2556+
# if the contents are the same)
25612557
if not os.path.exists(target_path) or not filecmp.cmp(path, target_path, shallow=False):
25622558
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err)
25632559

@@ -2569,8 +2565,10 @@ def copy_file(path, target_path, force_in_dry_run=False):
25692565
except OSError as err:
25702566
raise EasyBuildError("Failed to copy file %s to %s: %s", path, target_path, err)
25712567

2572-
msg = ("Failed to copy extended attributes from file %s to %s, due to a bug in shutil (see "
2573-
"https://bugs.python.org/issue24538). Copy successful with workaround.")
2568+
msg = ("In some cases, we may fail to copy extended attributes from file %s to %s, due to a "
2569+
"bug in shutil (see https://bugs.python.org/issue24538). We may also have already "
2570+
"copied the file over so we just check the contents and update the xattrs. "
2571+
"Copy successful with workaround.")
25742572
_log.info(msg, path, target_path)
25752573

25762574
elif os.path.islink(path):

0 commit comments

Comments
 (0)