From: donghyuk.yang Date: Wed, 5 Sep 2012 06:18:13 +0000 (+0900) Subject: [Title] Modified installer to check error strict and show log detail X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2600b80fca92779f1126e92ee6136fc0e5addaea;p=sdk%2Ftools%2Fsdk-build.git [Title] Modified installer to check error strict and show log detail [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- diff --git a/src/pkg_server/installer.rb b/src/pkg_server/installer.rb index 6571d7c..26440a6 100644 --- a/src/pkg_server/installer.rb +++ b/src/pkg_server/installer.rb @@ -40,6 +40,7 @@ class FileInstaller CONFIG_PATH = "#{PackageServerConfig::CONFIG_ROOT}/client" PACKAGE_INFO_DIR = ".info" + PACKAGE_MANIFEST = "pkginfo.manifest" def FileInstaller.install(package_name, package_file_path, type, target_path, logger) @@ -60,31 +61,44 @@ class FileInstaller end if not File.exist? path then FileUtils.mkdir_p "#{path}" end - if File.directory? path then - log = "##### create temporary dir : #{path} #####\n" - else - log = "##### [Failed] create temporary dir : #{path} #####\n" - return false - end + if File.directory? path then + log = "## create temporary dir : #{path}\n" + else + logger.error "Failed to create temporary dir" + logger.info " [path: #{path}]" + return false + end begin logger.info "Installing \"#{package_name}\" package.." - logger.info " [src: #{package_file_path}]" - log = log + "##### extract file : #{package_file_path} #####\n" - log = log + extract_file(package_name, package_file_path, path, target_path, logger) - if not move_dir(package_name, path, target_path, logger) then - #Utils.execute_shell("rm -rf #{path}") - return false - end - - log = log + "##### execute install script #####\n" - log = log + execute_install_script(package_name, path, target_path, logger) - - log = log + "##### move remove script #####\n" - move_remove_script(package_name, path, target_path) - - log = log + "##### remove temporary dir : #{path} #####\n" - Utils.execute_shell("rm -rf #{path}") + logger.info " [file: #{package_file_path}]" + + log = log + "## Extract file : #{package_file_path}\n" + result = extract_file(package_name, package_file_path, path, target_path, logger) + if result == "" or result.nil? then return false + else log = log + result end + + log = log + "## Move files : \"#{path}\" to \"#{target_path}\"\n" + result = move_dir(package_name, path, target_path, logger) + if result.nil? then return false + else log = log + result end + + log = log + "## Execute install script\n" + result = execute_install_script(package_name, path, target_path, logger) + if result.nil? then return false + else log = log + result end + + log = log + "## Move remove script\n" + result = move_remove_script(package_name, path, target_path, logger) + if result.nil? then return false + else log = log + result end + + log = log + "## Remove temporary dir : #{path} #####\n" + result = Utils.execute_shell_return("rm -rf #{path}") + if result.nil? then + logger.warn "Failed to remove temporary path" + logger.info " [path: #{path}]" + end rescue Interrupt logger.error "FileInstaller: Interrupted.." Utils.execute_shell("rm -rf #{path}") @@ -106,22 +120,38 @@ class FileInstaller # need verify logger.info "Installed \"#{package_name}\" package.. OK" - logger.info " [dist: #{target_path}]" + logger.info " [path: #{target_path}]" return true; end - def FileInstaller.move_remove_script(package_name, path, target_path) + def FileInstaller.move_remove_script(package_name, path, target_path, logger) target_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}" if not File.exist? target_path then FileUtils.mkdir_p(target_path) end script_file_prefix = "#{path}/remove.*" script_file = Dir.glob(script_file_prefix)[0] + log = "" if not script_file.nil? then - FileUtils.mv(script_file, target_path) - end + result = Utils.execute_shell_return("mv #{script_file} #{target_path}") + if result.nil? then + logger.error "Failed to move a remove script" + logger.info " [file: #{script_file}]" + logger.info " [from: #{path}]" + logger.info " [to: #{target_path}]" + return nil + else log = result.join("") end + logger.info "Moved remove script file.. OK" + log = log + "[file: #{script_file}]\n" + log = log + "[from: #{path}]\n" + log = log + "[to: #{target_path}]\n" + end + + return log end + # Does not verify that the script execution is successful. + # Register shortcut should be failed. def FileInstaller.execute_install_script(package_name, path, target_path, logger) script_file_prefix = "#{path}/install.*" script_file = Dir.glob(script_file_prefix)[0] @@ -133,16 +163,24 @@ class FileInstaller cmd = "set INSTALLED_PATH=\"#{target_path}\"& #{script_file}" else cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}" - end + end + logger.info " [cmd: #{cmd}]" log = `#{cmd}` - end + logger.info "Executed install script file.. OK" + log = log + "[file: #{script_file}]\n" + log = log + "[cmd: #{cmd}]\n" + end + return log end + # Does not verify that the script execution is successful. + # Removing shortcut should be failed. def FileInstaller.execute_remove_script(package_name, target_path, logger) info_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}" if not File.directory? info_path then - return false + logger.error "\"#{info_path}\" does not exist." + return nil end script_file_prefix = "#{info_path}/remove.*" @@ -156,15 +194,22 @@ class FileInstaller else cmd = "INSTALLED_PATH=\"#{target_path}\" #{script_file}" end + logger.info " [cmd: #{cmd}]" log = `#{cmd}` - end + logger.info "Executed remote script file.. OK" + log = log + "[file: #{script_file}]\n" + log = log + "[cmd: #{cmd}]\n" + end + + return log end def FileInstaller.remove_pkg_files(package_name, target_path, logger) list_path = target_path + "/#{PACKAGE_INFO_DIR}/#{package_name}" if not File.directory? list_path then - return false + logger.error "\"#{list_path}\" does not exist." + return false end list_file_name = "#{list_path}/#{package_name}.list" @@ -220,8 +265,9 @@ class FileInstaller def FileInstaller.uninstall(package_name, type, target_path, logger) case type when "binary" then - execute_remove_script(package_name, target_path, logger) - remove_pkg_files(package_name, target_path, logger) + result = execute_remove_script(package_name, target_path, logger) + if result.nil? then return false end + if not remove_pkg_files(package_name, target_path, logger) then return false end when "source" then end @@ -230,24 +276,35 @@ class FileInstaller def FileInstaller.move_dir(package_name, source_path, target_path, logger) config_path = File.join(target_path, PACKAGE_INFO_DIR, package_name) - pkginfo_path = File.join(source_path, "pkginfo.manifest") + pkginfo_path = File.join(source_path, PACKAGE_MANIFEST) data_path = File.join(source_path, "data") + log = "" if not File.exist? pkginfo_path then - logger.error "pkginfo.manifest file does not exist. Check #{source_path}" - return false + logger.error "#{PACKAGE_MANIFEST} file does not exist. Check #{source_path}" + return nil else FileUtils.cp pkginfo_path, config_path end if File.exist? data_path then # if os is linux, use cpio. it is faster than cp if Utils.is_linux_like_os( Utils::HOST_OS ) then absolute_path = `readlink -f #{target_path}` - Utils.execute_shell_return("cd #{data_path}; find . -depth | cpio -pldm #{absolute_path}") + result = Utils.execute_shell_return("cd #{data_path}; find . -depth | cpio -pldm #{absolute_path}") else - Utils.execute_shell_return("cp -r #{data_path}/* #{target_path}") + result = Utils.execute_shell_return("cp -r #{data_path}/* #{target_path}") + end + if result.nil? then + logger.error "Failed to move files" + logger.info " [from: #{source_path}]" + logger.info " [to: #{target_path}]" + return nil end - end - return true + logger.info "Moved files.. OK" + log = log + "[from: #{source_path}]\n" + log = log + "[to: #{target_path}]\n" + else logger.warn "\"data\" directory does not exist." end + + return log end def FileInstaller.extract_file(package_name, package_file_path, path, target_path, logger) @@ -298,14 +355,31 @@ class FileInstaller if Utils.is_windows_like_os( Utils::HOST_OS ) then log = unzip_file(package_file_path, path) else - log = `#{extract_file_list_command}` + result = Utils.execute_shell_return(extract_file_list_command) + if result.nil? then log = nil + else log = result.join("") end end when ".tar" then - log = `#{extract_file_list_command}` - end + result = Utils.execute_shell_return(extract_file_list_command) + if result.nil? then log = nil + else log = result.join("") end + end + + if log == "" then log = nil end + if log.nil? then + logger.error "Failed to extract \"#{filename}\" file" + logger.info " [file: #{package_file_path}]" + logger.info " [from: #{path}]" + logger.info " [to: #{target_path}]" + logger.info " [cmd: #{extract_file_list_command}]" + return nil + end logger.info "Extracted \"#{filename}\" file.. OK" - if log.nil? then log = "" end + log = log + "[file: #{package_file_path}]\n" + log = log + "[from: #{path}]\n" + log = log + "[to: #{target_path}]\n" + log = log + "[cmd: #{extract_file_list_command}]\n" return log end @@ -345,6 +419,9 @@ class FileInstaller return true else logger.warn "Failed to extracted \"#{target_file}\" file.." + logger.info " [file: #{package_file_path}]" + logger.info " [path: #{path}]" + logger.info " [cmd: #{extract_file_command}]" return false end end