for-GET / jesse

jesse (JSon Schema Erlang) is an implementation of a JSON Schema validator for Erlang.
https://github.com/for-get/jesse
Apache License 2.0
124 stars 64 forks source link

Fix recursive directory listing in jesse database #45

Closed JakubCzarniecki closed 7 years ago

JakubCzarniecki commented 7 years ago

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 commented 7 years ago

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

JakubCzarniecki commented 7 years ago

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 commented 7 years ago

"Oops" Thanks!