1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Updated cache_valid_time option to check the update timestamp if update-notifier-common is installed.

mtime of the apt lists is used as fallback.
This commit is contained in:
Ingo Gottwald 2013-04-24 22:21:38 +02:00
parent c4df662a7c
commit ad004d520f

View file

@ -122,6 +122,7 @@ DPKG_OPTIONS = '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force
APT_GET_ZERO = "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded." APT_GET_ZERO = "0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
APTITUDE_ZERO = "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded." APTITUDE_ZERO = "0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded."
APT_LISTS_PATH = "/var/lib/apt/lists" APT_LISTS_PATH = "/var/lib/apt/lists"
APT_UPDATE_SUCCESS_STAMP_PATH = "/var/lib/apt/periodic/update-success-stamp"
def package_split(pkgspec): def package_split(pkgspec):
parts = pkgspec.split('=') parts = pkgspec.split('=')
@ -274,7 +275,22 @@ def main():
cache_valid = False cache_valid = False
if p['cache_valid_time']: if p['cache_valid_time']:
tdelta = datetime.timedelta(seconds=p['cache_valid_time']) tdelta = datetime.timedelta(seconds=p['cache_valid_time'])
try:
mtime = os.stat(APT_UPDATE_SUCCESS_STAMP_PATH).st_mtime
except:
mtime = False
if mtime is False:
# Looks like the update-success-stamp is not available
# Fallback: Checking the mtime of the lists
try:
mtime = os.stat(APT_LISTS_PATH).st_mtime mtime = os.stat(APT_LISTS_PATH).st_mtime
except:
mtime = False
if mtime is False:
# No mtime could be read - looks like lists are not there
# We update the cache to be safe
cache_valid = False
else:
mtimestamp = datetime.datetime.fromtimestamp(mtime) mtimestamp = datetime.datetime.fromtimestamp(mtime)
if mtimestamp + tdelta >= datetime.datetime.now(): if mtimestamp + tdelta >= datetime.datetime.now():
# dont update the cache # dont update the cache