Merge pull request #10902 from briancain/fixup-rsync-listener
Fixes #10895: Use relative paths to machines folder path for Listener
This commit is contained in:
commit
75d42fed9d
|
@ -121,9 +121,13 @@ module VagrantPlugins
|
||||||
|
|
||||||
if folder_opts[:exclude]
|
if folder_opts[:exclude]
|
||||||
Array(folder_opts[:exclude]).each do |pattern|
|
Array(folder_opts[:exclude]).each do |pattern|
|
||||||
ignores << RsyncHelper.exclude_to_regexp(hostpath, pattern.to_s)
|
ignores << RsyncHelper.exclude_to_regexp(pattern.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Always ignore Vagrant
|
||||||
|
ignores << /.vagrant\//
|
||||||
|
ignores.uniq!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,13 @@ module VagrantPlugins
|
||||||
|
|
||||||
# This converts an rsync exclude pattern to a regular expression
|
# This converts an rsync exclude pattern to a regular expression
|
||||||
# we can send to Listen.
|
# we can send to Listen.
|
||||||
def self.exclude_to_regexp(path, exclude)
|
#
|
||||||
|
# Note: Listen expects a path relative to the parameter passed into the
|
||||||
|
# Listener, not a fully qualified path
|
||||||
|
#
|
||||||
|
# @param [String] - exclude path
|
||||||
|
# @return [Regexp] - A regex of the path, modified, to exclude
|
||||||
|
def self.exclude_to_regexp(exclude)
|
||||||
start_anchor = false
|
start_anchor = false
|
||||||
|
|
||||||
if exclude.start_with?("/")
|
if exclude.start_with?("/")
|
||||||
|
@ -24,19 +30,14 @@ module VagrantPlugins
|
||||||
exclude = exclude[1..-1]
|
exclude = exclude[1..-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
path = "#{path}/" if !path.end_with?("/")
|
|
||||||
regexp = "^#{Regexp.escape(path)}"
|
|
||||||
regexp += ".*" if !start_anchor
|
|
||||||
|
|
||||||
# This is not an ideal solution, but it's a start. We can improve and
|
# This is not an ideal solution, but it's a start. We can improve and
|
||||||
# keep unit tests passing in the future.
|
# keep unit tests passing in the future.
|
||||||
exclude = exclude.gsub("**", "|||GLOBAL|||")
|
exclude = exclude.gsub("**", "|||GLOBAL|||")
|
||||||
exclude = exclude.gsub("*", "|||PATH|||")
|
exclude = exclude.gsub("*", "|||PATH|||")
|
||||||
exclude = exclude.gsub("|||PATH|||", "[^/]*")
|
exclude = exclude.gsub("|||PATH|||", "[^/]*")
|
||||||
exclude = exclude.gsub("|||GLOBAL|||", ".*")
|
exclude = exclude.gsub("|||GLOBAL|||", ".*")
|
||||||
regexp += exclude
|
|
||||||
|
|
||||||
Regexp.new(regexp)
|
Regexp.new(exclude)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.rsync_single(machine, ssh_info, opts)
|
def self.rsync_single(machine, ssh_info, opts)
|
||||||
|
|
|
@ -66,15 +66,12 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
|
||||||
# https://github.com/hashicorp/vagrant/blob/9c1b014536e61b332cfaa00774a87a240cce8ed9/lib/vagrant/action/builtin/synced_folders.rb#L45-L46
|
# https://github.com/hashicorp/vagrant/blob/9c1b014536e61b332cfaa00774a87a240cce8ed9/lib/vagrant/action/builtin/synced_folders.rb#L45-L46
|
||||||
let(:config_synced_folders) { {"/vagrant":
|
let(:config_synced_folders) { {"/vagrant":
|
||||||
{type: "rsync",
|
{type: "rsync",
|
||||||
exclude: false,
|
|
||||||
hostpath: "/Users/brian/code/vagrant-sandbox"},
|
hostpath: "/Users/brian/code/vagrant-sandbox"},
|
||||||
"/vagrant/other-dir":
|
"/vagrant/other-dir":
|
||||||
{type: "rsync",
|
{type: "rsync",
|
||||||
exclude: false,
|
|
||||||
hostpath: "/Users/brian/code/vagrant-sandbox/other-dir"},
|
hostpath: "/Users/brian/code/vagrant-sandbox/other-dir"},
|
||||||
"/vagrant/relative-dir":
|
"/vagrant/relative-dir":
|
||||||
{type: "rsync",
|
{type: "rsync",
|
||||||
exclude: false,
|
|
||||||
hostpath: "/Users/brian/code/relative-dir"}}}
|
hostpath: "/Users/brian/code/relative-dir"}}}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
@ -103,6 +100,11 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
|
||||||
with("Watching: /Users/brian/code/relative-dir")
|
with("Watching: /Users/brian/code/relative-dir")
|
||||||
expect(helper_class).to receive(:rsync_single)
|
expect(helper_class).to receive(:rsync_single)
|
||||||
|
|
||||||
|
expect(Listen).to receive(:to).
|
||||||
|
with("/Users/brian/code/vagrant-sandbox",
|
||||||
|
"/Users/brian/code/relative-dir",
|
||||||
|
{:ignore=>[/.vagrant\//],
|
||||||
|
:force_polling=>false})
|
||||||
subject.execute
|
subject.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,23 +32,23 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do
|
||||||
let(:path) { "/foo/bar" }
|
let(:path) { "/foo/bar" }
|
||||||
|
|
||||||
it "converts a directory match" do
|
it "converts a directory match" do
|
||||||
expect(described_class.exclude_to_regexp(path, "foo/")).
|
expect(described_class.exclude_to_regexp("foo/")).
|
||||||
to eq(/^#{Regexp.escape(path)}\/.*foo\//)
|
to eq(/foo\//)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "converts the start anchor" do
|
it "converts the start anchor" do
|
||||||
expect(described_class.exclude_to_regexp(path, "/foo")).
|
expect(described_class.exclude_to_regexp("/foo")).
|
||||||
to eq(/^\/foo\/bar\/foo/)
|
to eq(/foo/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "converts the **" do
|
it "converts the **" do
|
||||||
expect(described_class.exclude_to_regexp(path, "fo**o")).
|
expect(described_class.exclude_to_regexp("fo**o")).
|
||||||
to eq(/^#{Regexp.escape(path)}\/.*fo.*o/)
|
to eq(/fo.*o/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "converts the *" do
|
it "converts the *" do
|
||||||
expect(described_class.exclude_to_regexp(path, "fo*o")).
|
expect(described_class.exclude_to_regexp("fo*o")).
|
||||||
to eq(/^#{Regexp.escape(path)}\/.*fo[^\/]*o/)
|
to eq(/fo[^\/]*o/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue