From 2b91983cae665f7791aefc6d231470c93732c3a0 Mon Sep 17 00:00:00 2001
From: Robin Gloster <robin@loc-com.de>
Date: Thu, 14 May 2015 12:43:47 +0200
Subject: [PATCH] do not copy the lxc template instead use the full path

---
 lib/vagrant-lxc/driver.rb | 41 +++------------------------------------
 spec/unit/driver_spec.rb  |  2 +-
 templates/sudoers.rb.erb  |  6 ------
 3 files changed, 4 insertions(+), 45 deletions(-)

diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb
index 9fe0993..a7d960f 100644
--- a/lib/vagrant-lxc/driver.rb
+++ b/lib/vagrant-lxc/driver.rb
@@ -79,10 +79,8 @@ module Vagrant
       def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {})
         @cli.name = @container_name = name
 
-        import_template(template_path) do |template_name|
-          @logger.debug "Creating container..."
-          @cli.create template_name, backingstore, backingstore_options, config_file, template_options
-        end
+        @logger.debug "Creating container..."
+        @cli.create template_path, backingstore, backingstore_options, config_file, template_options
       end
 
       def share_folders(folders)
@@ -92,7 +90,7 @@ module Vagrant
       end
 
       def share_folder(host_path, guest_path, mount_options = nil)
-        guest_path      = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
+        guest_path    = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
         mount_options = Array(mount_options || ['bind', 'create=dir'])
         host_path     = host_path.to_s.gsub(' ', '\\\040')
         @customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
@@ -239,39 +237,6 @@ module Vagrant
           @sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s
         end
       end
-
-      def import_template(path)
-        template_name     = "vagrant-tmp-#{@container_name}"
-        tmp_template_path = templates_path.join("lxc-#{template_name}").to_s
-
-        @logger.info 'Copying LXC template into place'
-        @sudo_wrapper.run('cp', path, tmp_template_path)
-        @sudo_wrapper.run('chmod', '+x', tmp_template_path)
-
-        yield template_name
-      ensure
-        @logger.info 'Removing LXC template'
-        if tmp_template_path
-          @sudo_wrapper.run('rm', tmp_template_path)
-        end
-      end
-
-      TEMPLATES_PATH_LOOKUP = %w(
-        /usr/share/lxc/templates
-        /usr/lib/lxc/templates
-        /usr/lib64/lxc/templates
-        /usr/local/lib/lxc/templates
-      )
-      def templates_path
-        return @templates_path if @templates_path
-
-        path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) }
-        if !path
-          raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect
-        end
-
-        @templates_path = Pathname(path)
-      end
     end
   end
 end
diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb
index 0aed4b5..571c2bf 100644
--- a/spec/unit/driver_spec.rb
+++ b/spec/unit/driver_spec.rb
@@ -54,7 +54,7 @@ describe Vagrant::LXC::Driver do
 
     it 'creates container with the right arguments' do
       expect(cli).to have_received(:create).with(
-        template_name,
+        template_path,
         backingstore,
         backingstore_opts,
         config_file,
diff --git a/templates/sudoers.rb.erb b/templates/sudoers.rb.erb
index e9e6fd5..fd4d40c 100644
--- a/templates/sudoers.rb.erb
+++ b/templates/sudoers.rb.erb
@@ -80,7 +80,6 @@ end
 
 base = "/var/lib/lxc"
 base_path = %r{\A#{base}/.*\z}
-templates_path = %r{\A/usr/(share|lib|lib64|local/lib)/lxc/templates/.*\z}
 
 ##
 # Commands from provider.rb
@@ -96,11 +95,6 @@ Whitelist.add '<%= cmd_paths['mkdir'] %>', '-p', base_path
 # - Container config customizations and pruning
 Whitelist.add '<%= cmd_paths['cp'] %>', '-f', %r{/tmp/.*}, base_path
 Whitelist.add '<%= cmd_paths['chown'] %>', 'root:root', base_path
-# - Template import
-Whitelist.add '<%= cmd_paths['cp'] %>', %r{\A.*\z}, templates_path
-Whitelist.add '<%= cmd_paths['chmod'] %>', '+x', templates_path
-# - Template removal
-Whitelist.add '<%= cmd_paths['rm'] %>', templates_path
 # - Packaging
 Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/rootfs.tar.gz}, '-C', base_path, './rootfs'
 Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}