diff options
author | Brian McCarthy <brian.mccarthy@mongodb.com> | 2018-04-25 16:44:27 -0400 |
---|---|---|
committer | Brian McCarthy <brian.mccarthy@mongodb.com> | 2018-04-27 13:20:42 -0400 |
commit | a4108de09a0703f550ec4f15764f8ad75e756271 (patch) | |
tree | 6d6c06bfdd10fc45d35833566343f1a7437c7bdc | |
parent | e30163d13fcb1d0a09a09a7569089a61d3551754 (diff) | |
download | mongo-a4108de09a0703f550ec4f15764f8ad75e756271.tar.gz |
SERVER-34655 Enhance SCons prune script error checking
-rw-r--r-- | buildscripts/scons_cache_prune.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/buildscripts/scons_cache_prune.py b/buildscripts/scons_cache_prune.py index 74631a9d4de..3f6bc2f400c 100644 --- a/buildscripts/scons_cache_prune.py +++ b/buildscripts/scons_cache_prune.py @@ -43,12 +43,16 @@ def collect_cache_contents(cache_path): "The cache may be corrupt.", file_path) continue - item = CacheItem(path=file_path, time=os.stat(file_path).st_atime, - size=os.stat(file_path).st_size) + try: + item = CacheItem(path=file_path, time=os.stat(file_path).st_atime, + size=os.stat(file_path).st_size) + + total += item.size - total += item.size + contents.append(item) + except OSError as err: + LOGGER.warning("Ignoring error querying file %s : %s", file_path, err) - contents.append(item) return (total, contents) @@ -74,19 +78,17 @@ def prune_cache(cache_path, cache_size_gb, clean_ratio): # just delete things until the total_size falls below the target cache size ratio. while total_size >= cache_size * clean_ratio: if not contents: - shutil.rmtree(cache_path) LOGGER.error("cache size is over quota, and there are no files in " - "the queue to delete. Removed the entire cache.") + "the queue to delete.") return False - # (file_name, _, size) = contents.pop() cache_item = contents.pop() to_remove = cache_item.path + ".del" try: os.rename(cache_item.path, to_remove) - except Exception: # pylint: disable=broad-except + except Exception as err: # pylint: disable=broad-except # another process may have already cleared the file. - pass + LOGGER.warning("Unable to rename %s : %s", cache_item, err) else: try: os.remove(to_remove) |