Skip to content

Commit

Permalink
apt: always ensure the ESM cache is present
Browse files Browse the repository at this point in the history
We used to build the base file/folder structure when updating the local
APT cache. However, in some cases, the cache may be accessed before it
is created. In the past an exception was raised and we catched + ignored
it, but from Noble onward this turned to a simple warning on the APT
side.

We fix it by always ensuring the structure is present when trying to
fetch the cache.

Fixes: #3132

Signed-off-by: Renan Rodrigo <[email protected]>
  • Loading branch information
renanrodrigo committed Sep 3, 2024
1 parent eebbfef commit b3760e5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions uaclient/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,24 @@ def get_apt_pkg_cache():

def get_esm_apt_pkg_cache():
try:
# If the rootdir folder doesn't contain any apt source info, the
# cache will be empty
# apt_pkg recently changed behvior: when the cache structure isn't
# present, instead of having an exception raised we only get a
# stderr warning. So we need to ensure all is there, our side.
_ensure_esm_cache_structure()

# Take care to initialize the cache with only the
# Acquire configuration preserved
for key in apt_pkg.config.keys():
if not re.search("^Acquire", key):
apt_pkg.config.clear(key)
apt_pkg.config.set("Dir", ESM_APT_ROOTDIR)
apt_pkg.init()
# If the rootdir folder doesn't contain any apt source info, the
# cache will be empty
# If the structure in the rootdir folder does not exist or is
# incorrect, an exception will be raised

return apt_pkg.Cache(None)
except Exception:
# We don't mind if there is any exception while trying to get the cache
# The empty dictionary will act as an empty cache
return {}

Expand Down

0 comments on commit b3760e5

Please sign in to comment.