Skip to content

Commit

Permalink
Try to smooth out the edge cases for cacheReq not ever updating data.
Browse files Browse the repository at this point in the history
 Main problems are:

1. User doesn't know cache is N months old.

2. User uses --enablerepo=updates-testing and that's N months older than
current fedora+updates.
  • Loading branch information
james-antill committed Sep 6, 2013
1 parent 23fcae6 commit ed0218a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,43 @@ def parseCommands(self):
cacheReq = 'write'
if hasattr(cmd, 'cacheRequirement'):
cacheReq = cmd.cacheRequirement(self, self.basecmd, self.extcmds)

# The main thing we want to do here is that if the user has done a
# "yum makecache fast" or has yum-cron running or something, then try
# not to update the repo. caches ... thus. not turning 0.5s ops. into
# 100x longer ops.
# However if the repos. are not in sync. that's probably not going to
# work well (Eg. user enables updates-testing). Also give a warning if
# they are _really_ old.
ts_min = None
ts_max = None
for repo in self.repos.sort():
if not os.path.exists(repo.metadata_cookie):
ts_min = None
break

rts = os.stat(repo.metadata_cookie).st_mtime
if not ts_min:
ts_min = rts
ts_max = rts
elif rts > ts_max:
ts_max = rts
elif rts < ts_min:
ts_min = rts

if ts_min:
# If caches are within 5 days of each other, they are ok to work
# together (lol, random numbers)...
if (ts_max - ts_min) > (60 * 60 * 24 * 5):
ts_min = None
elif ts_max > time.time():
ts_min = None

if not ts_min:
cacheReq = 'write'
elif (time.time() - ts_max) > (60 * 60 * 24 * 14):
self.logger.warning(_("Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast"))

for repo in self.repos.sort():
repo._metadata_cache_req = cacheReq

Expand Down

0 comments on commit ed0218a

Please sign in to comment.