1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-14 00:06:15 +01:00

Merge pull request #1654 from dmach/fix-store-migration-1.0-to-2.0-sources-file

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:
Daniel Mach 2024-11-05 14:14:42 +01:00 committed by GitHub
commit 8b1df4de3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 8 deletions

View File

@ -20,7 +20,7 @@ jobs:
- run: pip config set global.break-system-packages 1 - run: pip config set global.break-system-packages 1
- run: pip install mypy - run: pip install mypy
- run: pip install types-cryptography types-urllib3 - run: pip install types-cryptography types-urllib3
- run: pip install distro keyring progressbar zstandard - run: pip install distro keyring progressbar ruamel.yaml zstandard
- run: mypy osc - run: mypy osc
darker: darker:
@ -42,7 +42,7 @@ jobs:
- name: 'Install packages' - name: 'Install packages'
run: | run: |
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y --no-install-recommends install pylint python3-rpm sudo apt-get -y --no-install-recommends install pylint python3-rpm python3-ruamel.yaml
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@ -68,7 +68,7 @@ jobs:
- name: 'Install packages' - name: 'Install packages'
run: | run: |
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y --no-install-recommends install diffutils pylint python3-pip sudo apt-get -y --no-install-recommends install diffutils pylint python3-pip python3-rpm python3-ruamel.yaml
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:

View File

@ -131,7 +131,13 @@ jobs:
run: | run: |
sudo sh -c '. /etc/os-release; echo "deb [trusted=yes] http://download.opensuse.org/repositories/openSUSE:Tools/xUbuntu_${VERSION_ID} ./" > /etc/apt/sources.list.d/openSUSE-Tools.list' sudo sh -c '. /etc/os-release; echo "deb [trusted=yes] http://download.opensuse.org/repositories/openSUSE:Tools/xUbuntu_${VERSION_ID} ./" > /etc/apt/sources.list.d/openSUSE-Tools.list'
sudo apt-get -y update sudo apt-get -y update
sudo apt-get -y --no-install-recommends install python3-behave diffstat diffutils python3 python3-cryptography python3-pip python3-rpm python3-ruamel.yaml python3-setuptools python3-urllib3 obs-build obs-service-set-version sudo apt-get -y --no-install-recommends install git python3-behave diffstat diffutils python3 python3-cryptography python3-pip python3-rpm python3-ruamel.yaml python3-setuptools python3-urllib3 obs-build obs-service-set-version
# obs-scm-bridge is not available as a package at the moment, install it from github
sudo pip3 config set global.break-system-packages 1
sudo pip3 install git+https://github.com/openSUSE/obs-scm-bridge
sudo chmod a+x /usr/local/lib/*/*/obs_scm_bridge
sudo mkdir -p /usr/lib/obs/service
sudo ln -s /usr/local/lib/*/*/obs_scm_bridge /usr/lib/obs/service/obs_scm_bridge
- name: "Checkout sources" - name: "Checkout sources"
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -143,4 +149,4 @@ jobs:
- name: "Run tests" - name: "Run tests"
run: | run: |
cd behave cd behave
behave -Dosc=../osc-wrapper.py -Dpodman_max_containers=2 behave -Dosc=../osc-wrapper.py -Dgit-obs=../git-obs.py -Dpodman_max_containers=2

View File

@ -70,7 +70,7 @@ Run tests
Run all tests Run all tests
``` ```
$ cd behave $ cd behave
$ behave -Dosc=../osc-wrapper.py $ behave -Dosc=../osc-wrapper.py -Dgit-obs=../git-obs.py
``` ```
Run selected tests Run selected tests

View File

@ -405,7 +405,13 @@ def check_store_version(dir):
if v == "1.0": if v == "1.0":
store_dir = os.path.join(dir, store) store_dir = os.path.join(dir, store)
sources_dir = os.path.join(dir, store, "sources") 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) s = Store(dir, check=False)
if s.is_package and not s.scmurl: if s.is_package and not s.scmurl:
@ -416,7 +422,7 @@ def check_store_version(dir):
for fn in os.listdir(store_dir): for fn in os.listdir(store_dir):
old_path = os.path.join(store_dir, fn) 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): if not os.path.isfile(old_path):
continue continue
if fn in Package.REQ_STOREFILES or fn in Package.OPT_STOREFILES: 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): if os.path.isfile(old_path):
os.rename(old_path, new_path) os.rename(old_path, new_path)
if sources_dir != sources_dir_mv:
os.rename(sources_dir_mv, sources_dir)
v = "2.0" v = "2.0"
s.write_string("_osclib_version", v) s.write_string("_osclib_version", v)
migrated = True migrated = True

View File

@ -236,6 +236,21 @@ class TestStore(unittest.TestCase):
pkg = LocalPackage(self.tmpdir) pkg = LocalPackage(self.tmpdir)
self.assertEqual(pkg.get_meta_value("releasename"), "name") 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__": if __name__ == "__main__":
unittest.main() unittest.main()