From 4f05d1015df61cd1e5b228866e27bdc489b462cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Mon, 23 Dec 2019 14:13:50 +0300 Subject: [PATCH 1/3] [PathList] Use Dir.glob instead of Find.find for speed [FileReferencesInstaller] Do not refresh local pods --- .../pods_project_generator/file_references_installer.rb | 5 ++++- lib/cocoapods/sandbox/path_list.rb | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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..6fb6630aa0 100644 --- a/lib/cocoapods/sandbox/path_list.rb +++ b/lib/cocoapods/sandbox/path_list.rb @@ -51,12 +51,14 @@ 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| + Dir.glob(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? From 9ff85461dbb3cb30ebe1a5a3470a1f852d10bcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Mon, 23 Dec 2019 19:14:51 +0300 Subject: [PATCH 2/3] Revert escaping logic for metacharacters --- lib/cocoapods/sandbox/path_list.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods/sandbox/path_list.rb b/lib/cocoapods/sandbox/path_list.rb index 6fb6630aa0..107efff596 100644 --- a/lib/cocoapods/sandbox/path_list.rb +++ b/lib/cocoapods/sandbox/path_list.rb @@ -54,7 +54,8 @@ def read_file_system dirs = [] files = [] root_length = root.cleanpath.to_s.length + File::SEPARATOR.length - Dir.glob(root + '**/*', File::FNM_DOTMATCH).each 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 =~ /\.\.?$/ @@ -216,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 From 3a8e065c7b4e072b32348f92de8f3bb59548734b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Yavuz=20Nuzumlal=C4=B1?= Date: Tue, 24 Dec 2019 23:41:37 +0300 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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