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 module Pod
class Sandbox class Sandbox
# The PathList class is designed to perform multiple glob matches against # The PathList class is designed to perform multiple glob matches against
...@@ -20,7 +22,8 @@ module Pod ...@@ -20,7 +22,8 @@ module Pod
# @param [Pathname] root The root of the PathList. # @param [Pathname] root The root of the PathList.
# #
def initialize(root) def initialize(root)
@root = root root_dir = ActiveSupport::Multibyte::Unicode.normalize(root.to_s)
@root = Pathname.new(root_dir)
@glob_cache = {} @glob_cache = {}
end end
...@@ -47,15 +50,12 @@ module Pod ...@@ -47,15 +50,12 @@ module Pod
unless root.exist? unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`." raise Informative, "Attempt to read non existent folder `#{root}`."
end end
root_length = root.to_s.length + 1
escaped_root = escape_path_for_glob(root) escaped_root = escape_path_for_glob(root)
paths = Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH).sort_by(&:upcase) absolute_paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH)
absolute_dirs = paths.select { |path| File.directory?(path) } dirs_and_files = absolute_paths.reject { |path| path.basename.to_s =~ /^\.\.?$/ }
relative_dirs = absolute_dirs.map { |p| p[root_length..-1] } relative_paths = dirs_and_files.map { |path| path.relative_path_from(root) }
absolute_paths = paths.reject { |p| p == "#{root}/." || p == "#{root}/.." } sorted_paths = relative_paths.map(&:to_s).sort_by(&:upcase)
relative_paths = absolute_paths.map { |p| p[root_length..-1] } @dirs, @files = sorted_paths.partition { |path| File.directory?(root + path) }
@files = relative_paths - relative_dirs
@dirs = relative_dirs.map { |d| d.gsub(/\/\.\.?$/, '') }.reject { |d| d == '.' || d == '..' } .uniq
@glob_cache = {} @glob_cache = {}
end end
......
...@@ -168,16 +168,23 @@ module Pod ...@@ -168,16 +168,23 @@ module Pod
describe 'Reading file system' do describe 'Reading file system' do
it 'orders paths case insensitively' do it 'orders paths case insensitively' do
root = fixture('banana-lib') root = fixture('banana-unordered')
# Let Dir.glob result be ordered case-sensitively # Let Pathname.glob result be ordered case-sensitively
Dir.stubs(:glob).returns(["#{root}/Classes/NSFetchRequest+Banana.h", Pathname.stubs(:glob).returns([Pathname.new("#{root}/Classes/NSFetchRequest+Banana.h"),
"#{root}/Classes/NSFetchedResultsController+Banana.h"]) Pathname.new("#{root}/Classes/NSFetchedResultsController+Banana.h")])
File.stubs(:directory?).returns(false) 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) path_list.files.should == %w(Classes/NSFetchedResultsController+Banana.h Classes/NSFetchRequest+Banana.h)
end 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 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