Skip to content

Commit 64d481e

Browse files
authored
Fix reverse mapping to set basename & ensure filenames are preserved. (#527)
* Fix reverse mapping to set basename & ensure filenames are preserved. * Remove spurious Docker volume mount of runtime-created files.
1 parent 4c68e87 commit 64d481e

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

cwltool/draft2tool.py

+18-21
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,35 @@ def revmap_file(builder, outdir, f):
119119
# builder.outdir is the inner (container/compute node) output directory
120120
# outdir is the outer (host/storage system) output directory
121121

122-
if "location" in f:
122+
if "location" in f and "path" not in f:
123123
if f["location"].startswith("file://"):
124-
path = convert_pathsep_to_unix(uri_file_path(f["location"]))
125-
revmap_f = builder.pathmapper.reversemap(path)
126-
127-
if revmap_f and not builder.pathmapper.mapper(revmap_f[0]).type.startswith("Writable"):
128-
f["basename"] = os.path.basename(path)
129-
f["location"] = revmap_f[1]
130-
elif path == builder.outdir:
131-
f["location"] = outdir
132-
elif path.startswith(builder.outdir):
133-
f["location"] = builder.fs_access.join(outdir, path[len(builder.outdir) + 1:])
134-
elif f["location"].startswith(outdir):
135-
revmap_f = builder.pathmapper.reversemap(builder.fs_access.join(builder.outdir, f["location"][len(outdir) + 1:]))
136-
if revmap_f and not builder.pathmapper.mapper(revmap_f[0]).type.startswith("Writable"):
137-
f["basename"] = os.path.basename(path)
138-
f["location"] = revmap_f[1]
139-
return f
124+
f["path"] = convert_pathsep_to_unix(uri_file_path(f["location"]))
125+
else:
126+
return f
140127

141128
if "path" in f:
142129
path = f["path"]
130+
uripath = file_uri(path)
143131
del f["path"]
132+
133+
if "basename" not in f:
134+
f["basename"] = os.path.basename(path)
135+
144136
revmap_f = builder.pathmapper.reversemap(path)
145-
if revmap_f:
137+
138+
if revmap_f and not builder.pathmapper.mapper(revmap_f[0]).type.startswith("Writable"):
146139
f["location"] = revmap_f[1]
147-
return f
148-
elif path.startswith(builder.outdir):
140+
elif uripath == outdir or uripath.startswith(outdir+os.sep):
141+
f["location"] = file_uri(path)
142+
elif path == builder.outdir or path.startswith(builder.outdir+os.sep):
149143
f["location"] = builder.fs_access.join(outdir, path[len(builder.outdir) + 1:])
150-
return f
144+
elif not os.path.isabs(path):
145+
f["location"] = builder.fs_access.join(outdir, path)
151146
else:
152147
raise WorkflowException(u"Output file path %s must be within designated output directory (%s) or an input "
153148
u"file pass through." % (path, builder.outdir))
149+
return f
150+
154151

155152
raise WorkflowException(u"Output File object is missing both `location` and `path` fields: %s" % f)
156153

cwltool/job.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ def add_volumes(self, pathmapper, runtime, stage_output):
342342
createtmp = os.path.join(host_outdir, os.path.basename(vol.target))
343343
with open(createtmp, "wb") as f:
344344
f.write(vol.resolved.encode("utf-8"))
345-
runtime.append(u"--volume=%s:%s:ro" % (docker_windows_path_adjust(createtmp), docker_windows_path_adjust(vol.target)))
345+
if not vol.target.startswith(container_outdir):
346+
runtime.append(u"--volume=%s:%s:ro" % (docker_windows_path_adjust(createtmp), docker_windows_path_adjust(vol.target)))
346347

347348

348349
def run(self, pull_image=True, rm_container=True,

0 commit comments

Comments
 (0)