-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning empty result instead of nil. #4
Comments
If you use a count larger than the default of one it works just fine. iex(7)> {:ok, walker} = DirWalker.start_link("test/dir") |
I found the problem, since the matching function can return an empty list w/o processing a list, the call handler needs to check for returning { [] , [] } and instead set the result to nil if returning two empty arrays. iex -S mix Compiled lib/dir_walker.ex 20:20:18.903 [debug] Handling test/dir/a.txt 20:20:18.906 [debug] Replying with ["test/dir/a.txt"] ["test/dir/b.txt", ["test/dir/badlink", "test/dir/c", "test/dir/goodlink"]] 20:20:27.541 [debug] Handling test/dir/b.txt 20:20:27.541 [debug] Replying with ["test/dir/b.txt"] ["test/dir/badlink", ["test/dir/c", "test/dir/goodlink"]] 20:20:33.013 [info] Dangling symlink found: test/dir/badlink 20:20:33.013 [debug] Handling test/dir/badlink 20:20:33.013 [debug] Replying with ["test/dir/badlink"] ["test/dir/c", ["test/dir/goodlink"]] 20:20:37.798 [debug] Handling test/dir/c/d/f.txt 20:20:37.798 [debug] Replying with ["test/dir/c/d/f.txt"] ["test/dir/goodlink"] 20:20:42.461 [debug] Handling test/dir/goodlink 20:20:42.461 [debug] Replying with ["test/dir/goodlink"] [] 20:21:57.695 [debug] Handling test/dir/a.txt 20:21:57.695 [debug] Moving on to rest [["test/dir/b.txt", "test/dir/badlink", "test/dir/c", "test/dir/goodlink"]] 20:21:57.695 [debug] Handling test/dir/b.txt 20:21:57.695 [debug] Replying with ["test/dir/b.txt"] ["test/dir/badlink", ["test/dir/c", "test/dir/goodlink"]] 20:22:04.351 [info] Dangling symlink found: test/dir/badlink 20:22:04.351 [debug] Handling test/dir/badlink 20:22:04.351 [debug] Replying with ["test/dir/badlink"] ["test/dir/c", ["test/dir/goodlink"]] 20:22:07.887 [debug] Handling test/dir/c/d/f.txt 20:22:07.887 [debug] Moving on to rest [["test/dir/goodlink"]] 20:22:07.888 [debug] Handling test/dir/goodlink 20:22:07.888 [debug] Moving on to rest [] 20:22:07.888 [debug] Replying with [] [] The Logger debug statements are in my current version. The fix was to add this to the main handle_call routine. def handle_call({:get_next, n}, _from, {path_list, mappers}) do |
The problem seems to be that the new :matching option causes the code to return one empty array before it returns a nil at the end of the search. I did add the necessary e dir after checking out the
code from github. The problem appears whether you use the matching code or not.
iex -S mix
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> {:ok, walker} = DirWalker.start_link("test/dir", matching: ~r(a|f))
{:ok, #PID<0.79.0>}
iex(2)> file = DirWalker.next(walker)
["test/dir/a.txt"]
iex(3)> file = DirWalker.next(walker)
["test/dir/c/d/f.txt"]
iex(4)> file = DirWalker.next(walker)
[]
iex(5)> file = DirWalker.next(walker)
nil
iex(6)> {:ok, walker} = DirWalker.start_link("test/dir")
{:ok, #PID<0.85.0>}
iex(7)> file = DirWalker.next(walker)
["test/dir/a.txt"]
iex(8)> file = DirWalker.next(walker)
["test/dir/b.txt"]
iex(9)> file = DirWalker.next(walker)
["test/dir/c/d/f.txt"]
iex(10)> file = DirWalker.next(walker)
[]
iex(11)> file = DirWalker.next(walker)
nil
The text was updated successfully, but these errors were encountered: