diff --git a/mrblib/rf/directory.rb b/mrblib/rf/directory.rb index 0f11e27..da7b478 100644 --- a/mrblib/rf/directory.rb +++ b/mrblib/rf/directory.rb @@ -5,15 +5,11 @@ class Node def initialize(path) @path = path - @dir = Dir.open(path) + @children = Dir.entries(path).reject { |e| ['.', '..'].include?(e) }.sort end def next - child = loop do - child = @dir.read - return unless child - break child unless %w[. ..].include?(child) - end + return unless child = @children.shift File.join(@path, child) end diff --git a/spec/glonal_options_spec.rb b/spec/glonal_options_spec.rb index e104906..5728dfa 100644 --- a/spec/glonal_options_spec.rb +++ b/spec/glonal_options_spec.rb @@ -2,16 +2,16 @@ context 'with -R option' do let(:output) do <<~OUTPUT - ./foo/bar: foobar ./a/b/c: abc + ./foo/bar: foobar OUTPUT end before do - FileUtils.mkdir_p(expand_path('foo')) - write_file('foo/bar', 'foobar') FileUtils.mkdir_p(expand_path('a/b')) write_file('a/b/c', 'abc') + FileUtils.mkdir_p(expand_path('foo')) + write_file('foo/bar', 'foobar') run_rf('-R _ .') end