Skip to content

Commit b799776

Browse files
committed
Fix tests
1 parent 1048259 commit b799776

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

SCons/Defaults.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ def copy_func(dest, src, symlinks: bool=True) -> int:
291291

292292
elif os.path.islink(src):
293293
if symlinks:
294-
os.symlink(os.readlink(src), dest)
294+
try:
295+
os.symlink(os.readlink(src), dest)
296+
except FileExistsError:
297+
raise SCons.Errors.BuildError(
298+
errstr=(
299+
f'Error: Copy() called to create symlink at "{dest}",'
300+
' but a file already exists at that location.'
301+
)
302+
)
295303
return 0
296304

297305
return copy_func(dest, os.path.realpath(src))

SCons/Node/FS.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,11 @@ def LocalString(target, source, env) -> str:
326326

327327
def UnlinkFunc(target, source, env) -> int:
328328
t = target[0]
329-
t.fs.unlink(t.get_abspath())
329+
file = t.get_abspath()
330+
try:
331+
t.fs.unlink(file)
332+
except FileNotFoundError:
333+
pass
330334
return 0
331335

332336
Unlink = SCons.Action.Action(UnlinkFunc, None)
@@ -3185,12 +3189,16 @@ def remove(self):
31853189
return None
31863190

31873191
def do_duplicate(self, src):
3192+
"""Create a duplicate of this file from the specified source."""
31883193
self._createDir()
31893194
if SCons.Node.print_duplicate:
31903195
print(f"dup: relinking variant '{self}' from '{src}'")
31913196
Unlink(self, None, None)
3192-
e = Link(self, src, None)
3193-
if isinstance(e, SCons.Errors.BuildError):
3197+
try:
3198+
e = Link(self, src, None)
3199+
if isinstance(e, SCons.Errors.BuildError):
3200+
raise e
3201+
except SCons.Errors.BuildError as e:
31943202
raise SCons.Errors.StopError(f"Cannot duplicate `{src.get_internal_path()}' in `{self.dir._path}': {e.errstr}.")
31953203
self.linked = 1
31963204
# The Link() action may or may not have actually

0 commit comments

Comments
 (0)