From ecc32663c28e0212a4f5e4b6f1802d63a37b6755 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Mar 23 2021 23:13:47 +0000 Subject: Check whether sources file is not a directory Resolves: #541 JIRA: RHELCMP-4166 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/sources.py b/pyrpkg/sources.py index e021131..858461d 100644 --- a/pyrpkg/sources.py +++ b/pyrpkg/sources.py @@ -31,6 +31,13 @@ class SourcesFile(object): self.entry_type = {'old': SourceFileEntry, 'bsd': BSDSourceFileEntry}[entry_type] self.entries = [] + # if there is a directory with the same name, it causes a collision + # during reading the file and during its replacing as well + if os.path.exists(sourcesfile) and os.path.isdir(sourcesfile): + raise ValueError( + "'{0}' has to be a regular file, not a directory. The '{0}' " + "filename is a rpkg library default name or a specific layout " + " setting)".format(sourcesfile)) if not replace: if not os.path.exists(sourcesfile): diff --git a/tests/test_sources.py b/tests/test_sources.py index fafbaf9..cfacc51 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -268,3 +268,7 @@ class SourcesFileTestCase(unittest.TestCase): self.assertEqual(len(lines), 1) self.assertEqual(lines[0], 'MD5 (thirdfile) = thirdhash\n') + + def test_directory_instead_of_regular_file(self): + os.mkdir(self.sourcesfile) + self.assertRaises(ValueError, sources.SourcesFile, self.sourcesfile, 'bsd')