[Title] Download package file to tmp directory first to synchronize file.
authordonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 30 Aug 2012 12:54:28 +0000 (21:54 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 30 Aug 2012 12:54:28 +0000 (21:54 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/pkg_server/client.rb

index 34d7b4914d9bd932a27a29b94657749a7ac28f11..8bd431e6f5cfbdafe24735fc079c4a336f691c33 100644 (file)
@@ -43,6 +43,7 @@ require "Version"
 require "net/ftp"
 $update_mutex = Mutex.new
 $get_snapshot_mutex = Mutex.new
+$filemove_mutex = Mutex.new
 class Client
 
     # constant
@@ -55,7 +56,7 @@ class Client
        OS_INFO_FILE = "os_info"
        ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"      
     
-    attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :snapshot_path, :snapshots_path, :snapshot_url
+    attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url
 
     public
     # initialize
@@ -93,12 +94,14 @@ class Client
                @support_os_list = []
                @config_dist_path = CONFIG_PATH + "/" + get_flat_serveraddr
                @download_path = @config_dist_path + "/downloads"
+               @tmp_path = @config_dist_path + "/tmp"
                @snapshots_path = @config_dist_path + "/snapshots"
 
         # create directory
                if not File.exist? @config_dist_path then FileUtils.mkdir_p "#{@config_dist_path}" end
                if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
                if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
+               if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
 
         # set log
         if logger.nil? or logger.class.to_s.eql? "String" then
@@ -238,8 +241,6 @@ class Client
 
                file_path = File.join(loc, filename)
             file_local_path.push(file_path)
-
-            @log.info "Downloaded \"#{p} [#{pkg_ver}]\" package file.. OK"
         end
 
         if trace then
@@ -264,6 +265,25 @@ class Client
                end
        end                     
 
+       private
+       def move_downloaded_pkg(filepath, distpath)
+               if filepath.nil? or filepath == "" then return nil end                  
+               filename = filepath.split('/')[-1]
+               if not File.exist? distpath then FileUtils.mkdir_p "#{distpath}" end
+               distfile = File.join(distpath, filename)
+               $filemove_mutex.synchronize {
+                       if not File.exist? distfile then
+                               Utils.execute_shell("mv #{filepath} #{distfile}")
+                       else 
+                               Utils.execute_shell("rm -f #{filepath}")                                
+                               return distfile 
+                       end
+               }
+
+               if File.exist? distfile then return distfile
+               else return nil end
+       end                     
+
        private
        def remove_snapshots()
                listing_prefix = "#{@snapshots_path}/*"                 
@@ -1342,14 +1362,28 @@ class Client
         # install package
                cached_filepath = nil
                if Utils.is_linux_like_os( Utils::HOST_OS ) then
+                       @log.info "Checking cached #{pkg_name} package file"                            
                        cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
                end                     
                if not cached_filepath.nil? then
-                       @log.info "\"#{pkg_name}\" will be installed using cached file"                         
+                       @log.info "Installing #{pkg_name} package to [#{@location}] (using cached file)"
             ret = FileInstaller.install(pkg_name, cached_filepath, type, @location, @log)
                else
-                       filepath = download(pkg_name, os, false, @download_path)
-            ret = FileInstaller.install(pkg_name, filepath[0], type, @location, @log)
+                       @log.info "Downloading #{pkg_name} package to [#{@tmp_path}]"                           
+                       filepath = download(pkg_name, os, false, @tmp_path)
+                       if filepath.nil? then
+                               @log.info "Failed to download #{pkg_name}"
+                               return false
+                       end                                     
+                       @log.info "Moving package file [#{@download_path}]"                             
+                       filepath = move_downloaded_pkg(filepath[0], @download_path) 
+                       if filepath.nil? then
+                               @log.info "Failed to move [#{filepath[0]}] to "
+                               @log.info "  [#{@download_path}]"
+                               return false                            
+                       end     
+                       @log.info "Installing #{pkg_name} package to [#{@location}]"                    
+            ret = FileInstaller.install(pkg_name, filepath, type, @location, @log)
                        remove_downloaded_pkgs(pkg_name, os)                            
                end                     
         return ret