diff --git a/pyccc/files/directory.py b/pyccc/files/directory.py index ddadaaf..5d0eb08 100644 --- a/pyccc/files/directory.py +++ b/pyccc/files/directory.py @@ -79,11 +79,13 @@ def put(self, destination): members = [] for tarinfo in tf: # Get only files under the directory `self.dirname` - pathsplit = os.path.split(tarinfo.path) + pathsplit = os.path.normpath(tarinfo.path).split(os.sep) if pathsplit[0] not in valid_paths: print('WARNING: skipped file "%s" in archive; not in directory "%s"' % (tarinfo.path, self.dirname)) continue + if len(pathsplit) == 1: + continue tarinfo.name = os.path.join(*pathsplit[1:]) members.append(tarinfo) diff --git a/pyccc/tests/test_dir_refs.py b/pyccc/tests/test_dir_refs.py index a30e4cc..827512b 100644 --- a/pyccc/tests/test_dir_refs.py +++ b/pyccc/tests/test_dir_refs.py @@ -84,3 +84,18 @@ def test_put_directory_reference_with_renaming(request, fixturename, tmpdir, rel assert not mismatch assert not errors + +def test_get_directory_with_subdirs(tmpdir): + engine = pyccc.Docker() + + cmd = ("mkdir -p /opt/blah/fugu && echo a > /opt/blah/a" + " && echo b > /opt/blah/b && echo fish > /opt/blah/fugu/fish") + + job = engine.launch(image='alpine', + workingdir='/test', + command=cmd) + job.wait() + outdir = job.get_directory('/opt/blah') + outdir.put(tmpdir) + for path in ['a', 'b', 'fugu/fish']: + assert os.path.exists(os.path.join(tmpdir, 'blah', path))