Commit 5496974a authored by Samuel Giddins's avatar Samuel Giddins

Merge pull request #5326 from marcboquet/issue-5294b

[PathList] Simplify read_file_system implementation, deal with unicode paths
parents fea279b0 a60c8cca
require 'active_support/multibyte/unicode'
module Pod
class Sandbox
# The PathList class is designed to perform multiple glob matches against
......@@ -20,7 +22,8 @@ module Pod
# @param [Pathname] root The root of the PathList.
#
def initialize(root)
@root = root
root_dir = ActiveSupport::Multibyte::Unicode.normalize(root.to_s)
@root = Pathname.new(root_dir)
@glob_cache = {}
end
......@@ -47,15 +50,12 @@ module Pod
unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`."
end
root_length = root.to_s.length + 1
escaped_root = escape_path_for_glob(root)
paths = Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH).sort_by(&:upcase)
absolute_dirs = paths.select { |path| File.directory?(path) }
relative_dirs = absolute_dirs.map { |p| p[root_length..-1] }
absolute_paths = paths.reject { |p| p == "#{root}/." || p == "#{root}/.." }
relative_paths = absolute_paths.map { |p| p[root_length..-1] }
@files = relative_paths - relative_dirs
@dirs = relative_dirs.map { |d| d.gsub(/\/\.\.?$/, '') }.reject { |d| d == '.' || d == '..' } .uniq
absolute_paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH)
dirs_and_files = absolute_paths.reject { |path| path.basename.to_s =~ /^\.\.?$/ }
relative_paths = dirs_and_files.map { |path| path.relative_path_from(root) }
sorted_paths = relative_paths.map(&:to_s).sort_by(&:upcase)
@dirs, @files = sorted_paths.partition { |path| File.directory?(root + path) }
@glob_cache = {}
end
......
......@@ -168,16 +168,23 @@ module Pod
describe 'Reading file system' do
it 'orders paths case insensitively' do
root = fixture('banana-lib')
root = fixture('banana-unordered')
# Let Dir.glob result be ordered case-sensitively
Dir.stubs(:glob).returns(["#{root}/Classes/NSFetchRequest+Banana.h",
"#{root}/Classes/NSFetchedResultsController+Banana.h"])
# Let Pathname.glob result be ordered case-sensitively
Pathname.stubs(:glob).returns([Pathname.new("#{root}/Classes/NSFetchRequest+Banana.h"),
Pathname.new("#{root}/Classes/NSFetchedResultsController+Banana.h")])
File.stubs(:directory?).returns(false)
path_list = Sandbox::PathList.new(fixture('banana-lib'))
path_list = Sandbox::PathList.new(root)
path_list.files.should == %w(Classes/NSFetchedResultsController+Banana.h Classes/NSFetchRequest+Banana.h)
end
it 'supports unicode paths' do
# Load fixture("ü") with chars ["u", "̈"] instead of ["ü"]
unicode_name = [117, 776].pack('U*')
path_list = Sandbox::PathList.new(fixture(unicode_name))
path_list.files.should == ['README']
end
end
#-------------------------------------------------------------------------#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment