[Title] update pkg list for using tmp file
authorhataejun <taejun.ha@samsung.com>
Wed, 22 Aug 2012 13:09:51 +0000 (22:09 +0900)
committerhataejun <taejun.ha@samsung.com>
Wed, 22 Aug 2012 13:09:51 +0000 (22:09 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/pkg_server/distribution.rb

index f9367cf47e6a7c306bc400acb7a293dc3a116d08..7ce2daeb43451218b454c2783e42ebbdb3a980ce 100644 (file)
@@ -431,7 +431,17 @@ class Distribution
                # if input os is empty then return
                if os.nil? or os.empty? then return end 
 
-               File.open( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}", "w" ) do |f| 
+               # 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
+
+               File.open( tmp_file_name, "w" ) do |f| 
                        @pkg_hash_os[os].each_value do |pkg|
                                # insert package information to file 
                                pkg.print_to_file(f)
@@ -439,6 +449,8 @@ class Distribution
                                f.puts 
                        end
                end     
+
+               FileUtils.mv( tmp_file_name, "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}", :force => true ) 
        end
 
        # input: package file path(zip file)