Skip to content

Commit 50f7c35

Browse files
committed
style: make it obvious when files are moved or copied
1 parent 448ae30 commit 50f7c35

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

cwltool/process.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,21 @@ def _relocate(src, dst):
299299
if src == dst:
300300
return
301301

302-
_action = action
302+
# If the source is not contained in source_directories we're not allowed to delete it
303+
src_can_deleted = any(os.path.commonprefix([p, src]) == p for p in source_directories)
304+
305+
_action = "move" if action == "move" and src_can_deleted else "copy"
306+
303307
if _action == "move":
304-
# do not move anything if we are trying to move an entity from
305-
# outside of the source directories
306-
if any(os.path.commonprefix([path, src]) == path for path in source_directories):
307-
_logger.debug("Moving %s to %s", src, dst)
308-
if fs_access.isdir(src) and fs_access.isdir(dst):
309-
# merge directories
310-
for dir_entry in scandir(src):
311-
_relocate(dir_entry.path, fs_access.join(dst, dir_entry.name))
312-
else:
313-
shutil.move(src, dst)
308+
_logger.debug("Moving %s to %s", src, dst)
309+
if fs_access.isdir(src) and fs_access.isdir(dst):
310+
# merge directories
311+
for dir_entry in scandir(src):
312+
_relocate(dir_entry.path, fs_access.join(dst, dir_entry.name))
314313
else:
315-
# we still need the files at the destination, so let's copy them
316-
_action = "copy"
314+
shutil.move(src, dst)
317315

318-
if _action == "copy":
316+
elif _action == "copy":
319317
_logger.debug("Copying %s to %s", src, dst)
320318
if fs_access.isdir(src):
321319
if os.path.isdir(dst):

0 commit comments

Comments
 (0)