From 6dc2193813d1e8ee951288c5386296b0a2a5e7b9 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Wed, 14 Aug 2013 20:06:05 -0600 Subject: [PATCH] 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 --- cinder/image/image_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) -- 2.45.2