mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-13 12:58:17 +03:00
F #4913: Fix vcenter dir_empty? and check if file exists before rm action tries to delete file
This commit is contained in:
parent
18a556b0f1
commit
0c84c4b61b
@ -59,15 +59,33 @@ begin
|
||||
|
||||
img_type = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/TYPE"]
|
||||
|
||||
if img_type != CDROM
|
||||
# delete the disk
|
||||
ds.delete_virtual_disk(img_src)
|
||||
else
|
||||
# delete the CDROM iso
|
||||
ds.delete_file(img_src)
|
||||
end
|
||||
# Check if file exists before trying to delete it
|
||||
ds_name = ds['name']
|
||||
img_path = File.dirname img_src
|
||||
img_name = File.basename img_src
|
||||
|
||||
ds.rm_directory(img_dir) if ds.dir_empty?(img_dir)
|
||||
search_params = ds.get_search_params(ds_name, img_path, img_name)
|
||||
|
||||
# Perform search task and return results
|
||||
begin
|
||||
search_task = ds['browser'].SearchDatastoreSubFolders_Task(search_params)
|
||||
search_task.wait_for_completion
|
||||
|
||||
if img_type != CDROM
|
||||
# delete the disk
|
||||
ds.delete_virtual_disk(img_src)
|
||||
else
|
||||
# delete the CDROM iso
|
||||
ds.delete_file(img_src)
|
||||
end
|
||||
|
||||
ds.rm_directory(img_dir) if ds.dir_empty?(img_dir)
|
||||
|
||||
rescue Exception => e
|
||||
if !e.message.start_with?('FileNotFound')
|
||||
raise e.message # Ignore FileNotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
message = "Error deleting virtual disk #{img_src}."\
|
||||
|
@ -295,7 +295,8 @@ class Datastore < Storage
|
||||
).wait_for_completion
|
||||
rescue Exception => e
|
||||
# Ignore if file not found
|
||||
if !e.message.start_with?('ManagedObjectNotFound')
|
||||
if !e.message.start_with?('ManagedObjectNotFound') &&
|
||||
!e.message.start_with?('FileNotFound')
|
||||
raise e
|
||||
end
|
||||
end
|
||||
@ -312,7 +313,8 @@ class Datastore < Storage
|
||||
).wait_for_completion
|
||||
rescue Exception => e
|
||||
# Ignore if file not found
|
||||
if !e.message.start_with?('ManagedObjectNotFound')
|
||||
if !e.message.start_with?('ManagedObjectNotFound') &&
|
||||
!e.message.start_with?('FileNotFound')
|
||||
raise e
|
||||
end
|
||||
end
|
||||
@ -375,12 +377,18 @@ class Datastore < Storage
|
||||
'searchSpec' => spec
|
||||
}
|
||||
|
||||
ls = self['browser'].SearchDatastoreSubFolders_Task(search_params)
|
||||
|
||||
ls.info.result && ls.info.result.length == 1 && \
|
||||
ls.info.result.first.file.length == 0
|
||||
begin
|
||||
search_task = self['browser'].SearchDatastoreSubFolders_Task(search_params)
|
||||
search_task.wait_for_completion
|
||||
empty = !!search_task.info.result &&
|
||||
search_task.info.result.length == 1 &&
|
||||
search_task.info.result.first.file.length == 0
|
||||
rescue
|
||||
empty = false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def upload_file(source_path, target_path)
|
||||
@item.upload(target_path, source_path)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user