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
This commit is contained in:
Nicholas Kuechler 2014-02-28 11:23:30 -06:00
parent 9001bf283e
commit c232ed76c7

View File

@ -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):