From 244d550b817c4ed8ce5ae96b614bff4624576f05 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Fri, 27 Aug 2010 17:06:32 +0200 Subject: [PATCH] Use a finally block & make certain the loop will end --- buildtools/wafsamba/samba_throttle.py | 71 ++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/buildtools/wafsamba/samba_throttle.py b/buildtools/wafsamba/samba_throttle.py index 01a86a90b23..2af70ffc888 100644 --- a/buildtools/wafsamba/samba_throttle.py +++ b/buildtools/wafsamba/samba_throttle.py @@ -25,42 +25,53 @@ def cmp2(x, y): old = Build.BuildContext.compile def compile(self): - old(self) - if not Options.cache_global or Options.options.nocache: - return - - CACHESIZE = 1000 - val = re_num.sub('\\1', os.path.basename(Options.cache_global)) try: - CACHESIZE = int(val) - except: - pass + old(self) + finally: - while 1: - s = dsize(Options.cache_global) - if s < CACHESIZE: - break + if not Options.cache_global or Options.options.nocache: + return - lst = [Options.cache_global + os.sep + x for x in Utils.listdir(Options.cache_global)] + CACHESIZE = 1000 + val = re_num.sub('\\1', os.path.basename(Options.cache_global)) + try: + CACHESIZE = int(val) + except: + pass - acc = [] - for x in lst: - try: - acc.append((x, os.path.getctime(x), dsize(x))) - except: - pass - acc.sort(cmp=cmp2) + for x in range(5): - tot = sum([x[2] for x in acc]) - cur = 0 - while tot - cur > 0.9 * CACHESIZE: - x = acc.pop(0) - cur += x[2] - try: - shutil.rmtree(x[0]) - except: - pass + # loop in case another process is still filling up the cache + s = dsize(Options.cache_global) + if s < CACHESIZE: + break + + lst = [Options.cache_global + os.sep + x for x in Utils.listdir(Options.cache_global)] + + acc = [] + for x in lst: + try: + acc.append((x, os.path.getctime(x), dsize(x))) + except: + pass + + # sort the files by the oldest first + acc.sort(cmp=cmp2) + + tot = sum([x[2] for x in acc]) + cur = 0 + + # remove at least 10% more, just to make sure + while tot - cur > 0.9 * CACHESIZE: + x = acc.pop(0) + cur += x[2] + + # ignore if the folders cannot be removed + try: + shutil.rmtree(x[0]) + except: + pass Build.BuildContext.compile = compile -- 2.11.4.GIT