From 85feedb34dbb29bb2000986fe1c070e2aa86fb5e Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Wed, 13 Mar 2024 02:14:19 -0400 Subject: [PATCH] Fix content app not showing file size for 0 byte files fixes: #5100 --- CHANGES/5100.bugfix | 1 + pulpcore/content/handler.py | 2 +- .../using_plugin/test_content_directory.py | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 CHANGES/5100.bugfix diff --git a/CHANGES/5100.bugfix b/CHANGES/5100.bugfix new file mode 100644 index 0000000000..334388ec12 --- /dev/null +++ b/CHANGES/5100.bugfix @@ -0,0 +1 @@ +Fixed content directory listing not showing file size for 0-byte files. diff --git a/pulpcore/content/handler.py b/pulpcore/content/handler.py index 6341084cd1..8ee12d2f4a 100644 --- a/pulpcore/content/handler.py +++ b/pulpcore/content/handler.py @@ -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 -%} diff --git a/pulpcore/tests/functional/api/using_plugin/test_content_directory.py b/pulpcore/tests/functional/api/using_plugin/test_content_directory.py index f301baa81b..e7076ad976 100644 --- a/pulpcore/tests/functional/api/using_plugin/test_content_directory.py +++ b/pulpcore/tests/functional/api/using_plugin/test_content_directory.py @@ -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('')] + assert len(z_line) == 1 + assert z_line[0].endswith("0 Bytes")