apt-pkg/deb/dpkgpm.cc: make DPkg::Chroot-Directory work under fakechroot
dpkg::chroot-directory functionality was successfully restored by !178 (merged) -- thanks!
But while apt-get now works inside a real chroot environment, it still fails when run under fakechroot:
$ fakechroot fakeroot apt-get -o Dir=/path/to/chroot -o DPkg::chroot-directory=/path/to/chroot install tzdata
[...]
Chrooting into /path/to/chroot/
dpkg: error: cannot stat pathname '/tmp/apt-dpkg-install-htJPXf/24-tzdata_2021a-1_all.deb': No such file or directory
The reason is, that fakechroot expects that absolute symlinks inside the chroot are prefixed with the full chroot path so that those symlinks are also valid from outside the chroot. But apt creates symlinks such that they are valid as seen from inside a real chroot environment. There are multiple ways to fix this.
- conditionally prefix the symlink target with the chroot path if apt-get is run under fakechroot (this merge request)
- make the absolute symlink a relative one (this is difficult because TMPDIR can be any path so we would have to compute how many .. to put into the path)
- move the chroot() call to before where symlink() is called so that fakechroot creates the symlink as it needs it