131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/vagrant-commit/command.rb', line 131
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant copybox <source> <target>"
end
argv = parse_options(opts)
src_boxname, target_boxname = argv
if !src_boxname || !target_boxname
raise Vagrant::Errors::CLIInvalidUsage,
help: opts.help.chomp
end
collection = Vagrant::BoxCollection.new(@env.boxes_path)
box = collection.find(src_boxname, :libvirt, "> 0")
if !box
@env.ui.error("Box #{src_boxname} not found")
return 1
end
root_dir = @env.boxes_path
version = "0"
new_box_dir = root_dir.join(target_boxname).join(version).join("libvirt")
if File.exist?(new_box_dir)
ans = @env.ui.ask("Box #{target_boxname} exists. What to do? [use/remove/exit] ")
if ans.strip.downcase == "use"
return 0
elsif ans.strip.downcase == "remove"
FileUtils.rm_rf(new_box_dir)
@env.ui.info("Box removed. You probably want to run vagrant fulldestroy.")
end
return 1
end
new_box_dir.mkpath
new_box_dir.join("metadata.json").open("w") do |f|
f.write(metadata_json())
end
new_box_dir.join("Vagrantfile").open("w") do |f|
f.write(Vagrantfile())
end
src_path = box.directory.join("box.img")
target_path = new_box_dir.join("box.img")
FileUtils.cp(src_path, target_path)
end
|