Sha256: a6694b6b3abcb38e196b7ec5078057743314eeea4a55c60f1170b551d03bf2ec

Contents?: true

Size: 1.33 KB

Versions: 69

Compression:

Stored size: 1.33 KB

Contents

require "fileutils"

module VagrantPlugins
  module ProviderVirtualBox
    module Action
      # 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(env[:machine].provider.driver.read_machine_folder)
          @app.call(env)
        end

        def clean_machine_folder(machine_folder)
          folder = File.join(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) =~ /\.vbox-prev$/)
            end

            FileUtils.rm_rf(f) if !keep
          end
        end
      end
    end
  end
end

Version data entries

69 entries across 62 versions & 13 rubygems

Version Path
vagrant-unbundled-2.2.6.2 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.6.1 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.6.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.5.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.4.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.3.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.2.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.2.0.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.1.4.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.1.2.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.1.1.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.0.4.0 plugins/providers/virtualbox/action/clean_machine_folder.rb
vagrant-unbundled-2.0.3.0 plugins/providers/virtualbox/action/clean_machine_folder.rb