From 0a6c4e2d0ff5ed626f17c6e6c02750779b785d7f Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 2 Oct 2019 15:33:23 -0700 Subject: [PATCH] Ensure relative path for file provisioner is relative to machines cwd Prior to this commit, if you ran Vagrant in a different current working directory other than where a current guest machines location is, the file provisioner would not take into account the machines local dir, and would instead use the path where Vagrant was invoked to expand the `source` path option for a file provisioner. This commit fixes that by passing the root path `machine.env.cwd` when expanding the source dir. --- plugins/provisioners/file/provisioner.rb | 2 +- test/unit/plugins/provisioners/file/provisioner_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/file/provisioner.rb b/plugins/provisioners/file/provisioner.rb index 4cc5d7888..65851d32b 100644 --- a/plugins/provisioners/file/provisioner.rb +++ b/plugins/provisioners/file/provisioner.rb @@ -3,7 +3,7 @@ module VagrantPlugins class Provisioner < Vagrant.plugin("2", :provisioner) def provision @machine.communicate.tap do |comm| - source = File.expand_path(config.source) + source = File.expand_path(config.source, @machine.env.cwd) destination = expand_guest_path(config.destination) # If the source is a directory determine if any path modifications diff --git a/test/unit/plugins/provisioners/file/provisioner_test.rb b/test/unit/plugins/provisioners/file/provisioner_test.rb index 7f3c954ba..d79f5db2f 100644 --- a/test/unit/plugins/provisioners/file/provisioner_test.rb +++ b/test/unit/plugins/provisioners/file/provisioner_test.rb @@ -65,7 +65,7 @@ describe VagrantPlugins::FileUpload::Provisioner do allow(config).to receive(:destination).and_return("/foo/bar") expect(communicator).to receive(:upload).with( - File.expand_path("source"), "/foo/bar") + File.expand_path("#{machine.env.cwd}/source"), "/foo/bar") subject.provision end