From 164afc78399ef90f611039dded2b856c9a1bc1d9 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 21 Mar 2014 19:30:28 -0300 Subject: [PATCH] package: Nicely handle optional `lxc-template` on base boxes when packaging --- lib/vagrant-lxc/action/setup_package_files.rb | 4 +++- spec/unit/action/setup_package_files_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-lxc/action/setup_package_files.rb b/lib/vagrant-lxc/action/setup_package_files.rb index 0132035..a453300 100644 --- a/lib/vagrant-lxc/action/setup_package_files.rb +++ b/lib/vagrant-lxc/action/setup_package_files.rb @@ -43,8 +43,10 @@ module Vagrant def copy_box_files_to_pkg_dir box_dir = @env[:machine].box.directory - FileUtils.cp box_dir.join('lxc-template').to_s, @env['package.directory'].to_s FileUtils.cp box_dir.join('metadata.json').to_s, @env['package.directory'].to_s + if (template = box_dir.join('lxc-template')).exist? + FileUtils.cp template.to_s, @env['package.directory'].to_s + end if (conf = box_dir.join('lxc.conf')).exist? FileUtils.cp conf.to_s, @env['package.directory'].to_s end diff --git a/spec/unit/action/setup_package_files_spec.rb b/spec/unit/action/setup_package_files_spec.rb index 44db639..d427660 100644 --- a/spec/unit/action/setup_package_files_spec.rb +++ b/spec/unit/action/setup_package_files_spec.rb @@ -51,6 +51,16 @@ describe Vagrant::LXC::Action::SetupPackageFiles do end end + context 'when lxc-template file is not present' do + before do + box.directory.join('lxc-template').delete + end + + it 'does not blow up' do + expect { subject.call(env) }.to_not raise_error + end + end + context 'when lxc.conf file is not present' do before do box.directory.join('lxc.conf').delete