Skip to content

Commit

Permalink
Process rsync exclude regex less
Browse files Browse the repository at this point in the history
This change will prepend "^" and append "/" if a start anchor is
detected in the regex string. This allows users to specify
relative paths to exclude.

It also removes replacing occurences of "*" with "[^/]*". "*"
already expresses itself accurately.
  • Loading branch information
soapy1 committed Jan 20, 2023
1 parent 56d6cba commit 4b412d6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions plugins/synced_folders/rsync/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ def self.exclude_to_regexp(exclude)
exclude = exclude[1..-1]
end

exclude = "#{exclude}/" if !exclude.end_with?("/")
exclude = "^#{exclude}"
exclude += ".*" if !start_anchor
exclude = "#{exclude}/" if !exclude.end_with?("/") if start_anchor
exclude = "^#{exclude}" if start_anchor
exclude += ".*" if (!start_anchor && !exclude.end_with?("*"))

# This is not an ideal solution, but it's a start. We can improve and
# keep unit tests passing in the future.
exclude = exclude.gsub("**", "|||GLOBAL|||")
exclude = exclude.gsub("*", "|||PATH|||")
exclude = exclude.gsub("|||PATH|||", "[^/]*")
exclude = exclude.gsub("|||GLOBAL|||", ".*")

Regexp.new(exclude)
Expand Down

0 comments on commit 4b412d6

Please sign in to comment.