From c232ed76c78e76c01fcc41687b6b600eee553993 Mon Sep 17 00:00:00 2001 From: Nicholas Kuechler Date: Fri, 28 Feb 2014 11:23:30 -0600 Subject: [PATCH] Catch exception when image cache pruning If a cached image file does not exist, os.stat will throw an exception and the glance-cache-pruner can fail to run when it encounters the non-existent file. Adds a catch for the possible exception and sets file size to 0 so the glance-cache-pruner can successfully run and prune the cache. Change-Id: I55bee82c4a7aa0393d36c603c91adb8b44a7c7a3 Fixes: bug #1286240 --- glance/image_cache/drivers/sqlite.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/glance/image_cache/drivers/sqlite.py b/glance/image_cache/drivers/sqlite.py index b95f63287d..034ab7ad43 100644 --- a/glance/image_cache/drivers/sqlite.py +++ b/glance/image_cache/drivers/sqlite.py @@ -280,8 +280,12 @@ class Driver(base.Driver): return None path = self.get_image_filepath(image_id) - file_info = os.stat(path) - return image_id, file_info[stat.ST_SIZE] + try: + file_info = os.stat(path) + size = file_info[stat.ST_SIZE] + except OSError: + size = 0 + return image_id, size @contextmanager def open_for_write(self, image_id):