xbps-install: fix --reproducable.

The 'repository' obj also needs to be skipped to be fully
reproducable between different repositories.

Updated the test case accordingly.
This commit is contained in:
Juan RP 2019-12-29 16:31:23 +01:00
parent 2c7c4e1bf0
commit d68ff7ebf0
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368
5 changed files with 38 additions and 28 deletions

View File

@ -47,21 +47,20 @@ usage(bool fail)
" -C --config <dir> Path to confdir (xbps.d)\n" " -C --config <dir> Path to confdir (xbps.d)\n"
" -c --cachedir <dir> Path to cachedir\n" " -c --cachedir <dir> Path to cachedir\n"
" -d --debug Debug mode shown to stderr\n" " -d --debug Debug mode shown to stderr\n"
" -D --download-only Download packages and check integrity, nothing else.\n" " -D --download-only Download packages and check integrity, nothing else\n"
" -f --force Force package re-installation\n" " -f --force Force package re-installation\n"
" If specified twice, all files will be\n" " If specified twice, all files will be overwritten.\n"
" overwritten.\n"
" -h --help Print help usage\n" " -h --help Print help usage\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d\n" " -i --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -I --ignore-file-conflicts Ignore detected file conflicts.\n" " -I --ignore-file-conflicts Ignore detected file conflicts\n"
" -U --unpack-only Unpack packages in transaction, do not configure them\n" " -U --unpack-only Unpack packages in transaction, do not configure them\n"
" -M --memory-sync Remote repository data is fetched and stored\n" " -M --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n" " in memory, ignoring on-disk repodata archives\n"
" -n --dry-run Dry-run mode\n" " -n --dry-run Dry-run mode\n"
" -R,--repository=<url> Add repository to the top of the list.\n" " -R,--repository=<url> Add repository to the top of the list\n"
" This option can be specified multiple times.\n" " This option can be specified multiple times\n"
" -r --rootdir <dir> Full path to rootdir\n" " -r --rootdir <dir> Full path to rootdir\n"
" --reproducible Enable reproducible mode in pkgdb.\n" " --reproducible Enable reproducible mode in pkgdb\n"
" -S --sync Sync remote repository index\n" " -S --sync Sync remote repository index\n"
" -u --update Update target package(s)\n" " -u --update Update target package(s)\n"
" -v --verbose Verbose messages\n" " -v --verbose Verbose messages\n"

View File

@ -116,7 +116,9 @@ This option can be specified multiple times.
.It Fl -reproducible .It Fl -reproducible
Enables reproducible mode in pkgdb. The Enables reproducible mode in pkgdb. The
.Ar install-date .Ar install-date
package object is not added to pkgdb. and
.Ar repository
package objects are not stored in pkgdb.
.It Fl r, Fl -rootdir Ar dir .It Fl r, Fl -rootdir Ar dir
Specifies a full path for the target root directory. Specifies a full path for the target root directory.
.It Fl S, Fl -sync .It Fl S, Fl -sync

View File

@ -232,7 +232,8 @@
/** /**
* @def XBPS_FLAG_INSTALL_REPRO * @def XBPS_FLAG_INSTALL_REPRO
* Enabled reproducible mode; skips adding the "install-date" obj into pkgdb. * Enabled reproducible mode; skips adding the "install-date"
* and "repository" objs into pkgdb.
* Must be set through the xbps_handle::flags member. * Must be set through the xbps_handle::flags member.
*/ */
#define XBPS_FLAG_INSTALL_REPRO 0x00008000 #define XBPS_FLAG_INSTALL_REPRO 0x00008000

View File

@ -64,10 +64,17 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
if (xhp->flags & XBPS_FLAG_INSTALL_REPRO) {
/*
* Reproducible mode. Some objects must not be recorded:
* - install-date
* - repository
*/
xbps_dictionary_remove(pkgd, "repository");
} else {
/* /*
* Set the "install-date" object to know the pkg installation date. * Set the "install-date" object to know the pkg installation date.
*/ */
if ((xhp->flags & XBPS_FLAG_INSTALL_REPRO) == 0) {
t = time(NULL); t = time(NULL);
if ((tmp = localtime(&t)) == NULL) { if ((tmp = localtime(&t)) == NULL) {
xbps_dbg_printf(xhp, "%s: localtime failed: %s\n", xbps_dbg_printf(xhp, "%s: localtime failed: %s\n",
@ -105,6 +112,7 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd)
xbps_dictionary_remove(pkgd, "skip-obsoletes"); xbps_dictionary_remove(pkgd, "skip-obsoletes");
xbps_dictionary_remove(pkgd, "pkgname"); xbps_dictionary_remove(pkgd, "pkgname");
xbps_dictionary_remove(pkgd, "version"); xbps_dictionary_remove(pkgd, "version");
/* /*
* Remove self replacement when applicable. * Remove self replacement when applicable.
*/ */

View File

@ -65,40 +65,40 @@ reproducible_head() {
} }
reproducible_body() { reproducible_body() {
mkdir -p repo pkg_A mkdir -p repo-1 repo-2 pkg_A
touch pkg_A/file touch pkg_A/file
cd repo cd repo-1
xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ../repo-2
xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0 atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0 atf_check_equal $? 0
cd .. cd ..
xbps-install -r root-1 --repo=$PWD/repo --repro -y A
xbps-install -r root-1 --repo=$PWD/repo-1 --repro -y A
atf_check_equal $? 0 atf_check_equal $? 0
xbps-install -r root-2 --repo=$PWD/repo --repro -y A xbps-install -r root-2 --repo=$PWD/repo-2 --repro -y A
atf_check_equal $? 0 atf_check_equal $? 0
# Compare pkgdb in both rootdirs # Compare pkgdb in both rootdirs
cmp root-1/var/db/xbps/pkgdb-0.38.plist root-2/var/db/xbps/pkgdb-0.38.plist cmp -s root-1/var/db/xbps/pkgdb-0.38.plist root-2/var/db/xbps/pkgdb-0.38.plist
atf_check_equal $? 0
# compare pkgdb meta files in both rootdirs
cmp root-1/var/db/xbps/.A-files.plist root-2/var/db/xbps/.A-files.plist
atf_check_equal $? 0 atf_check_equal $? 0
# Now check without --reproducible # Now check without --reproducible
rm -rf root-1 root-2 rm -rf root-1 root-2
xbps-install -r root-1 --repo=$PWD/repo --repro -y A xbps-install -r root-1 --repo=$PWD/repo-1 --repro -y A
atf_check_equal $? 0 atf_check_equal $? 0
xbps-install -r root-2 --repo=$PWD/repo -y A xbps-install -r root-2 --repo=$PWD/repo-2 -y A
atf_check_equal $? 0 atf_check_equal $? 0
# Compare pkgdb in both rootdirs # Compare pkgdb in both rootdirs
cmp root-1/var/db/xbps/pkgdb-0.38.plist root-2/var/db/xbps/pkgdb-0.38.plist cmp -s root-1/var/db/xbps/pkgdb-0.38.plist root-2/var/db/xbps/pkgdb-0.38.plist
atf_check_equal $? 1 atf_check_equal $? 1
# compare pkgdb meta files in both rootdirs
cmp root-1/var/db/xbps/.A-files.plist root-2/var/db/xbps/.A-files.plist
atf_check_equal $? 0
} }
atf_init_test_cases() { atf_init_test_cases() {