1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-25 17:36:13 +01:00

Fix creating a Package object by providing multiple files on the command line

This commit is contained in:
Daniel Mach 2023-01-20 16:52:11 +01:00
parent cd35d69905
commit fdd2c3a8f0
5 changed files with 37 additions and 4 deletions

View File

@ -1277,13 +1277,24 @@ class Package:
path_is_file = os.path.isfile(path)
if path_is_file:
path = os.path.dirname(path) or "."
package = cls(path, progress_obj)
try:
# re-use an existing package
seen_package_index = packages.index(package)
package = packages[seen_package_index]
if os.path.abspath(path) != package.absdir:
raise oscerr.PackageExists(package.prjname, package.name, "Duplicate package")
except ValueError:
# use a new package instance
packages.append(package)
if path_is_file:
# XXX: modifying 'todo' is an unexpected side-effect
package.todo = [os.path.basename(orig_path)]
if package in packages:
raise oscerr.PackageExists(package.prjname, package.name, "Duplicate package")
packages.append(package)
todo_entry = os.path.basename(orig_path)
if todo_entry not in package.todo:
package.todo.append(todo_entry)
return packages
@classmethod

View File

@ -0,0 +1 @@
pkgA

View File

@ -81,10 +81,31 @@ class TestPackageFromPaths(OscTestCase):
self.assertEqual(pac.apiurl, "http://localhost")
def test_duplicates(self):
# passing a path twice is ok
paths = ["projectA/pkgA", "projectA/pkgA"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
pacs = osc.core.Package.from_paths(paths)
pac = pacs[0]
self.assertEqual(pac.name, "pkgA")
self.assertEqual(pac.prjname, "projectA")
self.assertEqual(pac.apiurl, "http://localhost")
# the same package in 2 paths is an error
paths = ["projectA/pkgA", "projectA/pkgA-symlink"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
self.assertRaises(osc.oscerr.PackageExists, osc.core.Package.from_paths, paths)
def test_one_package_two_files(self):
paths = ["projectA/pkgA/pkgA.spec", "projectA/pkgA/pkgA.changes"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]
pacs = osc.core.Package.from_paths(paths)
self.assertEqual(len(pacs), 1)
pac = pacs[0]
self.assertEqual(pac.name, "pkgA")
self.assertEqual(pac.prjname, "projectA")
self.assertEqual(pac.apiurl, "http://localhost")
def test_two_packages(self):
paths = ["projectA/pkgA", "projectA/pkgB"]
paths = [os.path.join(self.tmpdir, 'osctest', i) for i in paths]