Merge pull request #9131 from bpietraga/fix-outputh-pathname-folder-creation

Fix --output path with specified folder
This commit is contained in:
Brian Cain 2017-11-15 09:55:32 -08:00 committed by GitHub
commit 401f1d521e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -73,6 +73,8 @@ module Vagrant
self.class.validate!(env["package.output"], env["package.directory"]) self.class.validate!(env["package.output"], env["package.directory"])
package_with_folder_path if env["package.output"].include?(File::SEPARATOR)
raise Errors::PackageOutputDirectory if File.directory?(fullpath) raise Errors::PackageOutputDirectory if File.directory?(fullpath)
@app.call(env) @app.call(env)
@ -83,6 +85,16 @@ module Vagrant
compress compress
end end
def package_with_folder_path
folder_path = File.expand_path("..", @fullpath)
create_box_folder(folder_path) unless File.directory?(folder_path)
end
def create_box_folder(folder_path)
@env[:ui].info(I18n.t("vagrant.actions.general.package.box_folder", folder_path: folder_path))
FileUtils.mkdir_p(folder_path)
end
def recover(env) def recover(env)
@env = env @env = env

View File

@ -2117,6 +2117,7 @@ en:
package: package:
packaging: "Packaging additional file: %{file}" packaging: "Packaging additional file: %{file}"
compressing: "Compressing package to: %{fullpath}" compressing: "Compressing package to: %{fullpath}"
box_folder: "Creating new folder: %{folder_path}"
output_exists: |- output_exists: |-
The specified file '%{filename}' to save the package as already exists. Please The specified file '%{filename}' to save the package as already exists. Please
remove this file or specify a different file name for outputting. remove this file or specify a different file name for outputting.

View File

@ -57,6 +57,18 @@ describe VagrantPlugins::CommandPackage::Command do
expect{ package_command.execute }.to raise_error(Vagrant::Errors::MachineNotFound) expect{ package_command.execute }.to raise_error(Vagrant::Errors::MachineNotFound)
end end
end end
context "with --output option" do
let(:argv){ ['--output', 'package-output-folder/default'] }
it "packages default machine inside specified folder" do
expect(package_command).to receive(:package_vm).with(
a_machine_named('default'), :output => "package-output-folder/default"
)
package_command.execute
end
end
end end
context "with multiple arguments" do context "with multiple arguments" do