From: hyoun jiil Date: Wed, 20 Mar 2013 08:52:19 +0000 (+0900) Subject: [Title] change cp to ln in client cache X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5ac412eb28a146c407d8e28afdce5ff5520e875;p=sdk%2Ftools%2Fsdk-build.git [Title] change cp to ln in client cache [Type] Enhancement [Module] Toolchain / [Priority] Major [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: I6902f9e5ff9bdba2ef8a2317c06524441c381da3 --- diff --git a/src/common/utils.rb b/src/common/utils.rb index e7804dd..8e0aa2c 100644 --- a/src/common/utils.rb +++ b/src/common/utils.rb @@ -540,12 +540,22 @@ class Utils def Utils.checksum(file_path) if File.exist? file_path then - return Utils.execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0] + return execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0] else return nil end end + def Utils.validatePkgFile(filepath, orig_checksum, orig_size) + checksum = checksum(filepath) + size = File.size filepath + if checksum.eql? orig_checksum and size.to_s.eql? orig_size then + return true + else + return false + end + end + def Utils.get_version() version_file = "#{File.dirname(__FILE__)}/../../VERSION" diff --git a/src/pkg_server/client.rb b/src/pkg_server/client.rb index dd3284a..575527d 100644 --- a/src/pkg_server/client.rb +++ b/src/pkg_server/client.rb @@ -324,7 +324,7 @@ class Client return nil end - if validatePkgFile(file_path, pkg_checksum, pkg_size) then + if Utils.validatePkgFile(file_path, pkg_checksum, pkg_size) then add_file_to_cache(file_path) else @log.error "File Validation Failed!!" @@ -344,26 +344,16 @@ class Client return file_local_path end - private - def validatePkgFile(filepath, orig_checksum, orig_size) - checksum = Digest::SHA256.file(filepath).hexdigest - size = File.size filepath - if checksum.to_s.eql? orig_checksum and size.to_s.eql? orig_size then - return true - else - return false - end - end - private def get_file_from_cache(filename, pkg_checksum, pkg_size, location) + if not File.directory? location then return nil end downloaded_file_path = nil @log.info "Wait for cache sync",Log::LV_USER $cache_mutex.synchronize do @log.info "Entering cache sync",Log::LV_USER cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size) - if not cached_filepath.nil? then - FileUtils.cp(cached_filepath, location) + if not cached_filepath.nil? and File.exist? cached_filepath then + FileUtils.ln(cached_filepath, location, :force => true) downloaded_file_path = File.join(location, File.basename(cached_filepath)) end end @@ -376,7 +366,7 @@ class Client private def add_file_to_cache(filepath) - if filepath.nil? or filepath.empty? then return end + if filepath.nil? or filepath.empty? or not File.exist? filepath then return end if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end filename = File.basename(filepath) @@ -386,7 +376,7 @@ class Client @log.info " [path: #{@download_path}]" if not File.exist? cachefile then - FileUtils.cp(filepath, @download_path) + FileUtils.ln(filepath, @download_path, :force => true) end if not File.exist? cachefile then @@ -412,7 +402,7 @@ class Client def get_cached_filepath(pkg_filename, pkg_checksum, pkg_size) cached_filepath = "#{@download_path}/#{pkg_filename}" if File.exist? cached_filepath then - if validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then + if Utils.validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then FileUtils.touch cached_filepath return cached_filepath else @@ -1873,4 +1863,5 @@ class Client if ret then @log.info "Snapshot is generated : #{ret}" end end + end