Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,28 @@ def _relocate(src: str, dst: str) -> None:
return

# If the source is not contained in source_directories we're not allowed to delete it
src = fs_access.realpath(src)
real_src = fs_access.realpath(src)
src_can_deleted = any(
os.path.commonprefix([p, src]) == p for p in source_directories
os.path.commonprefix([p, real_src]) == p for p in source_directories
)

_action = "move" if action == "move" and src_can_deleted else "copy"

if _action == "move":
_logger.debug("Moving %s to %s", src, dst)
if fs_access.isdir(src) and fs_access.isdir(dst):
# merge directories
for dir_entry in scandir(src):
_relocate(dir_entry.path, fs_access.join(dst, dir_entry.name))
if fs_access.isdir(src):
if fs_access.isdir(dst):
if len(fs_access.listdir(dst)) > 0:
# merge directories
for dir_entry in scandir(src):
_relocate(
dir_entry.path, fs_access.join(dst, dir_entry.name)
)
else:
os.rmdir(dst)
shutil.move(src, dst)
else:
shutil.move(src, dst)
else:
shutil.move(src, dst)

Expand Down
14 changes: 14 additions & 0 deletions tests/symlinks.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: CommandLineTool
inputs: []
baseCommand: [ bash, -c ]
arguments:
# - "mkdir foo; echo 42 > foo/bar; ln -s bar foo/baz"
- "mkdir foo; echo 42 > foo/bar; ln -s $PWD/foo/bar foo/baz"
# - "mkdir foo; ln -s $PWD/foo/bar foo/baz ; echo 42 > foo/bar"
outputs:
result:
type: Directory
outputBinding:
glob: foo
20 changes: 16 additions & 4 deletions tests/test_relocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from .util import get_data, needs_docker

if sys.version_info[0] < 3:
from StringIO import StringIO
else:
from io import StringIO
from io import StringIO


@needs_docker
Expand All @@ -18,6 +15,21 @@ def test_for_910() -> None:
assert main([get_data("tests/wf/910.cwl")]) == 0


def test_symlinks_with_absolute_paths(tmp_path: Path) -> None:
"""Confirm that absolute paths in Directory types don't cause problems."""
assert (
main(
[
"--debug",
f"--outdir={tmp_path}/result",
f"--tmpdir-prefix={tmp_path}/tmp",
get_data("tests/symlinks.cwl"),
]
)
== 0
)


@needs_docker
def test_for_conflict_file_names(tmp_path: Path) -> None:
stream = StringIO()
Expand Down