summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2021-07-05 09:50:05 +0000
committerJulian Andres Klode <jak@debian.org>2021-07-05 09:50:05 +0000
commit544d81a26f8c97a2a45262aecbaef4a5b43fb325 (patch)
tree99d86a27bd049c3f5246393170ce4519e887c141 /apt-pkg
parentb1a384c646427e52abef5bdb799f7bbdbb505bb6 (diff)
parent8083d4019844f764058efa2a950ed16975178bff (diff)
Merge branch 'fix/dpkgchroot' into 'main'
Restore dpkg::chroot-directory functionality See merge request apt-team/apt!178
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/debsystem.cc25
-rw-r--r--apt-pkg/deb/debsystem.h1
-rw-r--r--apt-pkg/deb/dpkgpm.cc30
3 files changed, 26 insertions, 30 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() /*{{{*/
diff --git a/apt-pkg/deb/debsystem.h b/apt-pkg/deb/debsystem.h
index b3d241512..c426faf81 100644
--- a/apt-pkg/deb/debsystem.h
+++ b/apt-pkg/deb/debsystem.h
@@ -43,6 +43,7 @@ class debSystem : public pkgSystem
APT_HIDDEN static std::string GetDpkgExecutable();
APT_HIDDEN static std::vector<std::string> GetDpkgBaseCommand();
APT_HIDDEN static void DpkgChrootDirectory();
+ APT_HIDDEN static std::string StripDpkgChrootDirectory(std::string const &File);
APT_HIDDEN static pid_t ExecDpkg(std::vector<std::string> const &sArgs, int * const inputFd, int * const outputFd, bool const DiscardOutput);
bool MultiArchSupported() const override;
static bool AssertFeature(std::string const &Feature);
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index c1a9f6f68..09d605feb 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -248,19 +248,7 @@ bool pkgDPkgPM::Install(PkgIterator Pkg,string File)
if (File.empty() == true || Pkg.end() == true)
return _error->Error("Internal Error, No file name for %s",Pkg.FullName().c_str());
- // If the filename string begins with DPkg::Chroot-Directory, return the
- // substr that is within the chroot so dpkg can access it.
- string const chrootdir = _config->FindDir("DPkg::Chroot-Directory","/");
- if (chrootdir != "/" && File.find(chrootdir) == 0)
- {
- size_t len = chrootdir.length();
- if (chrootdir.at(len - 1) == '/')
- len--;
- List.push_back(Item(Item::Install,Pkg,File.substr(len)));
- }
- else
- List.push_back(Item(Item::Install,Pkg,File));
-
+ List.emplace_back(Item::Install, Pkg, debSystem::StripDpkgChrootDirectory(File));
return true;
}
/*}}}*/
@@ -1855,6 +1843,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
}
std::unique_ptr<char, decltype(&cleanUpTmpDir)> tmpdir_for_dpkg_recursive{nullptr, &cleanUpTmpDir};
+ std::string const dpkg_chroot_dir = _config->FindDir("DPkg::Chroot-Directory", "/");
// Write in the file or package names
if (I->Op == Item::Install)
@@ -1862,11 +1851,14 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
auto const installsToDo = J - I;
if (dpkg_recursive_install == true && dpkg_recursive_install_min < installsToDo)
{
- std::string tmpdir;
- strprintf(tmpdir, "%s/apt-dpkg-install-XXXXXX", GetTempDir().c_str());
- tmpdir_for_dpkg_recursive.reset(strndup(tmpdir.data(), tmpdir.length()));
- if (mkdtemp(tmpdir_for_dpkg_recursive.get()) == nullptr)
- return _error->Errno("DPkg::Go", "mkdtemp of %s failed in preparation of calling dpkg unpack", tmpdir_for_dpkg_recursive.get());
+ {
+ std::string basetmpdir = (dpkg_chroot_dir == "/") ? GetTempDir() : flCombine(dpkg_chroot_dir, "tmp");
+ std::string tmpdir;
+ strprintf(tmpdir, "%s/apt-dpkg-install-XXXXXX", basetmpdir.c_str());
+ tmpdir_for_dpkg_recursive.reset(strndup(tmpdir.data(), tmpdir.length()));
+ if (mkdtemp(tmpdir_for_dpkg_recursive.get()) == nullptr)
+ return _error->Errno("DPkg::Go", "mkdtemp of %s failed in preparation of calling dpkg unpack", tmpdir_for_dpkg_recursive.get());
+ }
char p = 1;
for (auto c = installsToDo - 1; (c = c/10) != 0; ++p);
@@ -1886,7 +1878,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
return _error->Errno("DPkg::Go", "Symlinking %s to %s failed!", I->File.c_str(), linkpath.c_str());
}
Args.push_back("--recursive");
- Args.push_back(tmpdir_for_dpkg_recursive.get());
+ Args.push_back(debSystem::StripDpkgChrootDirectory(tmpdir_for_dpkg_recursive.get()));
}
else
{