Skip to content
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

Fix recursive directory listing in jesse database #45

Merged
merged 2 commits into from
Mar 11, 2017
Merged

Fix recursive directory listing in jesse database #45

merged 2 commits into from
Mar 11, 2017

Conversation

JakubCzarniecki
Copy link
Contributor

Problem:
jesse_database:list_dir/1 is broken - while recursively listing files in directory it produces a nested list of filenames i.e.

[[[],"first/second/third.json", "first/second/fourth.json"]]

instead of

["first/second/third.json", "first/second/fourth.json"]

This produces a cryptic error message when trying to use jesse:load_schemas/2,3 or jesse_database:add_path/3:

** exception error: no match of right hand side value {error,enoent}
     in function  jesse_database:get_schema_info/2 (src/jesse_database.erl, line 272)
     in call from lists:foldl/3 (lists.erl, line 1263)
     in call from jesse_database:get_schema_infos/2 (src/jesse_database.erl, line 262)
     in call from jesse_database:add_path/3 (src/jesse_database.erl, line 102)

Solution:
Make jesse_database:list_dir/1 always produce a flat list of files within directory, appending any subdirectory listings.

@seriyps
Copy link
Collaborator

seriyps commented Mar 10, 2017

Maybe just use http://erlang.org/doc/man/filelib.html#fold_files-5 ?

@JakubCzarniecki
Copy link
Contributor Author

Good suggestion @seriyps.
If we find it useful we could allow filename filtering by extension / regex in jesse:load_schemas/2,3 and jesse_database:add_path/3 but it is out of the scope of this PR.

@andreineculau andreineculau merged commit c4da4a6 into for-GET:master Mar 11, 2017
@andreineculau
Copy link
Member

"Oops"
Thanks!

@JakubCzarniecki JakubCzarniecki deleted the fix-empty-list-dir branch March 11, 2017 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants