core: SyncedFolders middleware saves what it synced
This commit is contained in:
parent
794cd4f287
commit
4557ece4df
|
@ -62,7 +62,21 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @param [Machine] machine The machine that the folders belong to
|
# @param [Machine] machine The machine that the folders belong to
|
||||||
# @param [Hash] folders The result from a {#synced_folders} call.
|
# @param [Hash] folders The result from a {#synced_folders} call.
|
||||||
def save_synced_folders(machine, folders)
|
def save_synced_folders(machine, folders, **opts)
|
||||||
|
if opts[:merge]
|
||||||
|
existing = cached_synced_folders(machine)
|
||||||
|
if existing
|
||||||
|
folders.each do |impl, fs|
|
||||||
|
existing[impl] ||= {}
|
||||||
|
fs.each do |id, data|
|
||||||
|
existing[impl][id] = data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
folders = existing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
machine.data_dir.join("synced_folders").open("w") do |f|
|
machine.data_dir.join("synced_folders").open("w") do |f|
|
||||||
f.write(JSON.dump(folders))
|
f.write(JSON.dump(folders))
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,12 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
folders = synced_folders(env[:machine], env[:synced_folders_config])
|
opts = {
|
||||||
|
cached: !!env[:synced_folders_cached],
|
||||||
|
}
|
||||||
|
|
||||||
|
folders = synced_folders(
|
||||||
|
env[:machine], env[:synced_folders_config], **opts)
|
||||||
|
|
||||||
folders.each do |impl_name, fs|
|
folders.each do |impl_name, fs|
|
||||||
@logger.info("Synced Folder Implementation: #{impl_name}")
|
@logger.info("Synced Folder Implementation: #{impl_name}")
|
||||||
|
@ -82,6 +87,9 @@ module Vagrant
|
||||||
@logger.info("Invoking synced folder enable: #{impl_name}")
|
@logger.info("Invoking synced folder enable: #{impl_name}")
|
||||||
impl.enable(env[:machine], fs, impl_opts(impl_name, env))
|
impl.enable(env[:machine], fs, impl_opts(impl_name, env))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Save the synced folders
|
||||||
|
save_synced_folders(env[:machine], folders, merge: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -158,5 +158,32 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do
|
||||||
})
|
})
|
||||||
expect(result[:nfs]).to eq({ "nfs" => old_folders["nfs"] })
|
expect(result[:nfs]).to eq({ "nfs" => old_folders["nfs"] })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should be able to save and retrieve cached versions" do
|
||||||
|
folders["foo"] = { type: "default" }
|
||||||
|
result = subject.synced_folders(machine)
|
||||||
|
subject.save_synced_folders(machine, result)
|
||||||
|
|
||||||
|
# Clear the folders and set some more
|
||||||
|
folders.clear
|
||||||
|
folders["bar"] = { type: "default" }
|
||||||
|
folders["baz"] = { type: "nfs" }
|
||||||
|
result = subject.synced_folders(machine)
|
||||||
|
subject.save_synced_folders(machine, result, merge: true)
|
||||||
|
|
||||||
|
# Clear one last time
|
||||||
|
folders.clear
|
||||||
|
|
||||||
|
# Read them all back
|
||||||
|
result = subject.synced_folders(machine, nil, cached: true)
|
||||||
|
expect(result.length).to eq(2)
|
||||||
|
expect(result[:default]).to eq({
|
||||||
|
"foo" => { type: "default" },
|
||||||
|
"bar" => { type: "default" },
|
||||||
|
})
|
||||||
|
expect(result[:nfs]).to eq({
|
||||||
|
"baz" => { type: "nfs" }
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
||||||
env[:root_path] = Pathname.new(Dir.mktmpdir)
|
env[:root_path] = Pathname.new(Dir.mktmpdir)
|
||||||
subject.stub(:plugins => plugins)
|
subject.stub(:plugins => plugins)
|
||||||
subject.stub(:synced_folders => synced_folders)
|
subject.stub(:synced_folders => synced_folders)
|
||||||
|
allow(subject).to receive(:save_synced_folders)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should create on the host if specified" do
|
it "should create on the host if specified" do
|
||||||
|
@ -189,7 +190,7 @@ describe Vagrant::Action::Builtin::SyncedFolders do
|
||||||
env[:synced_folders_config] = new_config
|
env[:synced_folders_config] = new_config
|
||||||
|
|
||||||
expect(subject).to receive(:synced_folders).
|
expect(subject).to receive(:synced_folders).
|
||||||
with(machine, new_config).
|
with(machine, new_config, cached: false).
|
||||||
and_return(synced_folders)
|
and_return(synced_folders)
|
||||||
|
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
|
|
Loading…
Reference in New Issue