apt: create the partial directory before running apt-get update

apt-get complains if the var/lib/apt/lists/partial directory does not
exist or is not owned by the _apt user. Make sure that it is.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-01-04 14:11:04 +01:00
parent 0451c9de3b
commit fd9e4ace47
1 changed files with 9 additions and 0 deletions

View File

@ -126,6 +126,15 @@ class AptConfigurer:
"Cache::SrcPkgCache": None,
}
# Need to ensure the "partial" directory exists.
partial_dir = apt_dirs["State::Lists"] / "partial"
partial_dir.mkdir(
parents=True, exist_ok=True)
try:
shutil.chown(partial_dir, user="_apt")
except (PermissionError, LookupError) as exc:
log.warning("could to set owner of file %s: %r", partial_dir, exc)
apt_cmd = ["apt-get", "update", "-oAPT::Update::Error-Mode=any"]
for key, path in apt_dirs.items():