summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/debsystem.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-06-10 18:06:14 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2021-06-10 19:25:17 +0200
commit8083d4019844f764058efa2a950ed16975178bff (patch)
tree17e99832665981257d251ba4a2e5ea43f496eeb6 /apt-pkg/deb/debsystem.cc
parent06da685fc1abe073c379a34151500fc4d2d853fa (diff)
Restore dpkg::chroot-directory functionality
If we call dpkg inside a chroot we have to ensure that the temporary directory we construct to call dpkg --recursive is inside the chroot and that we strip the path to the chroot from the directory name we pass to dpkg. Note that the added test succeeds before and (hopefully) after as we can't really chroot here or fiddle with the needed settings as we are already setting up apt to work with a quasi-chroot. The test perhaps helps in ensuring we don't break it too much in the future though. (Broken five years (and one day) ago this seems to have an immense user base at the moment, but it might in the future via mmdebstrap) References: f495992428a396e0f98886c9a761a804aa161c68 Reported-By: Johannes Schauer Marin Rodrigues on IRC Tested-By: Johannes Schauer Marin Rodrigues
Diffstat (limited to 'apt-pkg/deb/debsystem.cc')
-rw-r--r--apt-pkg/deb/debsystem.cc25
1 files changed, 14 insertions, 11 deletions
diff --git a/apt-pkg/deb/debsystem.cc b/apt-pkg/deb/debsystem.cc
index a0200305d..c9c6a7e85 100644
--- a/apt-pkg/deb/debsystem.cc
+++ b/apt-pkg/deb/debsystem.cc
@@ -358,19 +358,22 @@ bool debSystem::FindIndex(pkgCache::PkgFileIterator File,
return false;
}
/*}}}*/
-
+std::string debSystem::StripDpkgChrootDirectory(std::string const &File)/*{{{*/
+{
+ // If the filename string begins with DPkg::Chroot-Directory, return the
+ // substr that is within the chroot so dpkg can access it.
+ std::string const chrootdir = _config->FindDir("DPkg::Chroot-Directory","/");
+ size_t len = chrootdir.length();
+ if (chrootdir == "/" || File.compare(0, len, chrootdir) != 0)
+ return File;
+ if (chrootdir.at(len - 1) == '/')
+ --len;
+ return File.substr(len);
+}
+ /*}}}*/
std::string debSystem::GetDpkgExecutable() /*{{{*/
{
- string Tmp = _config->Find("Dir::Bin::dpkg","dpkg");
- string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/");
- size_t dpkgChrootLen = dpkgChrootDir.length();
- if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0)
- {
- if (dpkgChrootDir[dpkgChrootLen - 1] == '/')
- --dpkgChrootLen;
- Tmp = Tmp.substr(dpkgChrootLen);
- }
- return Tmp;
+ return StripDpkgChrootDirectory(_config->Find("Dir::Bin::dpkg","dpkg"));
}
/*}}}*/
std::vector<std::string> debSystem::GetDpkgBaseCommand() /*{{{*/