Skip to content

Commit

Permalink
Merge branch 'fix/dpkgchroot' into 'main'
Browse files Browse the repository at this point in the history
Restore dpkg::chroot-directory functionality

See merge request apt-team/apt!178
  • Loading branch information
julian-klode committed Jul 5, 2021
2 parents b1a384c + 8083d40 commit 544d81a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
25 changes: 14 additions & 11 deletions apt-pkg/deb/debsystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() /*{{{*/
Expand Down
1 change: 1 addition & 0 deletions apt-pkg/deb/debsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 11 additions & 19 deletions apt-pkg/deb/dpkgpm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
/*}}}*/
Expand Down Expand Up @@ -1855,18 +1843,22 @@ 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)
{
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);
Expand All @@ -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
{
Expand Down
8 changes: 8 additions & 0 deletions test/integration/test-apt-get-install-deb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ echo 'dpkg::install::recursive "true";
dpkg::install::recursive::force "true";
dpkg::install::recursive::minimum "0";' > rootdir/etc/apt/apt.conf.d/lowerminimum.conf
mv ./incoming/pkg-as-it-should-be_0_all.deb ./incoming/pkg-as-it-should-be_0%3a0+0_all.ddeb
testsuccess aptget install -y ./incoming/pkg-as-it-should-be_0%3a0+0_all.ddeb --reinstall -o Debug::pkgDpkgPm=1
cp rootdir/tmp/testsuccess.output apt.output
testsuccess grep "^${TMPWORKINGDIRECTORY}/.*/dpkg.* --recursive .*/apt-dpkg-install-" apt.output
testsuccess aptget install -y ./incoming/pkg-as-it-should-be_0%3a0+0_all.ddeb --reinstall -o Debug::pkgDpkgPm=1 -o DPkg::Chroot-Directory="${TMPWORKINGDIRECTORY}/rootdir/"
cp rootdir/tmp/testsuccess.output apt.output
testsuccess grep 'dpkg.* --recursive .*/apt-dpkg-install-' apt.output
testfailure grep "^${TMPWORKINGDIRECTORY}/.*/dpkg.* --recursive .*/apt-dpkg-install-" apt.output
testfailure grep "dpkg.* --recursive ${TMPWORKINGDIRECTORY}" apt.output
testsuccess aptget install -y ./incoming/pkg-as-it-should-be_0%3a0+0_all.ddeb --reinstall
testfailure grep 'is already the newest version' rootdir/tmp/testsuccess.output
testsuccess apt purge -y pkg-as-it-should-be
Expand Down

0 comments on commit 544d81a

Please sign in to comment.