def sync(force)
pkg_list_update_flag = false
+ archive_update_flag = false
+ distribution_update_flag = false
# check distribution's server_url
if @server_url.empty? then
end
end
+ # sync archive package
+ update_archive_list = sync_archive_pkg()
+
# lock
- Utils.file_lock(@lock_file_path)
+ lock_file = Utils.file_lock(@lock_file_path)
# reload pkg list from newest pkg list file
- reload_binary_pkg_list
+ reload_distribution_information()
# update pkg_list hash
update_pkg_list.each do |update_option, os, pkg|
when "ADD"
new_pkg = @pkg_hash_os[os][pkg.package_name]
- if (not force) and (not new_pkg.nil?) and
- Utils.compare_version(new_pkg.version, pkg.version).eql?(-1) then
- # if package is update then skip
- next
+ if (not force) and (not new_pkg.nil?) then
+ # if updated package 'local' package then skip
+ if new_pkg.origin.eql? "local" then
+ next
+ end
+
+ # if package is update when sync time then skip
+ if Utils.compare_version(new_pkg.version, pkg.version).eql?(-1) then
+ next
+ end
end
@pkg_hash_os[os][pkg.package_name] = pkg
end
end
- # check install dependency integrity
- if @integrity.eql? "YES" then
- @log.info "integrity check"
- check_integrity
- else
- @log.info "skip integrity check"
- end
+ update_archive_list.each do |pkg|
+ if not @archive_pkg_list.include? pkg then
+ @archive_pkg_list.push pkg
+ archive_update_flag = true
+ end
+ end
# update pkg_list file
if pkg_list_update_flag then
write_all_pkg_list()
- return true
- else
- return false
+ distribution_update_flag = true
end
- # uplock
- Utils.file_unlock(@lock_file_path)
- end
-
- def sync_archive_pkg
- client = Client.new( @server_url, "#{@location}/source", @log )
-
- download_list = client.archive_pkg_list - @archive_pkg_list
-
- # if update list is empty then return false
- if download_list.empty? then return false end
-
- updated_file_list = []
-
- download_list.each do |pkg|
- file = client.download_dep_source(pkg)
- if file.nil?
- @log.error("Can't download archive package [#{pkg}]", Log::LV_USER)
- else
- updated_file_list.push pkg
- end
- end
-
- # lock
- Utils.file_lock(@lock_file_path)
-
- # reload archive pkg list
- @archive_pkg_list = read_archive_pkg_list( "" )
-
- # update archive pkg list
- updated_file_list.each do |pkg|
- if not @archive_pkg_list.include? pkg then
- @archive_pkg_list.push pkg
- end
+ # update archive list file
+ if archive_update_flag then
+ write_archive_pkg_list()
+ distribution_update_flag = true
end
- write_archive_pkg_list()
-
- # uplock
- Utils.file_unlock(@lock_file_path)
+ # unlock
+ Utils.file_unlock(lock_file)
- return true
- end
+ return distribution_update_flag
+ end
def add_os(os)
if @support_os_list.include? os then
File.open( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}", "w" ) do |f| end
end
- def remove_os(os)
- if not @support_os_list.include? os then
- @log.error("Can't remove os : #{os} does not exist ", Log::LV_USER)
- end
-
- # update os information
- @support_os_list.delete os
- @pkg_hash_os.delete os
-
- # 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
-
- info_file = File.readlines("#{@location}/#{OS_INFO_FILE}")
- File.open(tmp_file_name, "w") do |f|
- info_file.each do |line|
- if not line.strip.eql? os then
- f.puts line
- end
- end
- end
-
- FileUtils.mv( tmp_file_name, "#{@location}/#{OS_INFO_FILE}", :force => true )
-
- # delete pkg_list_#{os} file
- File.delete( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}" )
- end
-
def clean( remain_snapshot_list )
file_list = []
used_archive_list = []
return rdepends_list
end
- def reload_binary_pkg_list
+ def reload_distribution_information
if not File.exist?("#{@location}/#{OS_INFO_FILE}") then
return
end
end
end
- # read package_list file
+ # read binary package_list file
for os in @support_os_list
@pkg_hash_os[os] = {}
pkg_list_file = "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}"
end
end
end
+
+ # read archive package_list file
+ @archive_pkg_list = read_archive_pkg_list( "" )
+ end
+
+ def remove_os(os)
+ if not @support_os_list.include? os then
+ @log.error("Can't remove os : #{os} does not exist ", Log::LV_USER)
+ end
+
+ # update os information
+ @support_os_list.delete os
+ @pkg_hash_os.delete os
+
+ # 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
+
+ info_file = File.readlines("#{@location}/#{OS_INFO_FILE}")
+ File.open(tmp_file_name, "w") do |f|
+ info_file.each do |line|
+ if not line.strip.eql? os then
+ f.puts line
+ end
+ end
+ end
+
+ FileUtils.mv( tmp_file_name, "#{@location}/#{OS_INFO_FILE}", :force => true )
+
+ # delete pkg_list_#{os} file
+ File.delete( "#{@location}/#{PKG_LIST_FILE_PREFIX}#{os}" )
end
+
+ def sync_archive_pkg
+ client = Client.new( @server_url, "#{@location}/source", @log )
+
+ download_list = client.archive_pkg_list - @archive_pkg_list
+
+ updated_file_list = []
+
+ # if update list is empty then return empty array
+ if download_list.empty? then return updated_file_list end
+
+ download_list.each do |pkg|
+ file = client.download_dep_source(pkg)
+ if file.nil?
+ @log.error("Can't download archive package [#{pkg}]", Log::LV_USER)
+ else
+ updated_file_list.push pkg
+ end
+ end
+
+ return updated_file_list
+ end
+
end