Clean up Action::Clean a bit and get ready to fix GH-8
This commit is contained in:
parent
88a06626a2
commit
24c1d3a8ac
1 changed files with 11 additions and 6 deletions
|
@ -8,29 +8,34 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
@env = env
|
@machine = env[:machine]
|
||||||
|
|
||||||
if env[:machine].state.id == :running && symlinks.any?
|
if should_remove_symlinks?
|
||||||
env[:ui].info I18n.t('vagrant_cachier.cleanup')
|
env[:ui].info I18n.t('vagrant_cachier.cleanup')
|
||||||
symlinks.each do |symlink|
|
symlinks.each do |symlink|
|
||||||
remove_symlink symlink
|
remove_symlink symlink
|
||||||
end
|
end
|
||||||
|
|
||||||
File.delete env[:machine].data_dir.join('cache_dirs').to_s
|
File.delete @machine.data_dir.join('cache_dirs').to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call env
|
@app.call env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def should_remove_symlinks?
|
||||||
|
@logger.info 'Checking if cache symlinks should be removed'
|
||||||
|
symlinks.any? && @machine.state.id == :running
|
||||||
|
end
|
||||||
|
|
||||||
def symlinks
|
def symlinks
|
||||||
# TODO: Check if file exists instead of a blank rescue
|
# TODO: Check if file exists instead of a blank rescue
|
||||||
@symlinks ||= @env[:machine].data_dir.join('cache_dirs').read.split rescue []
|
@symlinks ||= @machine.data_dir.join('cache_dirs').read.split rescue []
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_symlink(symlink)
|
def remove_symlink(symlink)
|
||||||
if @env[:machine].communicate.test("test -L #{symlink}")
|
if @machine.communicate.test("test -L #{symlink}")
|
||||||
@logger.debug "Removing symlink for '#{symlink}'"
|
@logger.debug "Removing symlink for '#{symlink}'"
|
||||||
@env[:machine].communicate.sudo("unlink #{symlink}")
|
@machine.communicate.sudo("unlink #{symlink}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue