Skip to content

Commit 0fb9d0a

Browse files
committed
Use os.makedirs to build tree in extract_file
Since baaede6, `is_compressed` returns `True` when expected. This forces `extract_file_request` to call `extract_file` to retrieve the file. This method was failing because `os.mkdir` is not able to create directories recursively. This commit uses `os.makedirs` instead.
1 parent 85658e1 commit 0fb9d0a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

storage_service/locations/models/package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,14 +1633,14 @@ def extract_file(self, relative_path="", extract_path=None):
16331633
# copy only one file out of aip
16341634
head, tail = os.path.split(full_path)
16351635
src = os.path.join(head, relative_path)
1636-
os.mkdir(os.path.join(extract_path, basename))
1636+
os.makedirs(os.path.dirname(output_path))
1637+
LOGGER.info("Copying from: %s to %s", src, output_path)
16371638
shutil.copy(src, output_path)
16381639
else:
16391640
src = full_path
1641+
LOGGER.info("Copying from: %s to %s", full_path, output_path)
16401642
shutil.copytree(full_path, output_path)
16411643

1642-
LOGGER.info("Copying from: %s to %s", src, output_path)
1643-
16441644
if not relative_path:
16451645
self.local_path_location = ss_internal
16461646
self.local_path = output_path

storage_service/locations/tests/test_package.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,18 @@ def test_extract_file_file_from_uncompressed_aip(self):
448448
assert output_path == os.path.join(self.tmp_dir, basedir, "manifest-md5.txt")
449449
assert os.path.isfile(output_path)
450450

451+
def test_extract_file_nested_file_from_uncompressed_aip(self):
452+
""" It should return a single file from an uncompressed aip (with nested path) """
453+
package = models.Package.objects.get(
454+
uuid="0d4e739b-bf60-4b87-bc20-67a379b28cea"
455+
)
456+
basedir = package.get_base_directory()
457+
output_path, extract_path = package.extract_file(
458+
relative_path="working_bag/data/test.txt", extract_path=self.tmp_dir
459+
)
460+
assert output_path == os.path.join(self.tmp_dir, basedir, "data/test.txt")
461+
assert os.path.isfile(output_path)
462+
451463
def test_extract_file_file_from_compressed_aip(self):
452464
""" It should return a single file from a 7zip compressed aip """
453465
package = models.Package.objects.get(

0 commit comments

Comments
 (0)