summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2022-09-01 15:14:52 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2022-09-02 16:55:45 +0200
commitf52c1ce9b31befb71016a20759b96b4946034fcb (patch)
tree62d556e84db4489a4276ee7c6b41a8aa26f1c048
parent3498fbedafbf30e5c91deeaefa6a60d1e387593a (diff)
Allow apt to run if no dpkg/status file exists
Not having a dpkg/status file used to be a hard error which from a boostrap perspective is suspect as in the beginning, there is no status so you would need to touch it into existence. We make a difference between factual non-existence and inaccessibility to catch mistakes in which the file is not readable for some reason, the testcase test-bug-254770-segfault-if-cache-not-buildable is an example of this. Note that apt has already figured out at this point that this is a Debian-like system which should have a dpkg/status file. This change does not effect the auto-detection and is not supposed to.
-rw-r--r--apt-pkg/deb/debsystem.cc7
-rw-r--r--apt-pkg/policy.cc14
-rw-r--r--test/integration/framework2
-rwxr-xr-xtest/integration/test-allow-scores-for-all-dependency-types5
-rwxr-xr-xtest/integration/test-apt-cache-remapping1
-rwxr-xr-xtest/integration/test-apt-cli-update3
-rwxr-xr-xtest/integration/test-bug-604222-new-and-autoremove4
-rwxr-xr-xtest/integration/test-bug-673536-pre-depends-breaks-loop5
-rwxr-xr-xtest/integration/test-bug-782777-single-arch-weirdness3
-rwxr-xr-xtest/integration/test-failing-maintainer-scripts9
-rwxr-xr-xtest/integration/test-policy-pinning2
-rwxr-xr-xtest/integration/test-ubuntu-bug-1130419-prefer-installed-ma-same-siblings3
-rwxr-xr-xtest/integration/test-ubuntu-bug-784473-InRelease-one-message-only4
-rwxr-xr-xtest/integration/test-unpack-different-version-unpacked5
14 files changed, 34 insertions, 33 deletions
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index 65a27f72f..9c55e0a6e 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -338,6 +338,13 @@ bool debSystem::AddStatusFiles(std::vector<pkgIndexFile *> &List)
if (d->StatusFile == nullptr)
{
auto dpkgstatus = _config->FindFile("Dir::State::status");
+ if (dpkgstatus.empty())
+ return true;
+ // we ignore only if the file doesn't exist, not if it is inaccessible
+ // e.g. due to permissions on parent directories as FileExists would do
+ errno = 0;
+ if (access(dpkgstatus.c_str(), R_OK) != 0 && errno == ENOENT)
+ return true;
_error->PushToStack();
d->StatusFile = new debStatusIndex(std::move(dpkgstatus));
bool const errored = _error->PendingError();
diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc
index 5fcc11b66..68b3f5e5f 100644
--- a/apt-pkg/policy.cc
+++ b/apt-pkg/policy.cc
@@ -70,17 +70,19 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : VerPins(nullptr),
if (DefRel.empty() == false)
{
bool found = false;
- // FIXME: make ExpressionMatches static to use it here easily
- pkgVersionMatch vm("", pkgVersionMatch::None);
for (pkgCache::PkgFileIterator F = Cache->FileBegin(); F != Cache->FileEnd(); ++F)
{
- if (vm.ExpressionMatches(DefRel, F.Archive()) ||
- vm.ExpressionMatches(DefRel, F.Codename()) ||
- vm.ExpressionMatches(DefRel, F.Version()) ||
+ if (pkgVersionMatch::ExpressionMatches(DefRel, F.Archive()) ||
+ pkgVersionMatch::ExpressionMatches(DefRel, F.Codename()) ||
+ pkgVersionMatch::ExpressionMatches(DefRel, F.Version()) ||
(DefRel.length() > 2 && DefRel[1] == '='))
found = true;
}
- if (found == false)
+ // "now" is our internal archive name for the status file,
+ // which we should accept even if we have no status file at the moment
+ if (not found && pkgVersionMatch::ExpressionMatches(DefRel, "now"))
+ found = true;
+ if (not found)
_error->Error(_("The value '%s' is invalid for APT::Default-Release as such a release is not available in the sources"), DefRel.c_str());
else
CreatePin(pkgVersionMatch::Release,"",DefRel,990);
diff --git a/test/integration/framework b/test/integration/framework
index 5e1e68a98..d50b63518 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -626,8 +626,6 @@ configdpkg() {
if tail -1 rootdir/var/lib/dpkg/status | grep -q .; then
echo >> rootdir/var/lib/dpkg/status
fi
- else
- echo -n > rootdir/var/lib/dpkg/status
fi
fi
rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg
diff --git a/test/integration/test-allow-scores-for-all-dependency-types b/test/integration/test-allow-scores-for-all-dependency-types
index b8a9ed3ea..999efc04e 100755
--- a/test/integration/test-allow-scores-for-all-dependency-types
+++ b/test/integration/test-allow-scores-for-all-dependency-types
@@ -37,7 +37,6 @@ insertpackage 'jessie' 'login' 'amd64' '2' 'Pre-Depends: libaudit1 (>= 0)'
insertpackage 'jessie' 'libaudit1' 'amd64' '2' 'Depends: libaudit-common (>= 0)'
insertpackage 'jessie' 'libaudit-common' 'amd64' '2' 'Breaks: libaudit0, libaudit1 (<< 2)'
-cp rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status-backup
setupaptarchive
insertinstalledpackage 'libdb-dev' 'amd64' '5.1.7' 'Depends: libdb5.1-dev'
@@ -73,7 +72,7 @@ Inst libdb5.3-dev (5.3.28-3 versioned [amd64])
Conf libdb-dev (5.3.0 versioned [amd64])
Conf libdb5.3-dev (5.3.28-3 versioned [amd64])' aptget dist-upgrade -st versioned
-cp -f rootdir/var/lib/dpkg/status-backup rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
insertinstalledpackage 'foo' 'amd64' '1'
insertinstalledpackage 'bar' 'amd64' '1'
testsuccessequal 'Reading package lists...
@@ -131,7 +130,7 @@ Conf bar (2 versioned [amd64])
Conf baz (2 versioned [amd64])' aptget install baz -st versioned
# recreating the exact situation is hard, so we pull tricks to get the score
-cp -f rootdir/var/lib/dpkg/status-backup rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
insertinstalledpackage 'gdm3' 'amd64' '1' 'Depends: libaudit0, libaudit0'
insertinstalledpackage 'login' 'amd64' '1' 'Essential: yes'
insertinstalledpackage 'libaudit0' 'amd64' '1'
diff --git a/test/integration/test-apt-cache-remapping b/test/integration/test-apt-cache-remapping
index 31a406c57..19647a6a4 100755
--- a/test/integration/test-apt-cache-remapping
+++ b/test/integration/test-apt-cache-remapping
@@ -8,6 +8,7 @@ setupenvironment
configarchitecture 'amd64'
buildsimplenativepackage 'foo' 'amd64' '1'
+insertinstalledpackage 'bar' 'all' '1'
# the default is 1MB – too much for our simple tests
echo 'APT::Cache-Grow "1000";' > rootdir/etc/apt/apt.conf.d/limit-cachegrow.conf
diff --git a/test/integration/test-apt-cli-update b/test/integration/test-apt-cli-update
index cc8d051d2..810221510 100755
--- a/test/integration/test-apt-cli-update
+++ b/test/integration/test-apt-cli-update
@@ -8,7 +8,6 @@ setupenvironment
configarchitecture "i386"
insertpackage 'unstable' 'foo' 'all' '2.0'
-cp rootdir/var/lib/dpkg/status dpkg.status
insertinstalledpackage 'foo' 'all' '1.0'
setupaptarchive --no-update
@@ -18,6 +17,6 @@ testfailuremsg 'E: The update command takes no arguments' apt update arguments
testempty apt update -qq -o pkgCacheFile::Generate=false
testsuccessequal "1 package can be upgraded. Run 'apt list --upgradable' to see it." apt update -qq
-cp dpkg.status rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
insertinstalledpackage 'foo' 'all' '2.0'
testsuccessequal 'All packages are up to date.' apt update -qq
diff --git a/test/integration/test-bug-604222-new-and-autoremove b/test/integration/test-bug-604222-new-and-autoremove
index 08756e03d..47da810c6 100755
--- a/test/integration/test-bug-604222-new-and-autoremove
+++ b/test/integration/test-bug-604222-new-and-autoremove
@@ -19,7 +19,6 @@ insertpackage 'stable' 'libkipi-data' 'i386' '4:15.08.0-1' '' 'important'
setupaptarchive
-cp -a rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status.backup
insertinstalledpackage 'libvtk5.4' 'i386' '5.4.2-7'
testsuccess aptmark markauto 'libvtk5.4'
testmarkedauto 'libvtk5.4'
@@ -80,8 +79,7 @@ Need to get 0 B/126 B of archives.
After this operation, 129 kB of additional disk space will be used.
E: Trivial Only specified but this is not a trivial operation." aptget install dummy-archive --trivial-only -o APT::Get::HideAutoRemove=small
-cp rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
-rm -f rootdir/var/lib/apt/extended_states
+rm -f rootdir/var/lib/dpkg/status rootdir/var/lib/apt/extended_states
CONFLICTING='Reading package lists...
Building dependency tree...
diff --git a/test/integration/test-bug-673536-pre-depends-breaks-loop b/test/integration/test-bug-673536-pre-depends-breaks-loop
index a4cf66973..650866ee5 100755
--- a/test/integration/test-bug-673536-pre-depends-breaks-loop
+++ b/test/integration/test-bug-673536-pre-depends-breaks-loop
@@ -18,11 +18,8 @@ setupaptarchive
# we check with 'real' packages here as the simulation reports a 'Conf broken'
# which is technical correct for the simulation, but testing errormsg is ugly
-cp -a rootdir/var/lib/dpkg/status dpkg.status.backup
-
testloopbreak() {
- cp -a dpkg.status.backup rootdir/var/lib/dpkg/status
- rm -f rootdir/var/lib/apt/extended_states
+ rm -f rootdir/var/lib/dpkg/status rootdir/var/lib/apt/extended_states
testsuccess aptget install advanced=1 -y -t "$1"
testdpkginstalled advanced
diff --git a/test/integration/test-bug-782777-single-arch-weirdness b/test/integration/test-bug-782777-single-arch-weirdness
index 41be1e79c..695d053d3 100755
--- a/test/integration/test-bug-782777-single-arch-weirdness
+++ b/test/integration/test-bug-782777-single-arch-weirdness
@@ -50,7 +50,6 @@ is only available from another source
E: Package 'abar:amd64' has no installation candidate
E: Package 'zfoo:amd64' has no installation candidate" aptget install abar:amd64 zfoo:amd64 -s
- cp -f rootdir/var/lib/dpkg/status status.backup
insertinstalledpackage 'abar' 'i386' '1'
insertinstalledpackage 'zfoo' 'i386' '1'
@@ -62,7 +61,7 @@ zfoo set to automatically installed.' aptmark auto abar zfoo
testequal 'abar
zfoo' aptmark showauto abar zfoo
- mv -f status.backup rootdir/var/lib/dpkg/status
+ rm -f rootdir/var/lib/dpkg/status
}
msgmsg 'Single-Arch testrun'
diff --git a/test/integration/test-failing-maintainer-scripts b/test/integration/test-failing-maintainer-scripts
index 8cf2380ee..c2d631634 100755
--- a/test/integration/test-failing-maintainer-scripts
+++ b/test/integration/test-failing-maintainer-scripts
@@ -70,22 +70,21 @@ testmyfailure() {
testmarkedauto 'dependee'
}
-cp -a rootdir/var/lib/dpkg/status rootdir/var/lib/dpkg/status.backup
testmyfailure aptget install failure-preinst -y
-cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
testmyfailure aptget install failure-postinst -y
-cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
testsuccess aptget install failure-prerm -y
testdpkginstalled failure-prerm
testmyfailure aptget purge failure-prerm -y
-cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
testsuccess aptget install failure-postrm -y
testdpkginstalled failure-postrm
testmyfailure aptget purge failure-postrm -y
# FIXME: test with output going to a PTY as it usually does
if false; then
- cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
+ rm -f rootdir/var/lib/dpkg/status
apt install dependee -y || true
apt install failure-postinst -y || true
fi
diff --git a/test/integration/test-policy-pinning b/test/integration/test-policy-pinning
index fccef6da3..dc3192fe9 100755
--- a/test/integration/test-policy-pinning
+++ b/test/integration/test-policy-pinning
@@ -7,6 +7,8 @@ TESTDIR="$(readlink -f "$(dirname "$0")")"
setupenvironment
configarchitecture "i386"
+insertinstalledpackage 'foobar' 'all' '1'
+
buildaptarchive
setupflataptarchive
diff --git a/test/integration/test-ubuntu-bug-1130419-prefer-installed-ma-same-siblings b/test/integration/test-ubuntu-bug-1130419-prefer-installed-ma-same-siblings
index 4ac5e9060..d76602631 100755
--- a/test/integration/test-ubuntu-bug-1130419-prefer-installed-ma-same-siblings
+++ b/test/integration/test-ubuntu-bug-1130419-prefer-installed-ma-same-siblings
@@ -43,7 +43,6 @@ Inst steam:i386 (2 unstable [i386])
Conf libmesa:i386 (2 unstable [i386])
Conf steam:i386 (2 unstable [i386])' aptget install steam -st unstable
-cp rootdir/var/lib/dpkg/status default-status.dpkg
insertinstalledpackage 'libmesa' 'amd64' '1' 'Multi-Arch: same'
testsuccessequal 'Reading package lists...
Building dependency tree...
@@ -72,7 +71,7 @@ Conf libmesa (2 unstable [amd64])
Conf libmesa:i386 (2 unstable [i386])
Conf steam:i386 (2 unstable [i386])' aptget install steam -st unstable
-cp default-status.dpkg rootdir/var/lib/dpkg/status
+rm -f rootdir/var/lib/dpkg/status
insertinstalledpackage 'libmesa-lts' 'amd64' '1' 'Provides: libmesa
Conflicts: libmesa
Multi-Arch: same'
diff --git a/test/integration/test-ubuntu-bug-784473-InRelease-one-message-only b/test/integration/test-ubuntu-bug-784473-InRelease-one-message-only
index fe42ba83d..80e41f2c2 100755
--- a/test/integration/test-ubuntu-bug-784473-InRelease-one-message-only
+++ b/test/integration/test-ubuntu-bug-784473-InRelease-one-message-only
@@ -28,6 +28,10 @@ done
testfailure aptget update
testsuccess grep '^E:.*Clearsigned file .*NOSPLIT.*' rootdir/tmp/testfailure.output
+testsuccessequal "Package files:
+Pinned packages:" aptcache policy
+
+insertinstalledpackage 'foo' 'all' '1'
ROOTDIR="$(readlink -f .)"
testsuccessequal "Package files:
diff --git a/test/integration/test-unpack-different-version-unpacked b/test/integration/test-unpack-different-version-unpacked
index bcb483639..e7da64ceb 100755
--- a/test/integration/test-unpack-different-version-unpacked
+++ b/test/integration/test-unpack-different-version-unpacked
@@ -9,11 +9,8 @@ configarchitecture 'amd64' 'i386'
insertpackage 'unstable' 'libqtcore4' 'i386,amd64' '2' 'Multi-Arch: same'
setupaptarchive
-DPKGSTATUS='rootdir/var/lib/dpkg/status'
-cp $DPKGSTATUS dpkg.status
-
cleanstatus() {
- cp dpkg.status $DPKGSTATUS
+ rm -f rootdir/var/lib/dpkg/status
rm rootdir/var/cache/apt/*.bin
}