From: donghee yang Date: Sat, 1 Sep 2012 02:59:34 +0000 (+0900) Subject: [Title] Modified to use download cache when transfering files between machines X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dcc6cf5efefaa0f7b6cb20dcd694a6ceef120312;p=sdk%2Ftools%2Fsdk-build.git [Title] Modified to use download cache when transfering files between machines --- diff --git a/package/pkginfo.manifest b/package/pkginfo.manifest index c82c6cc..b920108 100644 --- a/package/pkginfo.manifest +++ b/package/pkginfo.manifest @@ -1,5 +1,5 @@ Source : dibs -Version :0.99.27 +Version :0.99.28 Maintainer : taejun ha, jiil hyoun , donghyuk yang , donghee yang , sungmin kim e @@ -273,11 +317,57 @@ class BuildCommServer rescue Timeout::Error false end + + + private + def check_download_cache(dst_file, file_size, checksum ) + file_name = File.basename(dst_file) + cache_file = "#{@cache_dir}/#{file_name}" + + @download_cache_mutex.synchronize { + found = false + # check file exist + if File.exist? cache_file and + File.size(cache_file) == file_size and + Utils.checksum(cache_file) == checksum then + + # if hit , touch and copy + FileUtils.touch cache_file + FileUtils.copy_file(cache_file, dst_file) + + found = true + end + + # refresh cache dir + curr_time = Time.now + Dir.entries(@cache_dir).each { |fname| + if fname == "." or fname == ".." then next end + file_path = "#{@cache_dir}/#{fname}" + if File.mtime(file_path) + 3600 < curr_time then + FileUtils.rm_rf file_path + end + } + + return found + } + end + + + private + def add_download_cache(dst_file) + file_name = File.basename(dst_file) + cache_file = "#{@cache_dir}/#{file_name}" + @download_cache_mutex.synchronize { + # copy & touch + FileUtils.copy_file(dst_file, cache_file) + FileUtils.touch cache_file + } + end end class BuildCommClient - VERSION = "1.4.0" + VERSION = "1.5.0" private_class_method :new @@ -451,6 +541,14 @@ class BuildCommClient while line = @socket.gets() if line.strip == "READY" then @log.info "Server is ready to receive file" + file_name = File.basename(src_file) + file_size = File.size(src_file) + checksum = Utils.checksum(src_file) + send "CHECK_CACHE,#{file_name},#{file_size},#{checksum}" + elsif line.strip == "CACHED" then + @log.info "Server already has cached file" + elsif line.strip == "NOT_CACHED" then + @log.info "Server doest not have cached file" ftp_filepath = nil for attempt in ATTEMPTS ftp_filepath = FileTransfer.putfile(ip, port, username, passwd, src_file, @log) diff --git a/src/build_server/SocketJobRequestListener.rb b/src/build_server/SocketJobRequestListener.rb index 3d106ed..4009c72 100644 --- a/src/build_server/SocketJobRequestListener.rb +++ b/src/build_server/SocketJobRequestListener.rb @@ -72,7 +72,8 @@ class SocketJobRequestListener begin ftp_url = Utils.generate_ftp_url(@parent_server.ftp_addr, @parent_server.ftp_port, @parent_server.ftp_username, @parent_server.ftp_passwd) - @comm_server = BuildCommServer.create(@parent_server.port, @log, ftp_url) + cache_dir = "#{@parent_server.transport_path}/.cache" + @comm_server = BuildCommServer.create(@parent_server.port, @log, ftp_url, cache_dir) rescue @log.info "Server creation failed" puts "Server creation failed" diff --git a/src/common/utils.rb b/src/common/utils.rb index 8ee5a88..5972b76 100644 --- a/src/common/utils.rb +++ b/src/common/utils.rb @@ -525,6 +525,14 @@ class Utils end + def Utils.checksum(file_path) + if File.exist? file_path then + return `sha256sum #{file_path}`.split(" ")[0] + else + return nil + end + end + if defined?(HOST_OS).nil? then HOST_OS = Utils.identify_current_OS() end