Use bsdtar to repackage boxes

This commit is contained in:
Mitchell Hashimoto 2013-01-28 13:18:07 -08:00
parent 2d2f9577af
commit 35aef1aa0b
1 changed files with 6 additions and 20 deletions

View File

@ -1,10 +1,10 @@
require 'fileutils' require 'fileutils'
require 'archive/tar/minitar'
require "json" require "json"
require "log4r" require "log4r"
require "vagrant/util/platform" require "vagrant/util/platform"
require "vagrant/util/subprocess"
module Vagrant module Vagrant
# Represents a "box," which is a package Vagrant environment that is used # Represents a "box," which is a package Vagrant environment that is used
@ -68,26 +68,12 @@ module Vagrant
def repackage(path) def repackage(path)
@logger.debug("Repackaging box '#{@name}' to: #{path}") @logger.debug("Repackaging box '#{@name}' to: #{path}")
path.open(Util::Platform.tar_file_options) do |f| Dir.chdir(@directory) do
Archive::Tar::Minitar::Output.open(f) do |output|
# Store the current working directory since we need to change
# for the tar library.
current_dir = FileUtils.pwd
begin
FileUtils.cd(@directory)
# Find all the files in our current directory and tar it up! # Find all the files in our current directory and tar it up!
Dir.glob(File.join(".", "**", "*")).each do |entry| files = Dir.glob(File.join(".", "**", "*"))
@logger.debug("Packing file: #{entry}")
Archive::Tar::Minitar.pack_file(entry, output) # Package!
end Util::Subprocess.execute("bsdtar", "-czf", path.to_s, *files)
ensure
# Make sure we always cd back into our previous working
# directory.
FileUtils.cd(current_dir)
end
end
end end
@logger.info("Repackaged box '#{@name}' successfully: #{path}") @logger.info("Repackaged box '#{@name}' successfully: #{path}")