<=>(other)
click to toggle source
def <=>(other)
return unless self.class === other
version.<=>(other.version)
end
==(other)
click to toggle source
def ==(other)
self.class === other && track == other.track && version == other.version && architecture == other.architecture
end
base_path()
click to toggle source
def base_path
@base_path ||= File.join(Proxy::Omaha::Plugin.settings.contentpath, track, architecture)
end
complete?()
click to toggle source
def complete?
missing_files.empty?
end
create()
click to toggle source
def create
logger.debug "Creating #{track} #{version} #{architecture}"
return false unless create_path
return false unless download
return false unless create_metadata
true
end
create_path()
click to toggle source
def create_path
FileUtils.mkdir_p(path)
true
rescue
false
end
current?()
click to toggle source
def current?
return false unless File.symlink?(current_path)
File.readlink(current_path) == path
end
current_path()
click to toggle source
def current_path
@current_path ||= File.join(base_path, 'current')
end
digest_files()
click to toggle source
def digest_files
Dir.glob(File.join(path, '*.DIGESTS')).map { |file| File.basename(file) }
end
digests()
click to toggle source
def digests
@digests ||= load_digests!
end
download()
click to toggle source
def download
sources.map do |url|
file = URI.parse(url).path.split('/').last
next if file_exists?(file)
dst = File.join(path, file)
logger.debug "Downloading file #{url} to #{dst}"
task = ::Proxy::Omaha::HttpDownload.new(url, dst)
task.start
task
end.compact.each(&:join).map(&:result).all?
end
existing_files()
click to toggle source
def existing_files
Dir.glob(File.join(path, '*')).map { |file| File.basename(file) }
end
exists?()
click to toggle source
def exists?
File.directory?(path)
end
expected_files()
click to toggle source
def expected_files
sources.map { |source| File.basename(source) }
end
file_exists?(file)
click to toggle source
def file_exists?(file)
File.file?(File.join(path, file))
end
file_urls(base_url)
click to toggle source
def file_urls(base_url)
existing_files.map do |file|
[base_url, 'omahareleases', track, architecture, self, file].join('/')
end
end
load_digests!()
click to toggle source
def load_digests!
self.digests = {}
digest_files.each do |digest_file|
file = File.basename(digest_file, '.DIGESTS')
File.readlines(File.join(path, digest_file)).each do |line|
next unless line =~ /^\w+[ ]+\S+$/
hexdigest = line.split(/[ ]+/).first
self.digests[file] ||= []
self.digests[file] << hexdigest
end
end
self.digests
end
mark_as_current!()
click to toggle source
def mark_as_current!
return true if current?
File.unlink(current_path) if File.symlink?(current_path)
FileUtils.ln_s(path, current_path)
end
missing_files()
click to toggle source
def missing_files
expected_files - existing_files
end
path()
click to toggle source
def path
@path ||= File.join(base_path, version.to_s)
end
purge()
click to toggle source
def purge
FileUtils.rm(Dir.glob(File.join(path, '*')), :force => true)
FileUtils.remove_dir(path)
true
rescue
false
end
sources()
click to toggle source
def sources
upstream = "https://#{track}.release.core-os.net/#{architecture}/#{version}"
[
"#{upstream}/coreos_production_pxe.vmlinuz",
"#{upstream}/coreos_production_pxe.DIGESTS",
"#{upstream}/coreos_production_image.bin.bz2",
"#{upstream}/coreos_production_image.bin.bz2.sig",
"#{upstream}/coreos_production_image.bin.bz2.DIGESTS",
"#{upstream}/coreos_production_pxe_image.cpio.gz",
"#{upstream}/coreos_production_pxe_image.cpio.gz.DIGESTS",
"#{upstream}/coreos_production_vmware_raw_image.bin.bz2",
"#{upstream}/coreos_production_vmware_raw_image.bin.bz2.sig",
"#{upstream}/coreos_production_vmware_raw_image.bin.bz2.DIGESTS",
"#{upstream}/version.txt",
"#{upstream}/version.txt.DIGESTS",
"https://update.release.core-os.net/#{architecture}/#{version}/update.gz"
]
end
to_h()
click to toggle source
def to_h
{
:name => to_s,
:current => current?,
:architecture => architecture,
:track => track,
:complete => complete?,
:files => existing_files
}
end
to_json()
click to toggle source
def to_json
to_h.to_json
end
to_s()
click to toggle source
def to_s
version.to_s
end
updatefile()
click to toggle source
def updatefile
File.join(path, 'update.gz')
end
valid?()
click to toggle source
def valid?
existing_files.select { |file| file !~ /\.(DIGESTS|sig)$/ }.map do |file|
next unless digests[file]
digests[file].include?(Digest::MD5.file(File.join(path, file)).hexdigest)
end.compact.all?
end