lib/vagrant/action/builtin/mixin_synced_folders.rb in vagrant-unbundled-2.2.9.0 vs lib/vagrant/action/builtin/mixin_synced_folders.rb in vagrant-unbundled-2.2.10.0
- old
+ new
@@ -70,11 +70,11 @@
# They can then be retrieved again with `synced_folders` by passing
# the `cached` option to it.
#
# @param [Machine] machine The machine that the folders belong to
# @param [Hash] folders The result from a {#synced_folders} call.
- def save_synced_folders(machine, folders, **opts)
+ def save_synced_folders(machine, folders, opts={})
if opts[:merge]
existing = cached_synced_folders(machine)
if existing
if opts[:vagrantfile]
# Go through and find any cached that were from the
@@ -95,16 +95,13 @@
folders = existing
end
end
- folder_data = JSON.dump(folders)
+ # Remove implementation instances
+ folder_data = JSON.dump(folders.to_h)
- # Scrub any register credentials from the synced folders
- # configuration data to prevent accidental leakage
- folder_data = Util::CredentialScrubber.desensitize(folder_data)
-
machine.data_dir.join("synced_folders").open("w") do |f|
f.write(folder_data)
end
end
@@ -122,11 +119,11 @@
config = machine.config.vm
root = true
end
config_folders = config.synced_folders
- folders = {}
+ folders = Vagrant::Plugin::V2::SyncedFolder::Collection.new
# Determine all the synced folders as well as the implementation
# they're going to use.
config_folders.each do |id, data|
# Ignore disabled synced folders
@@ -179,20 +176,22 @@
folders.delete("")
end
# Apply the scoped hash overrides to get the options
folders.dup.each do |impl_name, fs|
+ impl = plugins[impl_name].first.new._initialize(machine, impl_name)
new_fs = {}
fs.each do |id, data|
+ data[:plugin] = impl
id = data[:id] if data[:id]
new_fs[id] = scoped_hash_override(data, impl_name)
end
folders[impl_name] = new_fs
end
- return folders
+ folders
end
# This finds the difference between two lists of synced folder
# definitions.
#
@@ -237,29 +236,29 @@
end
protected
def cached_synced_folders(machine)
- JSON.parse(machine.data_dir.join("synced_folders").read).tap do |r|
- # We have to do all sorts of things to make the proper things
- # symbols and
- r.keys.each do |k|
- r[k].each do |ik, v|
- v.keys.each do |vk|
- v[vk.to_sym] = v[vk]
- v.delete(vk)
- end
+ import = JSON.parse(machine.data_dir.join("synced_folders").read)
+ import.each do |type, folders|
+ impl = plugins[type.to_sym].first.new._initialize(machine, type.to_sym)
+ folders.each { |_, v| v[:plugin] = impl }
+ end
+ # Symbolize the keys we want as symbols
+ import.keys.dup.each do |k|
+ import[k].values.each do |item|
+ item.keys.dup.each do |ik|
+ item[ik.to_sym] = item.delete(ik)
end
-
- r[k.to_sym] = r[k]
- r.delete(k)
end
+ import[k.to_sym] = import.delete(k)
end
+ Vagrant::Plugin::V2::SyncedFolder::Collection[import]
rescue Errno::ENOENT
# If the file doesn't exist, we probably just have a machine created
# by a version of Vagrant that didn't cache shared folders. Report no
# shared folders to be safe.
- return {}
+ Vagrant::Plugin::V2::SyncedFolder::Collection.new
end
end
end
end
end