37 lines
865 B
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
module Cache
module_function
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def ensure_cache_exists
return if Hbc.cache.exist?
2016-09-20 15:11:33 +02:00
2016-09-24 13:52:43 +02:00
odebug "Creating Cache at #{Hbc.cache}"
Hbc.cache.mkpath
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def migrate_legacy_cache
return unless Hbc.legacy_cache.exist?
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +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-24 13:52:43 +02:00
new_name = file.basename
.sub(%r{\-((?:(\d|#{DSL::Version::DIVIDER_REGEX})*\-\2*)*[^\-]+)$}x,
'--\1')
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
renamed_file = Hbc.cache.join(new_name)
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
if file.exist?
puts "#{file} -> #{renamed_file}"
FileUtils.mv(file, renamed_file)
end
FileUtils.rm(symlink)
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
FileUtils.remove_entry_secure(Hbc.legacy_cache)
2016-08-18 22:11:42 +03:00
end
end
end