chdir() before 'apt-get update' to accomodate for apt << 1.5 (Debian bug #860738)

pull/1/head
parent b2d5a45932
commit dd5214a8c8
Signed by: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -535,7 +535,7 @@ sub print_progress {
} }
sub run_progress { sub run_progress {
my ($get_exec, $line_handler, $line_has_error) = @_; my ($get_exec, $line_handler, $line_has_error, $chdir) = @_;
pipe my $rfh, my $wfh; pipe my $rfh, my $wfh;
my $got_signal = 0; my $got_signal = 0;
my $ignore = sub { my $ignore = sub {
@ -568,6 +568,13 @@ sub run_progress {
# redirect stderr to stdout so that we can capture it # redirect stderr to stdout so that we can capture it
open(STDERR, '>&', STDOUT); open(STDERR, '>&', STDOUT);
my @execargs = $get_exec->($fd); my @execargs = $get_exec->($fd);
# before apt 1.5, "apt-get update" attempted to chdir() into the
# working directory. This will fail if the current working directory
# is not accessible by the user (for example in unshare mode). See
# Debian bug #860738
if (defined $chdir) {
chdir $chdir or error "failed chdir() to $chdir: $!";
}
exec { $execargs[0] } @execargs or error 'cannot exec() ' . (join ' ', @execargs); exec { $execargs[0] } @execargs or error 'cannot exec() ' . (join ' ', @execargs);
} }
close $wfh; close $wfh;
@ -687,7 +694,7 @@ sub run_apt_progress {
return $2; return $2;
} }
}; };
run_progress $get_exec, $line_handler, $line_has_error; run_progress $get_exec, $line_handler, $line_has_error, $options->{CHDIR};
} }
sub run_chroot(&$) { sub run_chroot(&$) {
@ -1139,7 +1146,7 @@ sub setup {
run_hooks('setup', $options); run_hooks('setup', $options);
info "running apt-get update..."; info "running apt-get update...";
run_apt_progress({ ARGV => ['apt-get', 'update'] }); run_apt_progress({ ARGV => ['apt-get', 'update'], CHDIR => $options->{root} });
# check if anything was downloaded at all # check if anything was downloaded at all
{ {
@ -1670,8 +1677,9 @@ sub setup {
info "cleaning package lists and apt cache..."; info "cleaning package lists and apt cache...";
run_apt_progress({ run_apt_progress({
ARGV => ['apt-get', '--option', 'Dir::Etc::SourceList=/dev/null', 'update'], ARGV => ['apt-get', '--option', 'Dir::Etc::SourceList=/dev/null', 'update'],
CHDIR => $options->{root},
}); });
run_apt_progress({ ARGV => ['apt-get', 'clean'] }); run_apt_progress({ ARGV => ['apt-get', 'clean'], CHDIR => $options->{root} });
# apt since 1.6 creates the auxfiles directory. If apt inside the chroot # apt since 1.6 creates the auxfiles directory. If apt inside the chroot
# is older than that, then it will not know how to clean it. # is older than that, then it will not know how to clean it.

Loading…
Cancel
Save