Sha256: ae2cdcd816792bc0d4a116b00ac51bd8d130cd0bdb7bfc66413ec5dd9fb0fa60
Contents?: true
Size: 1.29 KB
Versions: 30
Compression:
Stored size: 1.29 KB
Contents
require 'fileutils' module Vagrant class Action module VM # Cleans up the VirtualBox machine folder for any ".xml-prev" # files which VirtualBox may have left over. This is a bug in # VirtualBox. As soon as this is fixed, this middleware can and # will be removed. class CleanMachineFolder def initialize(app, env) @app = app end def call(env) clean_machine_folder @app.call(env) end def clean_machine_folder folder = File.join(VirtualBox::Global.global.system_properties.default_machine_folder, "*") # Small safeguard against potentially unwanted rm-rf, since the default # machine folder will typically always be greater than 10 characters long. # For users with it < 10, out of luck? return if folder.length < 10 Dir[folder].each do |f| next unless File.directory?(f) keep = Dir["#{f}/**/*"].find do |d| # Find a file that doesn't have ".xml-prev" as the suffix, # which signals that we want to keep this folder File.file?(d) && !(File.basename(d) =~ /\.xml-prev$/) end FileUtils.rm_rf(f) if !keep end end end end end end
Version data entries
30 entries across 30 versions & 2 rubygems