Skip to content

Commit c070bfc

Browse files
committed
added fallback if linking fails in copy
1 parent cfd67f2 commit c070bfc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fileformats/core/fileset.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from warnings import warn
55
import inspect
66
import tempfile
7+
import errno
78
from copy import copy
89
from collections import Counter
910
import typing as ty
@@ -1545,7 +1546,15 @@ def hardlink_dir(src: Path, dest: Path) -> None:
15451546
if fspath.is_dir():
15461547
copy_dir(fspath, new_path)
15471548
else:
1548-
copy_file(fspath, new_path)
1549+
try:
1550+
copy_file(fspath, new_path)
1551+
except PermissionError as e:
1552+
if e.errno == errno.EPERM and copy_file is not shutil.copyfile: # type: ignore[comparison-overlap]
1553+
# Fallback to proper copy if the link fails for some reason
1554+
shutil.copyfile(fspath, new_path)
1555+
else:
1556+
raise
1557+
15491558
new_paths.append(new_path)
15501559
return type(self)(new_paths)
15511560

0 commit comments

Comments
 (0)