Hi,

Le 29/08/2019 à 00:12, Johannes Schauer a écrit :
>
> Ah indeed -- please go ahead!
>

Thanks ! :)

I've made a git patch (see attached file) to be applied on master of
sbuild (tell me if I should make a Debian package patch (in
debian/patches) instead :) ).

It adds a new option "$apt_keep_downloaded_packages" to be used in
sbuild.conf, defaulting to the existing behavior.

I've tested these cases:
- $apt_keep_downloaded_packages is not set
- $apt_keep_downloaded_packages is set to 1
- $apt_keep_downloaded_packages is set to 0

And the result is as I expect it, downloaded packages are kept in the
apt cache only when $apt_keep_downloaded_packages is set to 1, else they
are removed from the cache after installation as in the existing behavior.

-- 
Alexis Murzeau
PGP: B7E6 0EBB 9293 7B06 BDBC  2787 E7BD 1904 F480 937F
From 8dd69fe5fb045d15a88b8822ed23d4a36b13662f Mon Sep 17 00:00:00 2001
From: Alexis Murzeau <amub...@gmail.com>
Date: Thu, 29 Aug 2019 23:43:13 +0200
Subject: [PATCH] Add configuration option to keep downloaded packages by APT
 (Closes: #933723)

sbuild was always setting APT::Keep-Downloaded-Packages to false which
caused downloaded packages to be always deleted from the APT cache after
installation.
This prevented to take advantage of using a persistent package cache to
avoid downloading packages on every sbuild invocation.

The added option "apt_keep_downloaded_packages" is 0 by default, which
cause sbuild to have the same behavior as before, that is setting
APT::Keep-Downloaded-Packages to false.
---
 lib/Sbuild/Conf.pm         | 7 +++++++
 lib/Sbuild/ResolverBase.pm | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index 17680aca..df9207ec 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -871,6 +871,13 @@ $environment_filter = [map /^FOOBAR$/ ? () : $_, 
Dpkg::Build::Info::get_build_en
            HELP => 'APT clean.  1 to enable running "apt-get clean" at the 
start of each build, or 0 to disable.',
            CLI_OPTIONS => ['--apt-clean', '--no-apt-clean']
        },
+       'APT_KEEP_DOWNLOADED_PACKAGES'          => {
+           TYPE => 'BOOL',
+           VARNAME => 'apt_keep_downloaded_packages',
+           GROUP => 'Chroot options',
+           DEFAULT => 0,
+           HELP => 'Keep downloaded packages in cache by APT. Controls 
APT::Keep-Downloaded-Packages option used when downloading dependencies. 1 to 
keep downloaded packages in cache, or 0 to delete them after installation.'
+       },
        'APT_UPDATE'                            => {
            TYPE => 'BOOL',
            VARNAME => 'apt_update',
diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm
index 4c154fe9..9be92e10 100644
--- a/lib/Sbuild/ResolverBase.pm
+++ b/lib/Sbuild/ResolverBase.pm
@@ -115,8 +115,13 @@ sub setup {
     print $F qq(APT::AutoRemove::SuggestsImportant "false";\n);
     print $F qq(APT::AutoRemove::RecommendsImportant "false";\n);
     print $F qq(Acquire::Languages "none";\n); # do not download translations
-    # remove packages from /var/cache/apt/archive/*.deb after installation
-    print $F qq(APT::Keep-Downloaded-Packages "false";\n);
+
+    if ($self->get_conf('APT_KEEP_DOWNLOADED_PACKAGES')) {
+       print $F qq(APT::Keep-Downloaded-Packages "true";\n);
+    } else {
+       # remove packages from /var/cache/apt/archive/*.deb after installation
+       print $F qq(APT::Keep-Downloaded-Packages "false";\n);
+    }
 
     if ($self->get('Split')) {
        print $F "Dir \"$chroot_dir\";\n";
-- 
2.23.0

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to