From 03be845d60dc0f75a0f20c191d1fde7ba57ec32e Mon Sep 17 00:00:00 2001 From: Stavros Polymenis Date: Wed, 15 Nov 2017 22:02:30 +0000 Subject: [PATCH] Finished patching core/file --- src/store/file.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/store/file.ml b/src/store/file.ml index 36602f0..7c6133f 100644 --- a/src/store/file.ml +++ b/src/store/file.ml @@ -11,6 +11,11 @@ let note path = Lpath.fpath_of_note path |> load |> Note.of_string type t = { repo_path : Lpath.repo_t } +let ext_len = String.length Lpath.extension +let note_filename name = + try Re_str.last_chars name ext_len = Lpath.extension with + | Invalid_argument _ -> false + let to_list ?(order) lens_fn store = let repo_path = store.repo_path in let cons_valid_meta list path = @@ -22,7 +27,7 @@ let to_list ?(order) lens_fn store = Lpath.string_of_repo repo_path |> Sys.readdir |> Array.to_list - |> List.filter (fun filename -> BatString.ends_with file Lpath.extension) (* convert to paths first then check extention *) + |> List.filter note_filename |> List.fold_left cons_valid_meta [] |> match order with | Some fn -> List.fast_sort fn @@ -41,7 +46,7 @@ let note_with_id store id = Lpath.string_of_repo repo_path |> Sys.readdir |> Array.to_list - |> List.filter (fun file -> BatString.ends_with file Lpath.extension) + |> List.filter note_filename in try Some (note_of_path (List.find with_id notes)) with Not_found -> None @@ -57,7 +62,7 @@ let note_with_alias store alias = Lpath.string_of_repo repo_path |> Sys.readdir |> Array.to_list - |> List.filter (fun file -> BatString.ends_with file Lpath.extension) + |> List.filter note_filename |> List.fold_left cons_valid_meta [] |> List.filter (fun note -> Meta.alias note.Note.meta = alias) |> List.fast_sort (fun a b -> recency_order a.Note.meta b.Note.meta)