#1147308 sbuild: clean_apt_cache (distclean) clears apt/archives/

#1147308#5
Date:
2026-09-10 18:05:57 UTC
From:
To:
Hi,

my `.sbuildrc` includes (very simplified):

```
$apt_keep_downloaded_packages = 1;
my $donkult_chroot_exec = '%SBUILD_CHROOT_EXEC tar --directory /var/cache/apt/archives --create --file - . | tar --directory /tmp/cache/archives --extract --file -';
$external_commands = {
	"post-build-commands" => [
		$donkult_chroot_exec,
	],
	"post-failed-build-commands" => [
		$donkult_chroot_exec,
	],
};
```

The idea behind this is that I want to extract the *.deb files
sbuild has downloaded from the chroot to integrate them into my
file:///-mirror (my chroots are configured to use APTs mirror method
with file:/// location(s) first and an online source as fallback, so
if the deb is found locally it will just be reused from where ever it
is rather than be downloaded, but if it isn't there it transparently
falls back to the online source -- poor men apt cacher proxy if you
will).

This is broken with the introduction of calling `apt distclean` by
default as that (also) clears the archives/ directory, which I suppose
was not intended, but as its usually empty anyhow it went unnoticed.

Beside breaking my, I suppose, "crazy" setup, it is practically breaking
`$apt_keep_downloaded_packages` as I don't see how you could use that
option successfully now and also the usecase this options doc alludes
to: mounting /var/cache/apt/archives into the chroot directly
(that said, not sure how that would work in a unshare setup through).

It would therefore be nice if `archives/` could be excluded from the
cleanup by default (it will be clean by default anyhow) by e.g. calling
`apt distclean -o Dir::Cache::archives=/nonexistent` instead. I have
tested that this solves my use case, but not if it breaks anything else
(even if I find that unlikely), so this is not a patch.


Ironically, looking around to check if anyone else reported this already
I found the recent MR https://salsa.debian.org/debian/sbuild/-/merge_requests/253
which sounds like it could actually be the perfect place for my
extraction, but I am fine with what exists now.


Best regards

David Kalnischkies