Commit 2319c8ea authored by csharp@chromium.org's avatar csharp@chromium.org

Better Cache Additional and Removal

Add sanity checking to the json file representing the cache directory to ensure it doesn't add non-existent files.

BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10392110

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137237 0039d316-1c4b-4281-b951-d872f2087c98
parent ac61a855
...@@ -188,14 +188,20 @@ class Cache(object): ...@@ -188,14 +188,20 @@ class Cache(object):
self.min_free_space and self.min_free_space and
self.state and self.state and
get_free_space(self.cache_dir) < self.min_free_space): get_free_space(self.cache_dir) < self.min_free_space):
os.remove(self.path(self.state.pop(0))) try:
os.remove(self.path(self.state.pop(0)))
except OSError as e:
logging.error('Error attempting to delete a file\n%s' % e)
# Ensure maximum cache size. # Ensure maximum cache size.
if self.max_cache_size and self.state: if self.max_cache_size and self.state:
sizes = [os.stat(self.path(f)).st_size for f in self.state] sizes = [os.stat(self.path(f)).st_size for f in self.state]
while sizes and sum(sizes) > self.max_cache_size: while sizes and sum(sizes) > self.max_cache_size:
# Delete the oldest item. # Delete the oldest item.
os.remove(self.path(self.state.pop(0))) try:
os.remove(self.path(self.state.pop(0)))
except OSError as e:
logging.error('Error attempting to delete a file\n%s' % e)
sizes.pop(0) sizes.pop(0)
self.save() self.save()
...@@ -212,7 +218,10 @@ class Cache(object): ...@@ -212,7 +218,10 @@ class Cache(object):
except ValueError: except ValueError:
out = self.path(item) out = self.path(item)
download_or_copy(os.path.join(self.remote, item), out) download_or_copy(os.path.join(self.remote, item), out)
self.state.append(item) if os.path.exists(out):
self.state.append(item)
else:
logging.error('File, %s, not placed in cache' % item)
return True return True
finally: finally:
self.save() self.save()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment