From: John Griffith Date: Thu, 15 Aug 2013 02:06:05 +0000 (-0600) Subject: Replace os.unlink with delete_if_exists X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6dc2193813d1e8ee951288c5386296b0a2a5e7b9;p=openstack-build%2Fcinder-build.git Replace os.unlink with delete_if_exists 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 --- diff --git a/cinder/image/image_utils.py b/cinder/image/image_utils.py index a212ed626..2f638ae64 100644 --- a/cinder/image/image_utils.py +++ b/cinder/image/image_utils.py @@ -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)