[Title] [package server] sync lock file generate
authorhataejun <taejun.ha@samsung.com>
Wed, 9 Jan 2013 12:43:16 +0000 (21:43 +0900)
committerhataejun <taejun.ha@samsung.com>
Wed, 9 Jan 2013 12:43:16 +0000 (21:43 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/pkg_server/distribution.rb

index e301f58f0b10f5d2b3a7113e82b37babdcf5c7aa..e64816d3eb05c8b6b15ba60e36183f2ea3225c4a 100644 (file)
@@ -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")}"