From 6b352bc049c23bef88f24ccf550b40eae20581f9 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Aug 25 2020 12:48:05 +0000 Subject: Skip directories inside of imported srpm file Fixes fail when `fedpkg import *.src.rpm` is run and imported file contains a directory (even empty). Now a warning is shown and the directory is skipped. JIRA: RHELCMP-1969 Resolves: rhbz#1866297 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 1252251..3c03d15 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1307,6 +1307,11 @@ class Commands(object): # Cycle through the srpm content and decide where to upload files for file in contents: + if os.path.isdir(os.path.join(target_dir, file)): + # only show warning; file-dir will be skipped during + # the test of eligibility + self.log.warning("SRPM file contains a directory: '{0}'. " + "Skipping it.".format(file)) if is_lookaside_eligible_file(file, target_dir): uploadfiles.append(file) else: diff --git a/pyrpkg/utils.py b/pyrpkg/utils.py index 1a50a3e..d754d78 100644 --- a/pyrpkg/utils.py +++ b/pyrpkg/utils.py @@ -271,6 +271,9 @@ def is_lookaside_eligible_file(file_name, dir_path=None): File size and file extension doesn't matter. """ file_path = os.path.join(dir_path or "", file_name) + if os.path.isdir(file_path): + # ignore dirs; do not upload them + return False if not os.path.isfile(file_path): raise IOError("Input file doesn't exist: {0}".format(file_path)) diff --git a/tests/fixtures/docpkg/EMPTY_DIR/.gitkeep b/tests/fixtures/docpkg/EMPTY_DIR/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/fixtures/docpkg/EMPTY_DIR/.gitkeep diff --git a/tests/fixtures/docpkg/docpkg.spec b/tests/fixtures/docpkg/docpkg.spec index cca2c78..ae6ac5f 100644 --- a/tests/fixtures/docpkg/docpkg.spec +++ b/tests/fixtures/docpkg/docpkg.spec @@ -10,6 +10,8 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Source0: hello-world.txt Source1: docpkg.tar.gz Source2: source-without-extension +# added empty dir just to test import srpm `fedpkg import`. It should skip the dir. +Source3: EMPTY_DIR %description This is a dummy description.