Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: 603a5969fe927516b17b812aafd85e14d0039923
Timestamp: Thu, 01 Jul 2021 15:58:30 +0000 (3 years ago)

+9 -4 +/-1 browse
fix absolute vs relative paths
1diff --git a/lib/manifest.ml b/lib/manifest.ml
2index 08dec95..7f489b1 100644
3--- a/lib/manifest.ml
4+++ b/lib/manifest.ml
5 @@ -1,11 +1,11 @@
6 open Core
7
8 module Util = struct
9- let dirname path =
10- (* nothing is relative, all things are absolute! *)
11+ (* makes any relative path absolute *)
12+ let fixpath path =
13 match path |> Filename.is_relative with
14- | true -> Filename.concat "/" (Filename.dirname path)
15- | false -> path |> Filename.dirname
16+ | true -> Filename.concat "/" path
17+ | false -> path
18 end
19
20 module Item = struct
21 @@ -102,6 +102,7 @@ let save manifest =
22 Out_channel.write_all ~data:(to_string manifest) (manifest |> mpath)
23
24 let find ~path manifest =
25+ let path = path |> Util.fixpath in
26 manifest.items |> List.find ~f:(fun item -> Filename.equal item.path path)
27
28 (* TODO: no support for recursive operations yet *)
29 @@ -136,12 +137,14 @@ let create ~path manifest =
30 | None -> failwith "no parent")
31
32 let list ~path manifest =
33+ let path = path |> Util.fixpath in
34 manifest.items
35 |> List.filter ~f:(fun item ->
36 String.equal (item.path |> Filename.dirname) path
37 && not (String.equal item.path "/"))
38
39 let remove ~path manifest =
40+ let path = path |> Util.fixpath in
41 match manifest |> list ~path |> List.length with
42 | 0 ->
43 let items =
44 @@ -152,6 +155,8 @@ let remove ~path manifest =
45 | _ -> failwith "will not delete recursively"
46
47 let move ~source ~dest manifest =
48+ let source = source |> Util.fixpath in
49+ let dest = dest |> Util.fixpath in
50 let item = manifest |> find ~path:source in
51 let others = manifest |> list ~path:source in
52 match others |> List.length with