FileUtils.copy_file( "#{snapshot_path}/#{OS_INFO_FILE}",
"#{@location}/snapshots/#{name}/#{OS_INFO_FILE}" )
- # update snapshot.info file information
- tmp_file_name = @location + "/temp/." + Utils.create_uniq_name
- # error check
- if File.exist? tmp_file_name then
- raise "snapshot temp file name already exist"
- end
+ # 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|
File.open( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}", "w" ) do |f| end
end
- def clean( snapshot_list )
+ def clean( remain_snapshot_list )
file_list = []
used_archive_list = []
write_archive_pkg_list
# collect remaning file's name from snapshot list
- for snapshot in snapshot_list
+ for snapshot in remain_snapshot_list
for os in @support_os_list
begin
- pkg_list = Parser.read_repo_pkg_list_from "#{@location}/snapshots/#{snapshot}/#{PKG_LIST_FILE_PREFIX}#{os}"
+ info_file = "#{@location}/snapshots/#{snapshot}/#{PKG_LIST_FILE_PREFIX}#{os}"
+ if not File.exist? info_file then
+ @log.error( "pkg list file does not exist : #{info_file}", Log::LV_USER)
+ next
+ end
+
+ pkg_list = Parser.read_repo_pkg_list_from(info_file)
pkg_list.each_value{ |pkg|
file_list.push(pkg.path.sub("/binary/",""))
}
rescue => e
- @log.error( e.message, Log::USER)
+ @log.error( e.message, Log::LV_USER)
end
end
Dir.new( @location + "/snapshots" ).each do |snapshot|
if snapshot.start_with? "." then next end
- if not snapshot_list.include? snapshot then
+ if not remain_snapshot_list.include? snapshot then
FileUtils.rm_rf "#{@location}/snapshots/#{snapshot}"
end
end
- clean_snapshot_info_file(snapshot_list)
+
+ # upate snapshot.info file
+ update_snapshot_info_file(remain_snapshot_list)
end
def write_all_pkg_list
end
end
- # modify info file
- info_file = File.readlines("#{@location}/#{SNAPSHOT_INFO_FILE}")
- File.open("#{@location}/#{SNAPSHOT_INFO_FILE}", 'w') do |f|
- remove_flag = false
- info_file.each { |line|
- if line =~ /name :/ then
- if snapshot_list.include? line.split(':')[1].strip then
- remove_flag = true
- else
- remove_flag = false
- end
-
- end
-
- if not remove_flag then
- f.puts line
- end
- }
- end
-
if not snapshot_list.empty? then
@log.output( "snapshot not exist : #{snapshot_list.join(",")}", Log::LV_USER )
end
@log.output( "snapshot removed: #{removed_snapshot.join(",")}", Log::LV_USER )
end
- clean_snapshot_info_file(remain_snapshot)
+ update_snapshot_info_file(remain_snapshot)
end
def check_integrity
end
- def clean_snapshot_info_file(snapshot_list)
+ def update_snapshot_info_file(remain_snapshot_list)
if not File.exist? "#{@location}/#{SNAPSHOT_INFO_FILE}"
@log.error "Can not find snapshot info file"
return
end
+ # 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
+
# modify snapshot info File
- f = File.open("#{@location}/#{SNAPSHOT_INFO_FILE}", "r")
- info_lines = []
- save_flag = false
- f.each_line do |l|
- if l.start_with? "name :" then
- if snapshot_list.include? l.split(":")[1].strip then
- save_flag = true
- else
- save_flag = false
+ info_file = File.readlines("#{@location}/#{SNAPSHOT_INFO_FILE}")
+ File.open(tmp_file_name, 'w') do |f|
+ save_flag = false
+ info_file.each { |line|
+ if line =~ /name :/ then
+ if remain_snapshot_list.include? line.split(':')[1].strip then
+ save_flag = true
+ else
+ save_flag = false
+ end
+
end
- end
- if save_flag then
- info_lines.push l
- end
+ if save_flag then
+ f.puts line
+ end
+ }
end
- f.close
- f = File.open("#{@location}/#{SNAPSHOT_INFO_FILE}", "w")
- info_lines.each do |i|
- f.puts i
- end
- f.close
+ FileUtils.mv( tmp_file_name, "#{@location}/#{SNAPSHOT_INFO_FILE}", :force => true )
end
def get_all_reverse_depends_pkgs(pkg, checked_list)