diff options
| author | Michael E Brown <michael_e_brown@dell.com> | 2007-11-28 15:22:40 -0600 |
|---|---|---|
| committer | Michael E Brown <michael_e_brown@dell.com> | 2007-11-28 15:22:40 -0600 |
| commit | 104bdd6a23e0eb3d4d02255fd357a6ccb158773b (patch) | |
| tree | 8de126115fbc46750f1c1c3ea0e99cc5e3ae27f5 /src/py-libs/plugins/yum_cache.py | |
| parent | 075a03dbee52860bc70f379fefc7de215906d93e (diff) | |
| download | mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.tar.gz mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.tar.xz mock-104bdd6a23e0eb3d4d02255fd357a6ccb158773b.zip | |
first (untested) try at adding offline mode.
Diffstat (limited to 'src/py-libs/plugins/yum_cache.py')
| -rw-r--r-- | src/py-libs/plugins/yum_cache.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/py-libs/plugins/yum_cache.py b/src/py-libs/plugins/yum_cache.py index 230a1a2..72497ff 100644 --- a/src/py-libs/plugins/yum_cache.py +++ b/src/py-libs/plugins/yum_cache.py @@ -31,6 +31,7 @@ class YumCache(object): self.yumSharedCachePath = self.yum_cache_opts['dir'] % self.yum_cache_opts self.state = rootObj.state self.rootdir = rootObj.rootdir + self.online = rootObj.online rootObj.yum_cacheObj = self rootObj.addHook("preyum", self._yumCachePreYumHook) rootObj.addHook("postyum", self._yumCachePostYumHook) @@ -68,24 +69,25 @@ class YumCache(object): self.yumCacheLock = open(os.path.join(self.yumSharedCachePath, "yumcache.lock"), "a+") self._yumCachePreYumHook() - self.state("enabled yum cache, cleaning yum metadata") - for (dirpath, dirnames, filenames) in os.walk(self.yumSharedCachePath): - for filename in filenames: - fullPath = os.path.join(dirpath, filename) - statinfo = os.stat(fullPath) - file_age_days = (time.time() - statinfo.st_ctime) / (60 * 60 * 24) - # prune repodata so yum redownloads. - # prevents certain errors where yum gets stuck due to bad metadata - for ext in (".sqllite", ".xml", ".bz2", ".gz"): - if filename.endswith(ext) and file_age_days > 1: + if self.online: + self.state("enabled yum cache, cleaning yum metadata") + for (dirpath, dirnames, filenames) in os.walk(self.yumSharedCachePath): + for filename in filenames: + fullPath = os.path.join(dirpath, filename) + statinfo = os.stat(fullPath) + file_age_days = (time.time() - statinfo.st_ctime) / (60 * 60 * 24) + # prune repodata so yum redownloads. + # prevents certain errors where yum gets stuck due to bad metadata + for ext in (".sqllite", ".xml", ".bz2", ".gz"): + if filename.endswith(ext) and file_age_days > self.yum_cache_opts['max_metadata_age_days']: + os.unlink(fullPath) + fullPath = None + break + + if fullPath is None: continue + if file_age_days > self.yum_cache_opts['max_age_days']: os.unlink(fullPath) - fullPath = None - break - - if fullPath is None: continue - if file_age_days > self.yum_cache_opts['max_age_days']: - os.unlink(fullPath) - continue + continue self._yumCachePostYumHook() |
