From 5f1ec978945e38063c99be80ee39320ec50caade Mon Sep 17 00:00:00 2001 From: hataejun Date: Wed, 9 Jan 2013 21:43:16 +0900 Subject: [PATCH] [Title] [package server] sync lock file generate [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] --- src/pkg_server/distribution.rb | 68 ++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/pkg_server/distribution.rb b/src/pkg_server/distribution.rb index e301f58..e64816d 100644 --- a/src/pkg_server/distribution.rb +++ b/src/pkg_server/distribution.rb @@ -40,6 +40,7 @@ class Distribution OS_INFO_FILE = "os_info" SNAPSHOT_INFO_FILE = "snapshot.info" LOCK_FILE = ".lock_file" + SYNC_LOCK_FILE = ".sync_lock_file" def initialize( name, location, server_url, pkg_server ) @@ -49,6 +50,7 @@ class Distribution @log = pkg_server.log @integrity = pkg_server.integrity @lock_file_path = "#{location}/#{LOCK_FILE}" + @sync_lock_file_path = "#{location}/#{SYNC_LOCK_FILE}" @pkg_hash_os = {} @archive_pkg_list = [] @snapshot_hash = [] @@ -156,37 +158,37 @@ class Distribution FileUtils.copy_file( "#{snapshot_path}/#{ARCHIVE_PKG_FILE}", "#{@location}/snapshots/#{name}/#{ARCHIVE_PKG_FILE}" ) - # copy os info file - FileUtils.copy_file( "#{snapshot_path}/#{OS_INFO_FILE}", - "#{@location}/snapshots/#{name}/#{OS_INFO_FILE}" ) - - # generate temp file - tmp_file_name = "" - while ( tmp_file_name.empty? ) - tmp_file_name = @location + "/temp/." + Utils.create_uniq_name - - if File.exist? tmp_file_name then - tmp_file_name = "" - end - end - - FileUtils.copy_file( "#{@location}/#{SNAPSHOT_INFO_FILE}", tmp_file_name ) - File.open( tmp_file_name, "a" ) do |f| - f.puts "name : #{name}" - f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}" - if from_cmd then - f.puts "type : manual" - else - f.puts "type : auto" - end - f.puts "path : /snapshots/#{name}" - f.puts - end - FileUtils.mv( tmp_file_name, "#{@location}/#{SNAPSHOT_INFO_FILE}", :force => true ) - - # snapshot is generated - @log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER) - return name + # copy os info file + FileUtils.copy_file( "#{snapshot_path}/#{OS_INFO_FILE}", + "#{@location}/snapshots/#{name}/#{OS_INFO_FILE}" ) + + # generate temp file + tmp_file_name = "" + while ( tmp_file_name.empty? ) + tmp_file_name = @location + "/temp/." + Utils.create_uniq_name + + if File.exist? tmp_file_name then + tmp_file_name = "" + end + end + + FileUtils.copy_file( "#{@location}/#{SNAPSHOT_INFO_FILE}", tmp_file_name ) + File.open( tmp_file_name, "a" ) do |f| + f.puts "name : #{name}" + f.puts "time : #{Time.now.strftime("%Y%m%d%H%M%S")}" + if from_cmd then + f.puts "type : manual" + else + f.puts "type : auto" + end + f.puts "path : /snapshots/#{name}" + f.puts + end + FileUtils.mv( tmp_file_name, "#{@location}/#{SNAPSHOT_INFO_FILE}", :force => true ) + + # snapshot is generated + @log.output( "snapshot is generated : #{@location}/snapshots/#{name}", Log::LV_USER) + return name end def sync(force, snapshot = "") @@ -194,6 +196,9 @@ class Distribution archive_update_flag = false distribution_update_flag = false changes = [] + + # lock + sync_lock_file = Utils.file_lock(@sync_lock_file_path) # reload pkg list from newest pkg list file reload_distribution_information() @@ -326,6 +331,7 @@ class Distribution # unlock Utils.file_unlock(lock_file) + Utils.file_unlock(sync_lock_file) if not changes.empty? then @last_sync_changes = "SYSTEM: sync parents server \n#{changes.uniq.join("\n\n")}" -- 2.34.1