35 lines
810 B
Ruby
Raw Normal View History

2016-08-18 22:11:42 +03:00
module Hbc::Cache
module_function
def ensure_cache_exists
return if Hbc.cache.exist?
2016-09-20 15:11:33 +02:00
2016-08-18 22:11:42 +03:00
odebug "Creating Cache at #{Hbc.cache}"
Hbc.cache.mkpath
end
def migrate_legacy_cache
2016-09-20 15:11:33 +02:00
return unless Hbc.legacy_cache.exist?
2016-08-18 22:11:42 +03:00
2016-09-20 15:11:33 +02:00
ohai "Migrating cached files to #{Hbc.cache}..."
Hbc.legacy_cache.children.select(&:symlink?).each do |symlink|
file = symlink.readlink
2016-08-18 22:11:42 +03:00
2016-09-20 15:11:33 +02:00
new_name = file.basename
.sub(%r{\-((?:(\d|#{Hbc::DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
'--\1')
2016-08-18 22:11:42 +03:00
2016-09-20 15:11:33 +02:00
renamed_file = Hbc.cache.join(new_name)
2016-08-18 22:11:42 +03:00
2016-09-20 15:11:33 +02:00
if file.exist?
puts "#{file} -> #{renamed_file}"
FileUtils.mv(file, renamed_file)
2016-08-18 22:11:42 +03:00
end
2016-09-20 15:11:33 +02:00
FileUtils.rm(symlink)
2016-08-18 22:11:42 +03:00
end
2016-09-20 15:11:33 +02:00
FileUtils.remove_entry_secure(Hbc.legacy_cache)
2016-08-18 22:11:42 +03:00
end
end