Skip to content

Commit

Permalink
Merge pull request #1654 from dmach/fix-store-migration-1.0-to-2.0-so…
Browse files Browse the repository at this point in the history
…urces-file

Fix store migration from 1.0 to 2.0 when there is a 'sources' file that would conflict with 'sources' directory
  • Loading branch information
dmach authored Nov 5, 2024
2 parents f8a9c93 + 4215d1a commit 8b1df4d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: pip config set global.break-system-packages 1
- run: pip install mypy
- 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

darker:
Expand All @@ -42,7 +42,7 @@ jobs:
- name: 'Install packages'
run: |
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

Expand All @@ -68,7 +68,7 @@ jobs:
- name: 'Install packages'
run: |
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
with:
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ jobs:
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 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"
uses: actions/checkout@v3
Expand All @@ -143,4 +149,4 @@ jobs:
- name: "Run tests"
run: |
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
2 changes: 1 addition & 1 deletion behave/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Run tests
Run all tests
```
$ cd behave
$ behave -Dosc=../osc-wrapper.py
$ behave -Dosc=../osc-wrapper.py -Dgit-obs=../git-obs.py
```

Run selected tests
Expand Down
13 changes: 11 additions & 2 deletions osc/obs_scm/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ def test_meta_node(self):
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()

0 comments on commit 8b1df4d

Please sign in to comment.