Skip to content

Commit

Permalink
Check to make sure the incomplete file exists before moving it during
Browse files Browse the repository at this point in the history
rollback. Fixes bug #888241.

Change-Id: I98bca574a26f9ab7173ac593d3b32b68d78d2360
  • Loading branch information
Dan Prince committed Nov 9, 2011
1 parent c8de988 commit a7db2db
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions glance/image_cache/drivers/sqlite.py
Expand Up @@ -303,11 +303,14 @@ def commit():

def rollback(e):
with self.get_db() as db:
invalid_path = self.get_image_filepath(image_id, 'invalid')
logger.debug(_("Fetch of cache file failed, rolling back by "
"moving '%(incomplete_path)s' to "
"'%(invalid_path)s'") % locals())
os.rename(incomplete_path, invalid_path)
if os.path.exists(incomplete_path):
invalid_path = self.get_image_filepath(image_id, 'invalid')

logger.debug(_("Fetch of cache file failed, rolling back "
"by moving '%(incomplete_path)s' to "
"'%(invalid_path)s'") % locals())
os.rename(incomplete_path, invalid_path)

db.execute("""DELETE FROM cached_images
WHERE image_id = ?""", (image_id, ))
db.commit()
Expand Down

0 comments on commit a7db2db

Please sign in to comment.