Skip to content

Commit aec33fc

Browse files
authored
Remove temporary directories when cache dir is empty string (#1541)
* Remove temporary directories when cache dir is empty string * Add unit test to confirm tmpdir is cleared
1 parent 96ebb49 commit aec33fc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cwltool/executors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def check_for_abstract_op(tool: CWLObjectType) -> None:
158158
)
159159

160160
if runtime_context.rm_tmpdir:
161-
if runtime_context.cachedir is None:
161+
if not runtime_context.cachedir:
162162
output_dirs = self.output_dirs # type: Iterable[str]
163163
else:
164164
output_dirs = filter(

tests/test_tmpdir.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from cwltool.context import LoadingContext, RuntimeContext
1515
from cwltool.docker import DockerCommandLineJob
1616
from cwltool.job import JobBase
17+
from cwltool.main import main
1718
from cwltool.pathmapper import MapperEnt, PathMapper
1819
from cwltool.stdfsaccess import StdFsAccess
1920
from cwltool.update import INTERNAL_VERSION, ORIGINAL_CWLVERSION
@@ -230,3 +231,20 @@ def test_runtimeContext_respects_tmp_outdir_prefix(tmp_path: Path) -> None:
230231
runtime_context = RuntimeContext({"tmp_outdir_prefix": tmpdir_prefix})
231232
assert runtime_context.get_outdir().startswith(tmpdir_prefix)
232233
assert runtime_context.create_outdir().startswith(tmpdir_prefix)
234+
235+
236+
def test_remove_tmpdirs(tmp_path: Path) -> None:
237+
"""Test that the tmpdirs are removed after the job execution."""
238+
assert (
239+
main(
240+
[
241+
"--tmpdir-prefix",
242+
str(f"{tmp_path}/"),
243+
get_data("tests/wf/hello_single_tool.cwl"),
244+
"--message",
245+
"Hello",
246+
]
247+
)
248+
== 0
249+
)
250+
assert len(list(tmp_path.iterdir())) == 0

0 commit comments

Comments
 (0)