end
file_path = File.join(loc, filename)
- add_file_to_cache(file_path)
+ if validatePkgFile(file_path, pkg_checksum, pkg_size) then
+ add_file_to_cache(file_path)
+ else
+ @log.error "File Validation Failed!!"
+ return nil
+ end
else
@log.info "Cached #{pkg_name} package file.. OK"
end
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)
downloaded_file_path = nil
private
def get_cached_filepath(pkg_filename, pkg_checksum, pkg_size)
-
cached_filepath = "#{@download_path}/#{pkg_filename}"
if File.exist? cached_filepath then
- FileUtils.touch cached_filepath
- checksum = Digest::SHA256.file(cached_filepath).hexdigest
- size = File.size cached_filepath
- if checksum.to_s.eql? pkg_checksum and size.to_s.eql? pkg_size then
+ if validatePkgFile(cached_filepath, pkg_checksum, pkg_size) then
+ FileUtils.touch cached_filepath
return cached_filepath
+ else
+ return nil
end
end
return nil