def Utils.checksum(file_path)
if File.exist? file_path then
- return Utils.execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0]
+ return execute_shell_return("shasum -a 256 \"#{file_path}\"")[0].split(" ")[0]
else
return nil
end
end
+ def Utils.validatePkgFile(filepath, orig_checksum, orig_size)
+ checksum = checksum(filepath)
+ size = File.size filepath
+ if checksum.eql? orig_checksum and size.to_s.eql? orig_size then
+ return true
+ else
+ return false
+ end
+ end
+
def Utils.get_version()
version_file = "#{File.dirname(__FILE__)}/../../VERSION"
return nil
end
- if validatePkgFile(file_path, pkg_checksum, pkg_size) then
+ if Utils.validatePkgFile(file_path, pkg_checksum, pkg_size) then
add_file_to_cache(file_path)
else
@log.error "File Validation Failed!!"
return file_local_path
end
- private
- def validatePkgFile(filepath, orig_checksum, orig_size)
- checksum = Digest::SHA256.file(filepath).hexdigest
- size = File.size filepath
- if checksum.to_s.eql? orig_checksum and size.to_s.eql? orig_size then
- return true
- else
- return false
- end
- end
-
private
def get_file_from_cache(filename, pkg_checksum, pkg_size, location)
+ if not File.directory? location then return nil end
downloaded_file_path = nil
@log.info "Wait for cache sync",Log::LV_USER
$cache_mutex.synchronize do
@log.info "Entering cache sync",Log::LV_USER
cached_filepath = get_cached_filepath(filename, pkg_checksum, pkg_size)
- if not cached_filepath.nil? then
- FileUtils.cp(cached_filepath, location)
+ if not cached_filepath.nil? and File.exist? cached_filepath then
+ FileUtils.ln(cached_filepath, location, :force => true)
downloaded_file_path = File.join(location, File.basename(cached_filepath))
end
end
private
def add_file_to_cache(filepath)
- if filepath.nil? or filepath.empty? then return end
+ if filepath.nil? or filepath.empty? or not File.exist? filepath then return end
if not File.exist? @download_path then FileUtils.mkdir_p "#{@download_path}" end
filename = File.basename(filepath)
@log.info " [path: #{@download_path}]"
if not File.exist? cachefile then
- FileUtils.cp(filepath, @download_path)
+ FileUtils.ln(filepath, @download_path, :force => true)
end
if not File.exist? cachefile then
def get_cached_filepath(pkg_filename, pkg_checksum, pkg_size)
cached_filepath = "#{@download_path}/#{pkg_filename}"
if File.exist? cached_filepath then
- if validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then
+ if Utils.validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then
FileUtils.touch cached_filepath
return cached_filepath
else
if ret then @log.info "Snapshot is generated : #{ret}" end
end
+
end