@@ -2446,18 +2446,33 @@ def copy_file(path, target_path, force_in_dry_run=False):
24462446 except OSError as err :
24472447 # catch the more general OSError instead of PermissionError, since python2 doesn't support
24482448 # PermissionError
2449+ if not os .stat (path ).st_mode & stat .S_IWUSR :
2450+ # failure not due to read-only file
2451+ raise EasyBuildError ("Failed to copy file %s to %s: %s" , path , target_path , err )
2452+
24492453 pyver = LooseVersion (platform .python_version ())
24502454 if pyver >= LooseVersion ('3.7' ):
24512455 raise EasyBuildError ("Failed to copy file %s to %s: %s" , path , target_path , err )
24522456 elif LooseVersion ('3.7' ) > pyver >= LooseVersion ('3' ):
24532457 if not isinstance (err , PermissionError ):
24542458 raise EasyBuildError ("Failed to copy file %s to %s: %s" , path , target_path , err )
2459+
24552460 # double-check whether the copy actually succeeded
24562461 if not os .path .exists (target_path ) or not filecmp .cmp (path , target_path , shallow = False ):
24572462 raise EasyBuildError ("Failed to copy file %s to %s: %s" , path , target_path , err )
2458- msg = ("%s copied to %s, ignoring permissions error (likely due to "
2459- "https://bugs.python.org/issue24538): %s" )
2460- _log .info (msg , path , target_path , err )
2463+
2464+ try :
2465+ # re-enable user write permissions in target, copy xattrs, then remove write perms again
2466+ adjust_permissions (target_path , stat .I_IWUSR )
2467+ shutil ._copyxattr (path , target_path )
2468+ adjust_permissions (target_path , stat .I_IWUSR , add = False )
2469+ except OSError as err :
2470+ raise EasyBuildError ("Failed to copy file %s to %s: %s" , path , target_path , err )
2471+
2472+ msg = ("Failed to copy extended attributes from file %s to %s, due to a bug in shutil (see "
2473+ "https://bugs.python.org/issue24538). Copy successful with workaround." )
2474+ _log .info (msg , path , target_path )
2475+
24612476 elif os .path .islink (path ):
24622477 if os .path .isdir (target_path ):
24632478 target_path = os .path .join (target_path , os .path .basename (path ))
0 commit comments