Sha256: 6ab34ad25cb15aa4d0e1c4a8678f6d6cc419b2c03fe7be62781304af3e5a6c97

Contents?: true

Size: 1.63 KB

Versions: 10

Compression:

Stored size: 1.63 KB

Contents

require "tempfile"
require "fileutils"
require "pathname"
require "vagrant/util/directory"
require "vagrant/util/subprocess"

module Vagrant
  module Util
    module Caps
      module BuildISO

        # Builds an iso given a compatible iso_command
        #
        # @param [List<String>] command to build iso
        # @param [Pathname] input directory for iso build
        # @param [Pathname] output file for iso build
        def build_iso(iso_command, source_directory, file_destination)
          FileUtils.mkdir_p(file_destination.dirname)
          if !file_destination.exist? || Vagrant::Util::Directory.directory_changed?(source_directory, file_destination.mtime)
            result = Vagrant::Util::Subprocess.execute(*iso_command)
            if result.exit_code != 0
              raise Vagrant::Errors::ISOBuildFailed, cmd: iso_command.join(" "), stdout: result.stdout, stderr: result.stderr
            end
          end
        end

        protected

        def ensure_output_iso(file_destination)
          if file_destination.nil?
            tmpfile = Tempfile.new(["vagrant", ".iso"])
            file_destination = Pathname.new(tmpfile.path)
            tmpfile.close
            tmpfile.unlink
          else
            file_destination = Pathname.new(file_destination.to_s)
            # If the file destination path is a folder, target the output to a randomly named
            # file in that dir
            if file_destination.extname != ".iso"
              file_destination = file_destination.join("#{SecureRandom.hex(3)}_vagrant.iso")
            end
          end
          file_destination
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/util/caps.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/caps.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/caps.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/caps.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/caps.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/caps.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/caps.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/caps.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/caps.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/caps.rb