Skip to content

Commit 79d8d9b

Browse files
committed
better handle symlinks in Directories
1 parent 83f5fb7 commit 79d8d9b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

cwltool/process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ def _relocate(src: str, dst: str) -> None:
356356
return
357357

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

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

tests/symlinks.cwl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: CommandLineTool
4+
inputs: []
5+
baseCommand: [ bash, -c ]
6+
arguments:
7+
# - "mkdir foo; echo 42 > foo/bar; ln -s bar foo/baz"
8+
- "mkdir foo; echo 42 > foo/bar; ln -s $PWD/foo/bar foo/baz"
9+
# - "mkdir foo; ln -s $PWD/foo/bar foo/baz ; echo 42 > foo/bar"
10+
outputs:
11+
result:
12+
type: Directory
13+
outputBinding:
14+
glob: foo

tests/test_relocate.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
from .util import get_data, needs_docker
88

9-
if sys.version_info[0] < 3:
10-
from StringIO import StringIO
11-
else:
12-
from io import StringIO
9+
from io import StringIO
1310

1411

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

2017

18+
def test_symlinks_with_absolute_paths(tmp_path: Path) -> None:
19+
assert (
20+
main(
21+
[
22+
"--debug",
23+
f"--outdir={tmp_path}/result",
24+
"--tmpdir-prefix={tmp_path}/tmp",
25+
get_data("tests/symlinks.cwl"),
26+
]
27+
)
28+
== 0
29+
)
30+
31+
2132
@needs_docker
2233
def test_for_conflict_file_names(tmp_path: Path) -> None:
2334
stream = StringIO()

0 commit comments

Comments
 (0)