From e6f7bfb02ef254ec6922c1a3b3f9a2c741db6a79 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 19 Sep 2021 19:03:29 +0200 Subject: apt-pkg/deb/dpkgpm.cc: make DPkg::Chroot-Directory work under fakechroot --- apt-pkg/deb/dpkgpm.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index 09d605feb..93effa959 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1874,8 +1874,18 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) strprintf(linkpath, "%s/%.*lu-%s", tmpdir_for_dpkg_recursive.get(), p, n, file.c_str()); else strprintf(linkpath, "%s/%s", tmpdir_for_dpkg_recursive.get(), file.c_str()); - if (symlink(I->File.c_str(), linkpath.c_str()) != 0) - return _error->Errno("DPkg::Go", "Symlinking %s to %s failed!", I->File.c_str(), linkpath.c_str()); + std::string linktarget = I->File; + if (dpkg_chroot_dir != "/") { + char * fakechroot = getenv("FAKECHROOT"); + if (fakechroot != nullptr && strcmp(fakechroot, "true") == 0) { + // if apt is run with DPkg::Chroot-Directory under + // fakechroot, absolulte symbolic links must be prefixed + // with the chroot path to be valid inside fakechroot + strprintf(linktarget, "%s/%s", dpkg_chroot_dir.c_str(), I->File.c_str()); + } + } + if (symlink(linktarget.c_str(), linkpath.c_str()) != 0) + return _error->Errno("DPkg::Go", "Symlinking %s to %s failed!", linktarget.c_str(), linkpath.c_str()); } Args.push_back("--recursive"); Args.push_back(debSystem::StripDpkgChrootDirectory(tmpdir_for_dpkg_recursive.get())); -- cgit v1.2.3-70-g09d2