[Title] change cp to ln in client cache
authorhyoun jiil <jiil.hyoun@samsung.com>
Wed, 20 Mar 2013 08:52:19 +0000 (17:52 +0900)
committerhyoun jiil <jiil.hyoun@samsung.com>
Wed, 20 Mar 2013 08:52:19 +0000 (17:52 +0900)
[Type] Enhancement
[Module] Toolchain /
[Priority] Major
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I6902f9e5ff9bdba2ef8a2317c06524441c381da3

src/common/utils.rb
src/pkg_server/client.rb

index e7804ddf1d3a9fe6da74ef0de640c41f53b275f4..8e0aa2c659176a7b3d0e74e63b7c6c4467578505 100644 (file)
@@ -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"
 
index dd3284a7e1b7bbd842b613fad3201a9991edebe0..575527dc19b077e6d1adaafdacbd2c885b3afe76 100644 (file)
@@ -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