Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Honor --repository flag for disabled repos as documented
Baptiste Daroussin committed 22 days ago
commit fcfe2f6bc2552064f2177a3e5f845f60752d0cfa
parent b64f9dd
5 files changed +99 -15
modified libpkg/pkgdb.c
@@ -831,26 +831,31 @@ pkgdb_access2(unsigned mode, unsigned database, c_charv_t *dbs)
		struct pkg_repo	*r = NULL;

		while (pkg_repos(&r) == EPKG_OK) {
-
			/* Ignore any repos marked as inactive */
-
			if (!pkg_repo_enabled(r))
-
				continue;
-

			if (dbs != NULL && dbs->len > 0 && r->name &&
			    !c_charv_contains(dbs, r->name, true)) {
				/* Skip what is not needed */
				continue;
			}

+
			/* Ignore inactive repos unless explicitly requested */
+
			if (!pkg_repo_enabled(r) &&
+
			    (dbs == NULL || dbs->len == 0))
+
				continue;
+

			retval = r->ops->access(r, mode);
			if (retval != EPKG_OK) {
				if (retval == EPKG_ENODB &&
-
				    (mode & PKGDB_MODE_READ) != PKGDB_MODE_READ) {
-
					pkg_emit_error("Repository %s missing."
-
						       " 'pkg update' required",
-
					    r->name);
+
				    (mode & PKGDB_MODE_CREATE) != 0) {
+
					retval = EPKG_OK;
+
				} else {
+
					if (retval == EPKG_ENODB &&
+
					    (mode & PKGDB_MODE_READ) !=
+
					    PKGDB_MODE_READ)
+
						pkg_emit_error("Repository %s "
+
						    "missing. 'pkg update' "
+
						    "required", r->name);
+
					return (retval);
				}
-

-
				return (retval);
			}
		}
	}
@@ -1174,7 +1179,8 @@ retry:
	}

	if (type == PKGDB_REMOTE || type == PKGDB_MAYBE_REMOTE) {
-
		if (pkg_repos_activated_count() > 0) {
+
		if (pkg_repos_activated_count() > 0 ||
+
		    (reponames != NULL && reponames->len > 0)) {
			if (reponames == NULL || reponames->len == 0) {
				ret = pkgdb_open_repos(db, NULL);
			} else {
modified libpkg/repo/binary/update.c
@@ -785,9 +785,6 @@ pkg_repo_binary_update(struct pkg_repo *repo, bool force)

	sqlite3_initialize();

-
	if (!pkg_repo_enabled(repo))
-
		return (EPKG_OK);
-

	pkg_debug(1, "PkgRepo: verifying update for %s", repo->name);

	(void)snprintf(filename, sizeof(filename), "%s/%s",
modified src/update.c
@@ -65,7 +65,7 @@ pkgcli_update(bool force, bool strict, c_charv_t *reponames)
	    PKGDB_DB_REPO, reponames) == EPKG_ENOACCESS)
		return (EPKG_OK);

-
	if (pkg_repos_total_count() == 0) {
+
	if (pkg_repos_total_count() == 0 && reponames->len == 0) {
		fprintf(stderr, "No active remote repositories configured.\n");
		return (EPKG_FATAL);
	}
modified tests/frontend/update.sh
@@ -5,6 +5,7 @@
tests_init \
	update_error \
	file_url \
+
	update_disabled_repo \

update_error_body() {

@@ -135,3 +136,46 @@ EOF
		pkg -R repos update

}
+

+
# Verify that "pkg update -r <repo>" works on a disabled repository,
+
# as documented in the man page ("irrespective of the configured active
+
# status").
+
update_disabled_repo_body()
+
{
+
	# Create a package and repo
+
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	atf_check pkg create -M test.ucl
+
	atf_check -o ignore pkg repo .
+

+
	# Configure two repos: one enabled, one disabled
+
	mkdir repos
+
	cat <<EOF > repos/enabled.conf
+
enabled_repo: {
+
	url: "file://${TMPDIR}",
+
	enabled: yes
+
}
+
EOF
+
	cat <<EOF > repos/disabled.conf
+
disabled_repo: {
+
	url: "file://${TMPDIR}",
+
	enabled: no
+
}
+
EOF
+

+
	atf_check \
+
		-o match:"Updating enabled_repo" \
+
		-o not-match:"disabled_repo" \
+
		-s exit:0 \
+
		pkg -R repos update
+

+
	atf_check \
+
		-o match:"Updating disabled_repo" \
+
		-o not-match:"enabled_repo" \
+
		-s exit:0 \
+
		pkg -R repos update -r disabled_repo
+

+
	atf_check \
+
		-o match:"No repositories are enabled" \
+
		-s exit:1 \
+
		pkg -R repos update -r nonexistent
+
}
modified tests/frontend/upgrade.sh
@@ -21,6 +21,7 @@ tests_init \
	upgrade_autoremove_flag \
	symlink_to_dir_upgrade \
	newpkgversion_two_repos \
+
	upgrade_disabled_repo \

issue1881_body() {
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg pkg1 pkg_a 1
@@ -805,3 +806,39 @@ EOF
		-s exit:0 \
		pkg -C ./pkg.conf upgrade -y
}
+

+
# Verify that "pkg upgrade -r <repo>" works on a disabled repository,
+
# as documented in the man page ("irrespective of the configured active
+
# status").
+
upgrade_disabled_repo_body()
+
{
+
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1"
+
	atf_check -o ignore pkg register -M test.ucl
+

+
	atf_check sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "2"
+
	atf_check pkg create -M test.ucl
+
	atf_check -o ignore pkg repo .
+

+
	mkdir repos
+
	cat <<EOF > repos/myrepo.conf
+
myrepo: {
+
	url: "file://${TMPDIR}",
+
	enabled: no
+
}
+
EOF
+

+
	atf_check \
+
		-o match:"Updating myrepo" \
+
		-s exit:0 \
+
		pkg -R repos update -r myrepo
+

+
	atf_check \
+
		-o match:"Upgrading test from 1 to 2" \
+
		-s exit:0 \
+
		pkg -o REPOS_DIR="${TMPDIR}/repos" -o PKG_CACHEDIR="${TMPDIR}" \
+
		upgrade -y -r myrepo
+

+
	atf_check \
+
		-o inline:"2\n" \
+
		pkg query "%v" test
+
}