Move package_setup_files to general lib to minimize code duplication
This commit is contained in:
parent
a4d41d0a0e
commit
6ed612e93b
|
@ -0,0 +1,51 @@
|
||||||
|
module Vagrant
|
||||||
|
module Action
|
||||||
|
module General
|
||||||
|
class PackageSetupFiles
|
||||||
|
def initialize(app, env)
|
||||||
|
@app = app
|
||||||
|
|
||||||
|
env["package.include"] ||= []
|
||||||
|
env["package.vagrantfile"] ||= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
files = {}
|
||||||
|
env["package.include"].each do |file|
|
||||||
|
source = Pathname.new(file)
|
||||||
|
dest = nil
|
||||||
|
|
||||||
|
# If the source is relative then we add the file as-is to the include
|
||||||
|
# directory. Otherwise, we copy only the file into the root of the
|
||||||
|
# include directory. Kind of strange, but seems to match what people
|
||||||
|
# expect based on history.
|
||||||
|
if source.relative?
|
||||||
|
dest = source
|
||||||
|
else
|
||||||
|
dest = source.basename
|
||||||
|
end
|
||||||
|
|
||||||
|
# Assign the mapping
|
||||||
|
files[file] = dest
|
||||||
|
end
|
||||||
|
|
||||||
|
if env["package.vagrantfile"]
|
||||||
|
# Vagrantfiles are treated special and mapped to a specific file
|
||||||
|
files[env["package.vagrantfile"]] = "_Vagrantfile"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Verify the mapping
|
||||||
|
files.each do |from, _|
|
||||||
|
raise Vagrant::Errors::PackageIncludeMissing,
|
||||||
|
file: from if !File.exist?(from)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Save the mapping
|
||||||
|
env["package.files"] = files
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,49 +1,14 @@
|
||||||
|
require_relative "../../../../lib/vagrant/action/general/package_setup_files"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HyperV
|
module HyperV
|
||||||
module Action
|
module Action
|
||||||
class PackageSetupFiles
|
class PackageSetupFiles < Vagrant::Action::General::PackageSetupFiles
|
||||||
def initialize(app, env)
|
# Doing this so that we can test that the parent is properly
|
||||||
@app = app
|
# called in the unit tests.
|
||||||
|
alias_method :general_call, :call
|
||||||
env["package.include"] ||= []
|
|
||||||
env["package.vagrantfile"] ||= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
files = {}
|
general_call(env)
|
||||||
env["package.include"].each do |file|
|
|
||||||
source = Pathname.new(file)
|
|
||||||
dest = nil
|
|
||||||
|
|
||||||
# If the source is relative then we add the file as-is to the include
|
|
||||||
# directory. Otherwise, we copy only the file into the root of the
|
|
||||||
# include directory. Kind of strange, but seems to match what people
|
|
||||||
# expect based on history.
|
|
||||||
if source.relative?
|
|
||||||
dest = source
|
|
||||||
else
|
|
||||||
dest = source.basename
|
|
||||||
end
|
|
||||||
|
|
||||||
# Assign the mapping
|
|
||||||
files[file] = dest
|
|
||||||
end
|
|
||||||
|
|
||||||
if env["package.vagrantfile"]
|
|
||||||
# Vagrantfiles are treated special and mapped to a specific file
|
|
||||||
files[env["package.vagrantfile"]] = "_Vagrantfile"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Verify the mapping
|
|
||||||
files.each do |from, _|
|
|
||||||
raise Vagrant::Errors::PackageIncludeMissing,
|
|
||||||
file: from if !File.exist?(from)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Save the mapping
|
|
||||||
env["package.files"] = files
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,49 +1,14 @@
|
||||||
|
require_relative "../../../../lib/vagrant/action/general/package_setup_files"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderVirtualBox
|
module ProviderVirtualBox
|
||||||
module Action
|
module Action
|
||||||
class PackageSetupFiles
|
class PackageSetupFiles < Vagrant::Action::General::PackageSetupFiles
|
||||||
def initialize(app, env)
|
# Doing this so that we can test that the parent is properly
|
||||||
@app = app
|
# called in the unit tests.
|
||||||
|
alias_method :general_call, :call
|
||||||
env["package.include"] ||= []
|
|
||||||
env["package.vagrantfile"] ||= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
files = {}
|
general_call(env)
|
||||||
env["package.include"].each do |file|
|
|
||||||
source = Pathname.new(file)
|
|
||||||
dest = nil
|
|
||||||
|
|
||||||
# If the source is relative then we add the file as-is to the include
|
|
||||||
# directory. Otherwise, we copy only the file into the root of the
|
|
||||||
# include directory. Kind of strange, but seems to match what people
|
|
||||||
# expect based on history.
|
|
||||||
if source.relative?
|
|
||||||
dest = source
|
|
||||||
else
|
|
||||||
dest = source.basename
|
|
||||||
end
|
|
||||||
|
|
||||||
# Assign the mapping
|
|
||||||
files[file] = dest
|
|
||||||
end
|
|
||||||
|
|
||||||
if env["package.vagrantfile"]
|
|
||||||
# Vagrantfiles are treated special and mapped to a specific file
|
|
||||||
files[env["package.vagrantfile"]] = "_Vagrantfile"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Verify the mapping
|
|
||||||
files.each do |from, _|
|
|
||||||
raise Vagrant::Errors::PackageIncludeMissing,
|
|
||||||
file: from if !File.exist?(from)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Save the mapping
|
|
||||||
env["package.files"] = files
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue