Skip to content

Commit ff84d44

Browse files
authored
Fix revmap (#206)
* Reverse mapping output file objects correctly handles "location" fields with container-internal file:// references. * Ensure that "location" field is URI with scheme and delete path field after we're done with it.
1 parent 74198c3 commit ff84d44

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

cwltool/draft2tool.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,43 @@ def remove_path(f): # type: (Dict[Text, Any]) -> None
8080

8181
def revmap_file(builder, outdir, f):
8282
# type: (Builder, Text, Dict[Text, Any]) -> Union[Dict[Text, Any], None]
83-
"""Remap a file back to original path. For Docker, this is outside the container.
8483

85-
Uses either files in the pathmapper or remaps internal output directories
86-
to the external directory.
84+
"""Remap a file from internal path to external path.
85+
86+
For Docker, this maps from the path inside tho container to the path
87+
outside the container. Recognizes files in the pathmapper or remaps
88+
internal output directories to the external directory.
8789
"""
8890

91+
split = urlparse.urlsplit(outdir)
92+
if not split.scheme:
93+
outdir = "file://" + outdir
94+
8995
if "location" in f:
96+
if f["location"].startswith("file://"):
97+
path = f["location"][7:]
98+
revmap_f = builder.pathmapper.reversemap(path)
99+
if revmap_f:
100+
f["location"] = revmap_f[1]
101+
elif path.startswith(builder.outdir):
102+
f["location"] = builder.fs_access.join(outdir, path[len(builder.outdir)+1:])
90103
return f
91104

92-
revmap_f = builder.pathmapper.reversemap(f["path"])
93-
if revmap_f:
94-
f["location"] = revmap_f[1]
95-
return f
96-
elif f["path"].startswith(builder.outdir):
97-
f["location"] = builder.fs_access.join(outdir, f["path"][len(builder.outdir)+1:])
98-
return f
99-
else:
100-
raise WorkflowException(u"Output file path %s must be within designated output directory (%s) or an input file pass through." % (f["path"], builder.outdir))
105+
if "path" in f:
106+
path = f["path"]
107+
del f["path"]
108+
revmap_f = builder.pathmapper.reversemap(path)
109+
if revmap_f:
110+
f["location"] = revmap_f[1]
111+
return f
112+
elif path.startswith(builder.outdir):
113+
f["location"] = builder.fs_access.join(outdir, path[len(builder.outdir)+1:])
114+
return f
115+
else:
116+
raise WorkflowException(u"Output file path %s must be within designated output directory (%s) or an input file pass through." % (path, builder.outdir))
117+
118+
raise WorkflowException(u"Output File object is missing both `location` and `path` fields: %s" % f)
119+
101120

102121
class CallbackJob(object):
103122
def __init__(self, job, output_callback, cachebuilder, jobcache):

0 commit comments

Comments
 (0)