From 54e580149a011fbd076487f00067831e45ac4153 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Sat, 26 Apr 2014 15:24:25 -0400 Subject: [PATCH] core: return {} if cached synced folders file missing [GH-3550] A missing synced folders cache indicates an empty cache, not a failure that should be handled by the caller. The cache file is missing from data dirs created by an earlier version of Vagrant. Fixes #3550. --- lib/vagrant/action/builtin/mixin_synced_folders.rb | 5 ++++- .../unit/vagrant/action/builtin/mixin_synced_folders_test.rb | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index 0f3889a0d..ab8058fd0 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -214,7 +214,10 @@ module Vagrant end end rescue Errno::ENOENT - return nil + # 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 {} end end end diff --git a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb index a9c4711d2..eb4156cab 100644 --- a/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/mixin_synced_folders_test.rb @@ -136,9 +136,9 @@ describe Vagrant::Action::Builtin::MixinSyncedFolders do expect(result[:nfs]["root"][:foo]).to eql("bar") end - it "returns nil if cached read with no cache" do + it "returns {} if cached read with no cache" do result = subject.synced_folders(machine, cached: true) - expect(result).to be_nil + expect(result).to eql({}) end it "should be able to save and retrieve cached versions" do