1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-09-05 20:58:42 +02:00

Fix store migration from 1.0 to 2.0 when there is a 'sources' file that would conflict with 'sources' directory

This commit is contained in:
2024-11-05 09:31:50 +01:00
parent f8a9c93e2a
commit 856277b63c
2 changed files with 26 additions and 2 deletions

View File

@@ -405,7 +405,13 @@ def check_store_version(dir):
if v == "1.0":
store_dir = os.path.join(dir, store)
sources_dir = os.path.join(dir, store, "sources")
os.makedirs(sources_dir, exist_ok=True)
sources_dir_mv = sources_dir
if os.path.isfile(sources_dir):
# there is a conflict with an existing "sources" file
sources_dir_mv = os.path.join(dir, store, "_sources")
os.makedirs(sources_dir_mv, exist_ok=True)
s = Store(dir, check=False)
if s.is_package and not s.scmurl:
@@ -416,7 +422,7 @@ def check_store_version(dir):
for fn in os.listdir(store_dir):
old_path = os.path.join(store_dir, fn)
new_path = os.path.join(sources_dir, fn)
new_path = os.path.join(sources_dir_mv, fn)
if not os.path.isfile(old_path):
continue
if fn in Package.REQ_STOREFILES or fn in Package.OPT_STOREFILES:
@@ -426,6 +432,9 @@ def check_store_version(dir):
if os.path.isfile(old_path):
os.rename(old_path, new_path)
if sources_dir != sources_dir_mv:
os.rename(sources_dir_mv, sources_dir)
v = "2.0"
s.write_string("_osclib_version", v)
migrated = True

View File

@@ -236,6 +236,21 @@ class TestStore(unittest.TestCase):
pkg = LocalPackage(self.tmpdir)
self.assertEqual(pkg.get_meta_value("releasename"), "name")
def test_migrate_10_20_sources_file(self):
self.store = Store(self.tmpdir, check=False)
self.store.write_string("_osclib_version", "1.0")
self.store.apiurl = "http://localhost"
self.store.is_package = True
self.store.project = "project name"
self.store.package = "package name"
self.store.write_string("sources", "")
self.store.files = [
osc_core.File(name="sources", md5="aabbcc", size=0, mtime=0),
]
Store(self.tmpdir, check=True)
self.assertTrue(os.path.exists(os.path.join(self.tmpdir, ".osc", "sources", "sources")))
if __name__ == "__main__":
unittest.main()