Confusion about APKBUILD "replaces"
I find APKBUILD Reference#replaces confusing. If I read the history right, that's what @ncopa added in 2010:
replaces
Package(s) that this package replaces. This package will "take over" files owned by packages listed in the replaces variable. This is useful when files move from one package to another, or when a package gets renamed.
It's for overriding files, not packages
I used to think that it works similar to replaces in PKGBUILD, where it means a whole package will be replaced by another one. However, recently I found that in APKBUILD, it's more like the replacing package overrides files of the replaced package. Both packages can be installed at the same time, and if they provide the same file, apk will just install the version of the replacing package. When the replaced package gets upgraded and would provide a new version of the replaced file, apk will still use the version of the replaced package.
(This is very useful btw, we'll use this in the future to properly override config files in postmarketOS.)
With the newly acquired knowledge, I added the following sentences:
The replaced package and the replacing package can be installed at the same time. A use case for this is replacing config files in "policy packages" [7].
Confusing part
This part throws me off:
This is useful when files move from one package to another, or when a package gets renamed.
I did an experiment and found that replaces
is not needed in order to rename a package, one only needs provides="oldpkg=$pkgver-r$pkgrel"
and a higher version (pkgver/pkgrel).
First package:
pkgname="replace-pkg-test"
pkgver=1
pkgrel=0
pkgdesc="reproducer"
url="https://postmarketos.org"
license="MIT"
arch="all"
package() {
mkdir -p "$pkgdir/etc"
echo "$pkgname" > "$pkgdir/etc/test"
}
Second package:
pkgname="replace-pkg-test-new"
pkgver=1
pkgrel=1
pkgdesc="reproducer"
url="https://postmarketos.org"
license="MIT"
arch="all"
provides="replace-pkg-test=$pkgver-r$pkgrel"
package() {
mkdir -p "$pkgdir/etc"
echo "$pkgname" > "$pkgdir/etc/test"
}
apk output:
# apk add replace-pkg-test
(1/1) Installing replace-pkg-test (1-r0)
Build the second package and remove the first one from APKINDEX.
# apk upgrade
(1/2) Purging replace-pkg-test (1-r0)
(2/2) Installing replace-pkg-test-new (1-r1)
https://gitlab.com/ollieparanoid/reproducers/-/tree/master/apk-replace-pkg
So I'm wondering:
- Why is it useful when a package gets renamed?
- Why is it useful when moving files from one package to another?