Here is a patch to fix this. I checked every instance of $tmpfilename and only unlinked it after it's no longer used or an error occurs.
Cheers, Miguel
From ee283d286fb728b2aeed449f78120e7a57ba2c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20A=2E=20Col=C3=B3n=20V=C3=A9lez?= <[email protected]> Date: Tue, 15 Sep 2015 00:35:11 -0400 Subject: [PATCH] lib/Sbuild/ResolverBase.pm: Only unlink after the files are no longer needed. The previous commit unlinked the temporary file too early. Unlink it after all the calls using $tmpfilename are done. Also unlink $tmpfilename if there is an error and we exit the routine before we reach the unlink that happens when all calls succeed. --- lib/Sbuild/ResolverBase.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm index 5912a1c..5cefcb6 100644 --- a/lib/Sbuild/ResolverBase.pm +++ b/lib/Sbuild/ResolverBase.pm @@ -1048,7 +1048,6 @@ EOF print $tmpfh "\n"; } close($tmpfh); - unlink $tmpfilename; # Now that we've concat'd all the keys into the chroot, we're going # to use GPG to import the keys into a single keyring. We've stubbed @@ -1064,6 +1063,8 @@ EOF '--keyring', $session->strip_chroot_path($dummy_archive_key_file), $session->strip_chroot_path($tmpfilename)); + unlink $tmpfilename; + $session->run_command( { COMMAND => \@gpg_command, USER => 'root', @@ -1086,7 +1087,7 @@ EOF } close($tmpfh); - unlink $tmpfilename; + # List file needs to be moved with root. $session->run_command( { COMMAND => ['chmod', '0644', $session->strip_chroot_path($tmpfilename)], @@ -1095,6 +1096,7 @@ EOF if ($?) { $self->log("Failed to create apt list file for dummy archive.\n"); $self->cleanup_apt_archive(); + unlink $tmpfilename; return 0; } $session->run_command( @@ -1105,8 +1107,10 @@ EOF if ($?) { $self->log("Failed to create apt list file for dummy archive.\n"); $self->cleanup_apt_archive(); + unlink $tmpfilename; return 0; } + unlink $tmpfilename; } if (!$self->get_conf('APT_ALLOW_UNAUTHENTICATED')) { @@ -1212,7 +1216,6 @@ APT::FTPArchive::Release::Codename "invalid"; APT::FTPArchive::Release::Description "Sbuild Build Dependency Temporary Archive"; EOF close $tmpfh; - unlink $tmpfilename; # Remove APT_CONFIG environment variable here, restore it later. my $env = $self->get('Session')->get('Defaults')->{'ENV'}; @@ -1227,7 +1230,7 @@ EOF DIR => '/'}); if ($?) { $env->{'APT_CONFIG'} = $apt_config_value; - unlink $tmpfilename; + unlink $tmpfilename; return 0; } @@ -1239,7 +1242,7 @@ EOF DIR => '/'}); if (!defined($pipe)) { $env->{'APT_CONFIG'} = $apt_config_value; - unlink $tmpfilename; + unlink $tmpfilename; return 0; } $env->{'APT_CONFIG'} = $apt_config_value; @@ -1249,7 +1252,7 @@ EOF my ($releasefh); if (!open($releasefh, '>', $self->get('Dummy Release file'))) { close $pipe; - unlink $tmpfilename; + unlink $tmpfilename; return 0; } -- 2.5.1

