Commit e48ed9bb authored by David Sikter's avatar David Sikter
Browse files

Fixes bug in raw_directory_list when there are files in the root directory

parent 19e5eece
Pipeline #119302 passed with stages
in 31 minutes and 51 seconds
......@@ -1257,15 +1257,16 @@ class PublicUploadFiles(UploadFiles):
directory_path = os.path.dirname(path)
size = zf.getinfo(path).file_size if file_name else 0
# Ensure that all parent directories are added
sub_path = ''
for directory in directory_path.split(os.path.sep):
sub_path_next = os.path.join(sub_path, directory)
if sub_path_next not in self._directories:
self._directories[sub_path_next] = {}
directory_sizes.setdefault(sub_path_next, 0)
directory_sizes[sub_path_next] += size
sub_path = sub_path_next
if directory_path:
# Ensure that all parent directories are added
sub_path = ''
for directory in directory_path.split(os.path.sep):
sub_path_next = os.path.join(sub_path, directory)
if sub_path_next not in self._directories:
self._directories[sub_path_next] = {}
directory_sizes.setdefault(sub_path_next, 0)
directory_sizes[sub_path_next] += size
sub_path = sub_path_next
if file_name:
directory_content = self._directories[directory_path]
......
......@@ -225,12 +225,18 @@ class UploadFilesContract(UploadFilesFixtures):
raw_files = list(path_info.path for path_info in path_infos)
assert_example_files(raw_files)
@pytest.mark.parametrize('path', [None, 'examples_template'])
@pytest.mark.parametrize('path', ['', 'examples_template'])
def test_raw_directory_list(self, test_upload: UploadWithFiles, path: str):
_, _, upload_files = test_upload
upload_id, _, upload_files = test_upload
# Add file to root to test corner case
append_raw_files(upload_id, 'tests/data/proc/examples_template/1.aux', '1.aux')
# Test recursive call (but do not verify result)
upload_files.raw_directory_list(path, files_only=False, recursive=True)
# Test non-recursive call, verify result partially
raw_files = list(upload_files.raw_directory_list(path, files_only=True))
if path is None:
assert len(raw_files) == 0
if not path:
assert len(raw_files) == 1
assert raw_files[0].size == 8
else:
assert '1.aux' in list(os.path.basename(path_info.path) for path_info in raw_files)
for path_info in raw_files:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment