Skip to content

Commit

Permalink
fix: linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkProminic committed Jan 9, 2024
1 parent 59bbb0d commit ed04b7f
Showing 1 changed file with 15 additions and 26 deletions.
41 changes: 15 additions & 26 deletions lib/vagrant-zones/action/package.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'fileutils'
require "pathname"
require 'pathname'
require 'log4r'
require 'vagrant/util/safe_chdir'
require 'vagrant/util/subprocess'
Expand Down Expand Up @@ -49,41 +49,33 @@ def call(env)
datetime = %(#{t.year}-#{t.month}-#{t.day}-#{t.hour}:#{t.min}:#{t.sec})
snapshot_create(datasetpath, datetime, env[:ui], @machine.provider_config)
snapshot_send(datasetpath, "#{tmp_dir}/box.zss", datetime, env[:ui], @machine.provider_config)
## snapshot_delete(datasetpath, env[:ui], datetime)

# Package VM

## Include User Extra Files
if env['package.include']
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
include_files = files
end
Expand All @@ -93,7 +85,7 @@ def call(env)
## Create the Metadata and Vagrantfile
Dir.chdir(tmp_dir)
File.write('./metadata.json', metadata_content(brand, kernel, vcc, boxshortname))
File.write('./Vagrantfile', vagrantfile_content(brand, kernel, datasetpath))
File.write('./Vagrantfile', vagrantfile_content(brand, kernel))

## Create the Box file
assemble_box(boxname)
Expand Down Expand Up @@ -127,21 +119,18 @@ def metadata_content(brand, _kernel, vcc, boxshortname)
ZONEBOX
end


# This method copies the include files (passed in via command line)
# to the temporary directory so they are included in a sub-folder within
# the actual box
# This method copies the include files (passed in via command line) to the
# temporary directory so they are included in a sub-folder within the actual box
def copy_include_files(include_files, destination, uii)
include_files.each do |from, dest|

include_directory = Pathname.new(destination)

# We place the file in the include directory
to = include_directory.join(dest)
uii.info I18n.t("vagrant.actions.general.package.packaging", file: from)

uii.info I18n.t('vagrant.actions.general.package.packaging', file: from)
FileUtils.mkdir_p(to.parent)

# Copy directory contents recursively.
if File.directory?(from)
FileUtils.cp_r(Dir.glob(from), to.parent, preserve: true)
Expand All @@ -164,13 +153,13 @@ def vagrantfile_content(brand, _kernel, datasetpath)
config.brand = "#{brand}"
end
ZONEBOX
user_vagrantfile = File.expand_path('../Vagrantfile', __FILE__)
load user_vagrantfile if File.exists?(user_vagrantfile)
user_vagrantfile = File.expand_path('Vagrantfile', __dir__)
load user_vagrantfile if File.exist?(user_vagrantfile)
end

def assemble_box(boxname)
is_linux = `bash -c '[[ "$(uname -a)" =~ "Linux" ]]'`
files = Dir.glob(File.join(".", "*"))
files = Dir.glob(File.join('.', '*'))
`tar -cvzf ../#{boxname} #{files.join(' ')}` if is_linux
`tar -cvzEf ../#{boxname} #{files.join(' ')}` unless is_linux
end
Expand Down

0 comments on commit ed04b7f

Please sign in to comment.