require "net/ftp"
$update_mutex = Mutex.new
$get_snapshot_mutex = Mutex.new
+$filemove_mutex = Mutex.new
class Client
# constant
OS_INFO_FILE = "os_info"
ARCHIVE_PKG_LIST_FILE = "archive_pkg_list"
- attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :snapshot_path, :snapshots_path, :snapshot_url
+ attr_accessor :server_addr, :location, :pkg_hash_os, :is_server_remote, :installed_pkg_hash_loc, :archive_pkg_list, :all_dep_list, :log, :support_os_list, :config_dist_path, :download_path, :tmp_path, :snapshot_path, :snapshots_path, :snapshot_url
public
# initialize
@support_os_list = []
@config_dist_path = CONFIG_PATH + "/" + get_flat_serveraddr
@download_path = @config_dist_path + "/downloads"
+ @tmp_path = @config_dist_path + "/tmp"
@snapshots_path = @config_dist_path + "/snapshots"
# create directory
if not File.exist? @config_dist_path then FileUtils.mkdir_p "#{@config_dist_path}" end
if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
if not File.exist? @snapshots_path then FileUtils.mkdir_p "#{@snapshots_path}" end
+ if not File.exist? @tmp_path then FileUtils.mkdir_p "#{@tmp_path}" end
# set log
if logger.nil? or logger.class.to_s.eql? "String" then
file_path = File.join(loc, filename)
file_local_path.push(file_path)
-
- @log.info "Downloaded \"#{p} [#{pkg_ver}]\" package file.. OK"
end
if trace then
end
end
+ private
+ def move_downloaded_pkg(filepath, distpath)
+ if filepath.nil? or filepath == "" then return nil end
+ filename = filepath.split('/')[-1]
+ if not File.exist? distpath then FileUtils.mkdir_p "#{distpath}" end
+ distfile = File.join(distpath, filename)
+ $filemove_mutex.synchronize {
+ if not File.exist? distfile then
+ Utils.execute_shell("mv #{filepath} #{distfile}")
+ else
+ Utils.execute_shell("rm -f #{filepath}")
+ return distfile
+ end
+ }
+
+ if File.exist? distfile then return distfile
+ else return nil end
+ end
+
private
def remove_snapshots()
listing_prefix = "#{@snapshots_path}/*"
# install package
cached_filepath = nil
if Utils.is_linux_like_os( Utils::HOST_OS ) then
+ @log.info "Checking cached #{pkg_name} package file"
cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
end
if not cached_filepath.nil? then
- @log.info "\"#{pkg_name}\" will be installed using cached file"
+ @log.info "Installing #{pkg_name} package to [#{@location}] (using cached file)"
ret = FileInstaller.install(pkg_name, cached_filepath, type, @location, @log)
else
- filepath = download(pkg_name, os, false, @download_path)
- ret = FileInstaller.install(pkg_name, filepath[0], type, @location, @log)
+ @log.info "Downloading #{pkg_name} package to [#{@tmp_path}]"
+ filepath = download(pkg_name, os, false, @tmp_path)
+ if filepath.nil? then
+ @log.info "Failed to download #{pkg_name}"
+ return false
+ end
+ @log.info "Moving package file [#{@download_path}]"
+ filepath = move_downloaded_pkg(filepath[0], @download_path)
+ if filepath.nil? then
+ @log.info "Failed to move [#{filepath[0]}] to "
+ @log.info " [#{@download_path}]"
+ return false
+ end
+ @log.info "Installing #{pkg_name} package to [#{@location}]"
+ ret = FileInstaller.install(pkg_name, filepath, type, @location, @log)
remove_downloaded_pkgs(pkg_name, os)
end
return ret