Skip to content

Commit

Permalink
Merge pull request #50252 from dwoz/backport_fs_fix
Browse files Browse the repository at this point in the history
[2017.7] backport - Do not allow age to be a negative number
  • Loading branch information
Nicole Thomas committed Oct 30, 2018
2 parents 11fa33e + 59ac284 commit e535b38
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion salt/fileserver/__init__.py
Expand Up @@ -120,7 +120,20 @@ def check_file_list_cache(opts, form, list_cache, w_lock):
if os.path.exists(list_cache):
# calculate filelist age is possible
cache_stat = os.stat(list_cache)
age = time.time() - cache_stat.st_mtime
# st_time can have a greater precision than time, removing
# float precision makes sure age will never be a negative
# number.
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
Expand Down

0 comments on commit e535b38

Please sign in to comment.