Skip to content

Commit

Permalink
Fix content app not showing file size for 0 byte files
Browse files Browse the repository at this point in the history
fixes: pulp#5100
  • Loading branch information
gerrod3 authored and mdellweg committed Mar 13, 2024
1 parent 5afae80 commit 85feedb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/5100.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed content directory listing not showing file size for 0-byte files.
2 changes: 1 addition & 1 deletion pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def render_html(directory_list, path="", dates=None, sizes=None):
{% else -%}
{% set date = "" -%}
{% endif -%}
{% if sizes.get(name, "") -%}
{% if name in sizes -%}
{% set size | filesizeformat -%}
{{ sizes.get(name) }}
{% endset -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ def test_hidden_distros(file_distribution_factory, pulp_content_url, http_get):
assert content.count(f'a href="{d.base_path}/"') == 1
for d in hidden:
assert content.count(f'a href="{d.base_path}/"') == 0


@pytest.mark.parallel
def test_zero_byte_file_listing(
file_bindings,
file_distribution_factory,
file_repo_with_auto_publish,
random_artifact_factory,
http_get,
monitor_task,
pulpcore_bindings,
):
try:
zero_file = random_artifact_factory(size=0)
except pulpcore_bindings.ApiException:
zero_file = pulpcore_bindings.ArtifactsApi.list(
sha256="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
).results[0]
task = file_bindings.ContentFilesApi.create(
relative_path="zero",
artifact=zero_file.pulp_href,
repository=file_repo_with_auto_publish.pulp_href,
).task
monitor_task(task)
distribution = file_distribution_factory(repository=file_repo_with_auto_publish.pulp_href)

response = http_get(distribution.base_url)
z_line = [i for i in response.decode("utf-8").split("\n") if i.startswith('<a href="zero">')]
assert len(z_line) == 1
assert z_line[0].endswith("0 Bytes")

0 comments on commit 85feedb

Please sign in to comment.