diff --git a/hub/kojihub.py b/hub/kojihub.py index 36489de..ac21585 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -56,6 +56,17 @@ def log_error(msg): logging.getLogger('koji.hub').error(msg) +class DirCache(dict): + """Cache directory listings for speed over nfs""" + def __getitem__(self, key): + key = os.path.abspath(key) + if key not in self.keys(): + try: + self[key] = os.listdir(key) + except OSError: + self[key] = [] + return dict.__getitem__(self, key) + class Task(object): """A task for the build hosts""" @@ -1750,6 +1761,8 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None): builds = dict([[build['build_id'],build] for build in builds]) #index the packages by arch packages = {} + # Cache directory listings for speed over nfs + dir_cache = DirCache() for repoarch in repo_arches: packages.setdefault(repoarch, []) for rpminfo in rpms: @@ -1768,7 +1781,8 @@ def repo_init(tag, with_src=False, with_debuginfo=False, event=None): continue build = builds[rpminfo['build_id']] rpminfo['path'] = "%s/%s" % (koji.pathinfo.build(build), koji.pathinfo.rpm(rpminfo)) - if not os.path.exists(rpminfo['path']): + basedir = os.path.dirname(rpminfo['path']) + if not os.path.basename(rpminfo['path']) not in dir_cache[basedir]: logger.warn("Error: no such file: %(path)s" % rpminfo) continue packages.setdefault(repoarch,[]).append(rpminfo)