Skip to content

Commit

Permalink
Merge pull request #9428 from CocoaPods/manu-path-list-optimizations
Browse files Browse the repository at this point in the history
path list optimizations
  • Loading branch information
dnkoutso committed Dec 24, 2019
2 parents f4f64da + 3a8e065 commit 0b5328c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,7 +8,9 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Enhancements

* None.
* PathList optimizations related to file system reads.
[manuyavuz](https://github.com/manuyavuz)
[#issue_number](https://github.com/CocoaPods/CocoaPods/issues/4927)

##### Bug Fixes

Expand Down
Expand Up @@ -65,7 +65,10 @@ def install!
# @return [void]
#
def refresh_file_accessors
file_accessors.map(&:path_list).uniq.each(&:read_file_system)
file_accessors.reject do |file_accessor|
pod_name = file_accessor.spec.name
sandbox.local?(pod_name)
end.map(&:path_list).uniq.each(&:read_file_system)
end

# Prepares the main groups to which all files will be added for the respective target
Expand Down
26 changes: 24 additions & 2 deletions lib/cocoapods/sandbox/path_list.rb
Expand Up @@ -51,12 +51,15 @@ def read_file_system
unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`."
end

dirs = []
files = []
root_length = root.cleanpath.to_s.length + File::SEPARATOR.length
Find.find(root.to_s) do |f|
escaped_root = escape_path_for_glob(root)
Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH).each do |f|
directory = File.directory?(f)
# Ignore `.` and `..` directories
next if directory && f =~ /\.\.?$/

f = f.slice(root_length, f.length - root_length)
next if f.nil?

Expand Down Expand Up @@ -214,6 +217,25 @@ def dir_glob_equivalent_patterns(pattern)
end
end

# Escapes the glob metacharacters from a given path so it can used in
# Dir#glob and similar methods.
#
# @note See CocoaPods/CocoaPods#862.
#
# @param [String, Pathname] path
# The path to escape.
#
# @return [Pathname] The escaped path.
#
def escape_path_for_glob(path)
result = path.to_s
characters_to_escape = ['[', ']', '{', '}', '?', '*']
characters_to_escape.each do |character|
result.gsub!(character, "\\#{character}")
end
Pathname.new(result)
end

#-----------------------------------------------------------------------#
end
end
Expand Down

0 comments on commit 0b5328c

Please sign in to comment.