From 1f1b445af56d06d85c541631ba174cd46ffcbef7 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 31 Jan 2010 09:44:08 +0000 Subject: [PATCH] Merged from trunk -r15292:15298 | 15293 | Fix: change os.mkdir to os.makedirs in case of there are | | volkmar | more than one directory depth missing. According to | | | docs.python.org, permissions may be not respected with | | | os.makedirs... with some systems. | | 15294 | Avoid NameError when cwd is $FILESDIR. Thanks to Christian | | zmedico | Ruppert for reporting. | | 15295 | Bug #302764 - Inside __iter__, only recurse 1 deep, in order | | zmedico | to avoid iteration over entries from another nested cache | | | instance. This can happen if the user nests an overlay | | | inside /usr/portage/local. Thanks to Vlastimil Babka | | | for this patch. | | 15296 | Make __iter__ use list.pop() instead of pop(0), for greater | | zmedico | efficiency. | | 15297 | In __iter__, handle OSError from lstat in case a cache entry | | zmedico | disappears. | | 15298 | Reverting r15293, it was actually not needed. | | volkmar | | svn path=/main/branches/prefix/; revision=15302 --- bin/repoman | 6 ++++++ pym/portage/cache/flat_hash.py | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/repoman b/bin/repoman index 54b466348..3edb2b1ee 100755 --- a/bin/repoman +++ b/bin/repoman @@ -748,6 +748,12 @@ elif repolevel==3: caterror(catdir) scanlist.append(catdir+"/"+reposplit[-1]) repo_subdir = scanlist[-1] + os.sep +else: + msg = 'Repoman is unable to determine PORTDIR or PORTDIR_OVERLAY' + \ + ' from the current working directory' + logging.critical(msg) + sys.exit(1) + repo_subdir_len = len(repo_subdir) scanlist.sort() diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py index 934115805..b014f170d 100644 --- a/pym/portage/cache/flat_hash.py +++ b/pym/portage/cache/flat_hash.py @@ -120,24 +120,32 @@ class database(fs_template.FsBased): def __iter__(self): """generator for walking the dir struct""" - dirs = [self.location] + dirs = [(0, self.location)] len_base = len(self.location) - while len(dirs): + while dirs: + depth, dir_path = dirs.pop() try: - dir_list = os.listdir(dirs[0]) + dir_list = os.listdir(dir_path) except OSError as e: if e.errno != errno.ENOENT: raise del e - dirs.pop(0) continue for l in dir_list: if l.endswith(".cpickle"): continue - p = os.path.join(dirs[0],l) - st = os.lstat(p) + p = os.path.join(dir_path, l) + try: + st = os.lstat(p) + except OSError: + # Cache entry disappeared. + continue if stat.S_ISDIR(st.st_mode): - dirs.append(p) + # Only recurse 1 deep, in order to avoid iteration over + # entries from another nested cache instance. This can + # happen if the user nests an overlay inside + # /usr/portage/local as in bug #302764. + if depth < 1: + dirs.append((depth+1, p)) continue yield p[len_base+1:] - dirs.pop(0) -- 2.26.2