Commit 0e074f75 authored by Marc Boquet's avatar Marc Boquet

[PathList] Another try at the re-implementation of read_file_system

parent 768b2c57
......@@ -50,20 +50,12 @@ module Pod
unless root.exist?
raise Informative, "Attempt to read non existent folder `#{root}`."
end
files = []
dirs = []
escaped_root = escape_path_for_glob(root)
paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH) do |path|
next if path.basename.to_s.match /\.\.?$/
relative_path = path.relative_path_from(root)
if path.directory?
dirs << relative_path.to_s
else
files << relative_path.to_s
end
end
@files = files.sort_by(&:upcase)
@dirs = dirs.sort_by(&:upcase)
absolute_paths = Pathname.glob(escaped_root + '**/*', File::FNM_DOTMATCH)
dirs_and_files = absolute_paths.reject { |path| path.basename.to_s =~ /^\.\.?$/ }
dirs, files = dirs_and_files.partition(&:directory?)
@dirs = dirs.map { |dir| dir.relative_path_from(root).to_s }.sort_by(&:upcase)
@files = files.map { |file| file.relative_path_from(root).to_s }.sort_by(&:upcase)
@glob_cache = {}
end
......
......@@ -168,14 +168,14 @@ module Pod
describe 'Reading file system' do
it 'orders paths case insensitively' do
root = fixture('banana-lib')
root = fixture('banana-unordered')
# Let Pathname.glob result be ordered case-sensitively
Pathname.stubs(:glob).multiple_yields(Pathname.new("#{root}/Classes/NSFetchRequest+Banana.h"),
Pathname.new("#{root}/Classes/NSFetchedResultsController+Banana.h"))
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
......
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