]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace os.unlink with delete_if_exists
authorJohn Griffith <john.griffith@solidfire.com>
Thu, 15 Aug 2013 02:06:05 +0000 (20:06 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Thu, 15 Aug 2013 02:08:38 +0000 (20:08 -0600)
Shouldn't care when doing unlink on our temp files
if they exist or not.  In fact this causes problems
when you do things like with tempfile/dir and happen
to try and unlink after it's already been removed.

This replaces these calls with the safer
common.fileutils.delete_if_exists which will
ignore the os exception of the object DNE.

Fixes bug: 1212502

Change-Id: Ica86c95f736411da486335aec5512e59247bfbc0

cinder/image/image_utils.py

index a212ed6265c2dd9c88418a799fd0805a1841616e..2f638ae64d8bff499a85285bc7d71cc066a6cf74 100644 (file)
@@ -314,7 +314,7 @@ def upload_volume(context, image_service, image_meta, volume_path):
 
         with fileutils.file_open(tmp) as image_file:
             image_service.update(context, image_id, {}, image_file)
-        os.unlink(tmp)
+        fileutils.delete_if_exists(tmp)
 
 
 def is_xenserver_image(context, image_service, image_id):
@@ -377,7 +377,7 @@ def temporary_file():
         tmp = create_temporary_file()
         yield tmp
     finally:
-        os.unlink(tmp)
+        fileutils.delete_if_exists(tmp)
 
 
 def temporary_dir():
@@ -417,5 +417,5 @@ def replace_xenserver_image_with_coalesced_vhd(image_file):
         chain = discover_vhd_chain(tempdir)
         fix_vhd_chain(chain)
         coalesced = coalesce_chain(chain)
-        os.unlink(image_file)
+        fileutils.delete_if_exists(image_file)
         rename_file(coalesced, image_file)