Skip to content

Commit

Permalink
Hide hidden matches in non-recursive directories if match_hidden is…
Browse files Browse the repository at this point in the history
… false. (#7774)
  • Loading branch information
ayazhafiz authored and Brian J. Cardiff committed May 13, 2019
1 parent bbffbe0 commit f050127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/std/dir_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ describe "Dir" do
].sort
end
end

context "match_hidden: false" do
it "ignores hidden files" do
Dir.glob("#{datapath}/dir/dots/*", match_hidden: false).size.should eq 0
end

it "ignores hidden files recursively" do
Dir.glob("#{datapath}/dir/dots/**/*", match_hidden: false).size.should eq 0
end
end
end

describe "cd" do
Expand Down
3 changes: 2 additions & 1 deletion src/dir/glob.cr
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Dir
when EntryMatch
return if sequence[pos + 1]?.is_a?(RecursiveDirectories)
each_child(path) do |entry|
next if !options[:match_hidden] && entry.starts_with?('.')
yield join(path, entry) if cmd.matches?(entry)
end
when DirectoryMatch
Expand Down Expand Up @@ -219,7 +220,7 @@ class Dir

if entry = dir.try(&.read)
next if {".", ".."}.includes?(entry)
next if entry[0] == '.' && !options[:match_hidden]
next if !options[:match_hidden] && entry.starts_with?('.')

if dir_path.bytesize == 0
fullpath = entry
Expand Down

0 comments on commit f050127

Please sign in to comment.