Sha256: b501a0ee1a5a923113e753e861d0b11877d894989ae4157bf60465544ef30502

Contents?: true

Size: 697 Bytes

Versions: 45

Compression:

Stored size: 697 Bytes

Contents

require 'fileutils'
require 'tempfile'

# This class provides an easy way of creating a temporary
# directory and having it removed when the application exits.
#
# TODO: This class doesn't currently delete the temporary
# directory on exit.
class Tempdir
  attr_reader :path

  def initialize(basename="vagrant")
    @path = nil

    # Loop and attempt to create a temporary directory until
    # it succeeds.
    while @path.nil?
      file = Tempfile.new(basename)
      @path = file.path
      file.unlink

      begin
        Dir.mkdir(@path)
      rescue
        @path = nil
      end
    end
  end

  # This deletes the temporary directory.
  def unlink
    FileUtils.rm_rf(@path)
  end
end

Version data entries

45 entries across 45 versions & 6 rubygems

Version Path
bmhatfield-vagrant-1.0.10 test/support/tempdir.rb
bmhatfield-vagrant-1.0.9 test/support/tempdir.rb
bmhatfield-vagrant-1.0.8 test/support/tempdir.rb
bmhatfield-vagrant-1.0.7 test/support/tempdir.rb
vagrantup-1.0.7 test/support/tempdir.rb
vagrantup-1.0.6 test/support/tempdir.rb
vagrantup-1.0.5 test/support/tempdir.rb
vagrantup-1.0.4 test/support/tempdir.rb
vagrantup-1.0.3 test/support/tempdir.rb
vagrantup-1.0.2 test/support/tempdir.rb
vagrantup-1.0.1 test/support/tempdir.rb
vagrantup-1.0.0 test/support/tempdir.rb
vagrantup-0.9.99.2 test/support/tempdir.rb
vagrantup-0.9.99.1 test/support/tempdir.rb
vagrantup-0.9.7 test/support/tempdir.rb
vagrantup-0.9.6 test/support/tempdir.rb
vagrantup-0.9.5 test/support/tempdir.rb
vagrantup-0.9.4 test/support/tempdir.rb
vagrantup-0.9.3 test/support/tempdir.rb
vagrantup-0.9.2 test/support/tempdir.rb