diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ac8c871c..e94bd87862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb b/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb index c1b03ffb73..bacd34ce62 100644 --- a/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb +++ b/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb @@ -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 diff --git a/lib/cocoapods/sandbox/path_list.rb b/lib/cocoapods/sandbox/path_list.rb index be238b818c..107efff596 100644 --- a/lib/cocoapods/sandbox/path_list.rb +++ b/lib/cocoapods/sandbox/path_list.rb @@ -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? @@ -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