From a5cacd2e15d42aa4a1274f211077be3ed8d29f23 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Oct 2010 12:25:32 +0200 Subject: [PATCH] Set permissions to 770 if target path is a directory. Do not move files if they are the same --- src/oca/ruby/OpenNebula/ImageRepository.rb | 53 ++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/oca/ruby/OpenNebula/ImageRepository.rb b/src/oca/ruby/OpenNebula/ImageRepository.rb index b6c040a1e9..e26bace53c 100644 --- a/src/oca/ruby/OpenNebula/ImageRepository.rb +++ b/src/oca/ruby/OpenNebula/ImageRepository.rb @@ -2,8 +2,18 @@ require 'OpenNebula/Image' require 'fileutils' module OpenNebula - class ImageRepository + ############################################################################ + # The ImageRepository class represents and abstraction of the Image + # Repository, and it provides basic operations to manage and mantain it. + # This class is used by the OpenNebula daemon (through the image hook) to + # save and update images, and by the OpenNebula CLI to create and delete + # them + ############################################################################ + class ImageRepository + ######################################################################## + # + ######################################################################## def create(image, template) if image.nil? error_msg = "Image could not be found, aborting." @@ -59,6 +69,9 @@ module OpenNebula return result end + ######################################################################## + # + ######################################################################## def delete(image) if image.nil? error_msg = "Image could not be found, aborting." @@ -80,6 +93,9 @@ module OpenNebula return result end + ######################################################################## + # + ######################################################################## def update_source(image, source) if image.nil? error_msg = "Image could not be found, aborting." @@ -98,12 +114,27 @@ module OpenNebula end private - FS_UTILS = { :dd => "env dd", :mkfs => "env mkfs" } + ######################################################################## + # + ######################################################################## + def set_permissions(source) + if File.directory?(source) + perms = 0770 + else + perms = 0660 + end + + FileUtils.chmod(perms, source) + end + + ######################################################################## + # + ######################################################################## def copy(path, source) if source.nil? or path.nil? return OpenNebula::Error.new("copy Image: missing parameters.") @@ -111,7 +142,7 @@ module OpenNebula begin FileUtils.copy(path, source) - FileUtils.chmod(0660, source) + set_permissions(source) rescue Exception => e return OpenNebula::Error.new(e.message) end @@ -119,14 +150,19 @@ module OpenNebula return nil end + ######################################################################## + # + ######################################################################## def move(path, source) if source.nil? or path.nil? return OpenNebula::Error.new("copy Image: missing parameters.") + elsif File.identical?(path,source) + return nil end begin FileUtils.move(path, source) - FileUtils.chmod(0660, source) + set_permissions(source) rescue Exception => e return OpenNebula::Error.new(e.message) end @@ -134,6 +170,9 @@ module OpenNebula return nil end + ######################################################################## + # + ######################################################################## def dd(size, source) if source.nil? or size.nil? return OpenNebula::Error.new("dd Image: missing parameters.") @@ -153,6 +192,9 @@ module OpenNebula return nil end + ######################################################################## + # + ######################################################################## def mkfs(fstype, source) if source.nil? or fstype.nil? return OpenNebula::Error.new("mkfs Image: missing parameters.") @@ -171,6 +213,9 @@ module OpenNebula return nil end + ######################################################################## + # + ######################################################################## def remove(source) if File.exists?(source) begin