Do not allow age to be a negative number

This commit is contained in:
Daniel A. Wozniak 2018-10-17 13:35:14 -07:00
parent a24d8b8c83
commit 0b033a645f
No known key found for this signature in database
GPG key ID: 166B9D2C06C82D61

View file

@ -134,7 +134,17 @@ def check_file_list_cache(opts, form, list_cache, w_lock):
# st_time can have a greater precision than time, removing
# float precision makes sure age will never be a negative
# number.
age = int(time.time()) - int(cache_stat.st_mtime)
current_time = int(time.time())
file_mtime = int(cache_stat.st_mtime)
if file_mtime > current_time:
log.debug(
'Cache file modified time is in the future, ignoring. '
'file=%s mtime=%s current_time=%s',
list_cache, current_time, file_mtime
)
age = 0
else:
age = current_time - file_mtime
else:
# if filelist does not exists yet, mark it as expired
age = opts.get('fileserver_list_cache_time', 20) + 1