vaguerent/plugins/commands/up/middleware/store_box_metadata.rb
Chris Roberts 6c1a9dc58e Store box metadata of active guest
When a guest is created, the box metadata information is stored in the
machine data directory. This allows modifications to happen to the
Vagrantfile definition of the box in use (box name change, box version
change, etc) while still allowing the Machine instance of an active
guest successfully load the box currently backing it.
2018-08-02 11:01:36 -07:00

32 lines
865 B
Ruby

require "json"
module VagrantPlugins
module CommandUp
# Stores metadata information about the box used
# for the current guest. This allows Vagrant to
# determine the box currently in use when the
# Vagrantfile is modified with a new box name or
# version while the guest still exists.
class StoreBoxMetadata
def initialize(app, env)
@app = app
end
def call(env)
box = env[:machine].box
box_meta = {
name: box.name,
version: box.version,
provider: box.provider,
directory: box.directory.sub(Vagrant.user_data_path.to_s + "/", "")
}
meta_file = env[:machine].data_dir.join("box_meta")
File.open(meta_file.to_s, "w+") do |file|
file.write(JSON.dump(box_meta))
end
@app.call(env)
end
end
end
end