From 148371c1b2be0aed3ebc876219fbfbb066a1b046 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Fri, 19 Oct 2012 17:16:01 +0200 Subject: [PATCH] [LocalPod] Always use Pathname::glob. This patch also removes the custom Pathname.glob based on Dir::glob. Related #572 and #602. --- lib/cocoapods.rb | 6 ------ lib/cocoapods/command/repo.rb | 2 +- lib/cocoapods/command/spec.rb | 2 +- lib/cocoapods/local_pod.rb | 9 +++++---- lib/cocoapods/podfile.rb | 3 ++- spec/unit/podfile_spec.rb | 8 ++++---- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/cocoapods.rb b/lib/cocoapods.rb index 9d20b5c..528ac42 100644 --- a/lib/cocoapods.rb +++ b/lib/cocoapods.rb @@ -57,12 +57,6 @@ module Pod end end -class Pathname - def glob(pattern = '') - Dir.glob((self + pattern).to_s).map { |f| Pathname.new(f) } - end -end - if ENV['COCOA_PODS_ENV'] == 'development' require 'letters' require 'awesome_print' diff --git a/lib/cocoapods/command/repo.rb b/lib/cocoapods/command/repo.rb index dc177a3..669078b 100644 --- a/lib/cocoapods/command/repo.rb +++ b/lib/cocoapods/command/repo.rb @@ -90,7 +90,7 @@ module Pod dirs.each do |dir| check_versions(dir) UI.puts "\nLinting spec repo `#{dir.realpath.basename}'\n".yellow - podspecs = dir.glob('**/*.podspec') + podspecs = Pathname.glob( dir + '**/*.podspec') invalid_count = 0 podspecs.each do |podspec| diff --git a/lib/cocoapods/command/spec.rb b/lib/cocoapods/command/spec.rb index 76629ce..b27ff15 100644 --- a/lib/cocoapods/command/spec.rb +++ b/lib/cocoapods/command/spec.rb @@ -138,7 +138,7 @@ module Pod end files << output_path else if (pathname = Pathname.new(path)).directory? - files += pathname.glob('**/*.podspec') + files += Pathname.glob(pathname + '**/*.podspec') raise Informative, "No specs found in the current directory." if files.empty? else files << (pathname = Pathname.new(path)) diff --git a/lib/cocoapods/local_pod.rb b/lib/cocoapods/local_pod.rb index 9dddf8f..55d4bb7 100644 --- a/lib/cocoapods/local_pod.rb +++ b/lib/cocoapods/local_pod.rb @@ -163,14 +163,15 @@ module Pod # # @return [Array] The paths that can be deleted. # - # @note The Paths are downcased to prevent issues. See #568. + # @note Implementation detail: Don't use Dir#glob as there is an + # unexplained issue (#568, #572 and #602). # def clean_paths - used = used_files - files = Dir.glob(root + "**/*", File::FNM_DOTMATCH | File::FNM_CASEFOLD) + cached_used = used_files + files = Pathname.glob(root + "**/*", File::FNM_DOTMATCH | File::FNM_CASEFOLD).map(&:to_s) files.reject! do |candidate| - candidate.end_with?('.', '..') || used.any? do |path| + candidate.end_with?('.', '..') || cached_used.any? do |path| path.include?(candidate) || candidate.include?(path) end end diff --git a/lib/cocoapods/podfile.rb b/lib/cocoapods/podfile.rb index 5e9258f..0d065d1 100644 --- a/lib/cocoapods/podfile.rb +++ b/lib/cocoapods/podfile.rb @@ -35,7 +35,8 @@ module Pod if @path @path else - xcodeprojs = config.project_root.glob('*.xcodeproj') + puts config.project_root + '*.xcodeproj' + xcodeprojs = Pathname.glob(config.project_root + '*.xcodeproj') if xcodeprojs.size == 1 @path = xcodeprojs.first end diff --git a/spec/unit/podfile_spec.rb b/spec/unit/podfile_spec.rb index 6d72606..3ac99e5 100644 --- a/spec/unit/podfile_spec.rb +++ b/spec/unit/podfile_spec.rb @@ -105,7 +105,7 @@ describe "Pod::Podfile" do end path = config.project_root + 'MyProject.xcodeproj' - config.project_root.expects(:glob).with('*.xcodeproj').returns([path]) + Pathname.expects(:glob).with(config.project_root + '*.xcodeproj').returns([path]) podfile.target_definitions[:default].user_project.path.should == path podfile.target_definitions[:another_target].user_project.path.should == path @@ -113,7 +113,7 @@ describe "Pod::Podfile" do it "assumes the basename of the workspace is the same as the default target's project basename" do path = config.project_root + 'MyProject.xcodeproj' - config.project_root.expects(:glob).with('*.xcodeproj').returns([path]) + Pathname.expects(:glob).with(config.project_root + '*.xcodeproj').returns([path]) Pod::Podfile.new {}.workspace.should == config.project_root + 'MyProject.xcworkspace' Pod::Podfile.new do @@ -225,13 +225,13 @@ describe "Pod::Podfile" do it "returns a Xcode project found in the working dir when no explicit project is specified" do xcodeproj1 = config.project_root + '1.xcodeproj' - config.project_root.expects(:glob).with('*.xcodeproj').returns([xcodeproj1]) + Pathname.expects(:glob).with(config.project_root + '*.xcodeproj').returns([xcodeproj1]) Pod::Podfile::UserProject.new.path.should == xcodeproj1 end it "returns `nil' if more than one Xcode project was found in the working when no explicit project is specified" do xcodeproj1, xcodeproj2 = config.project_root + '1.xcodeproj', config.project_root + '2.xcodeproj' - config.project_root.expects(:glob).with('*.xcodeproj').returns([xcodeproj1, xcodeproj2]) + Pathname.expects(:glob).with(config.project_root + '*.xcodeproj').returns([xcodeproj1, xcodeproj2]) Pod::Podfile::UserProject.new.path.should == nil end