summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2008-02-29 16:27:05 -0600
committerClark Williams <williams@redhat.com>2008-02-29 16:27:05 -0600
commit8a37cad09df6b41032e5d1b79995b1c391bb2882 (patch)
treecf2454064c04a681f8ff8384eeafc32e53eb7f71
parent62b7b91c0f1d71f903f7bd81403a29f8d943bbaf (diff)
downloadmock-8a37cad09df6b41032e5d1b79995b1c391bb2882.tar.gz
mock-8a37cad09df6b41032e5d1b79995b1c391bb2882.tar.xz
mock-8a37cad09df6b41032e5d1b79995b1c391bb2882.zip
modify rootcache logic to rebuild cache if config files have newer timestamp
-rwxr-xr-xpy/mock.py4
-rw-r--r--py/mock/backend.py1
-rw-r--r--py/mock/plugins/root_cache.py11
3 files changed, 15 insertions, 1 deletions
diff --git a/py/mock.py b/py/mock.py
index d5afbbe..9935b30 100755
--- a/py/mock.py
+++ b/py/mock.py
@@ -425,9 +425,13 @@ def main(ret):
if options.configdir:
config_path = options.configdir
+ # array to save config paths
+ config_opts['config_paths'] = []
+
# Read in the config files: default, and then user specified
for cfg in ( os.path.join(config_path, 'site-defaults.cfg'), '%s/%s.cfg' % (config_path, options.chroot)):
if os.path.exists(cfg):
+ config_opts['config_paths'].append(cfg)
execfile(cfg)
else:
log.error("Could not find required config file: %s" % cfg)
diff --git a/py/mock/backend.py b/py/mock/backend.py
index 7d11532..6726deb 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -50,6 +50,7 @@ class Root(object):
self._state_log = getLog("mock.Root.state")
# config options
+ self.configs = config['config_paths']
self.chrootuid = config['chrootuid']
self.chrootuser = 'mockbuild'
self.chrootgid = config['chrootgid']
diff --git a/py/mock/plugins/root_cache.py b/py/mock/plugins/root_cache.py
index 9cb0a13..5382912 100644
--- a/py/mock/plugins/root_cache.py
+++ b/py/mock/plugins/root_cache.py
@@ -61,12 +61,21 @@ class RootCache(object):
if self.rootCacheLock is None:
self.rootCacheLock = open(os.path.join(self.rootSharedCachePath, "rootcache.lock"), "a+")
- # check cache age:
+ # check cache status
try:
+ # see if it aged out
statinfo = os.stat(self.rootCacheFile)
file_age_days = (time.time() - statinfo.st_ctime) / (60 * 60 * 24)
if file_age_days > self.root_cache_opts['max_age_days']:
+ getLog().info("root cache aged out! cache will be rebuilt")
os.unlink(self.rootCacheFile)
+ else:
+ # make sure no config file is newer than the cache file
+ for cfg in self.rootObj.configs:
+ if os.stat(cfg).st_mtime > statinfo.st_mtime:
+ getLog().info("%s newer than root cache; cache will be rebuilt" % cfg)
+ os.unlink(self.rootCacheFile)
+ break
except OSError:
pass