Repositories / agent-snapshot.git
agent-snapshot.git
Clone (read-only): git clone http://git.guha-anderson.com/git/agent-snapshot.git
@@ -9,4 +9,5 @@ dune yojson camomile - ocaml-git)) + ocaml-git + fpath))
@@ -123,34 +123,20 @@ let blob_dir : string ref = ref "" let tracer_uid : int = Unix.getuid () let tracer_gid : int = Unix.getgid () -let path_sep = '/' - let split_path (path : string) : string list = - path |> String.split_on_char path_sep |> List.filter (fun part -> part <> "" && part <> ".") + if path = "" then [] + else Fpath.segs (Fpath.normalize (Fpath.v path)) |> List.filter (fun seg -> seg <> "") let normalize_path (path : string) : string = - let absolute = String.length path > 0 && path.[0] = path_sep in - let parts = - List.fold_left - (fun acc part -> - if part = ".." then match acc with [] -> acc | _ :: rest -> rest else part :: acc) - [] (split_path path) - |> List.rev - in - let body = String.concat "/" parts in - if absolute then if body = "" then "/" else "/" ^ body else if body = "" then "." else body + if path = "" then "." else Fpath.to_string (Fpath.normalize (Fpath.v path)) let concat_path (base : string) (path : string) : string = if path = "" then base - else if String.length path > 0 && path.[0] = '/' then normalize_path path - else normalize_path (base ^ "/" ^ path) + else Fpath.to_string (Fpath.normalize (Fpath.append (Fpath.v base) (Fpath.v path))) let dirname (path : string) : string = - let path = normalize_path path in - match String.rindex_opt path '/' with - | None -> "." - | Some 0 -> "/" - | Some i -> String.sub path 0 i + if path = "" then "." + else Fpath.to_string (Fpath.parent (Fpath.normalize (Fpath.v path))) let rec mkdir_p (path : string) : unit = if path = "" || path = "/" || Sys.file_exists path then () @@ -158,7 +144,7 @@ let rec mkdir_p (path : string) : unit = mkdir_p (dirname path); try Unix.mkdir path 0o777 with Unix.Unix_error (Unix.EEXIST, _, _) -> ()) -let is_absolute (path : string) : bool = String.length path > 0 && path.[0] = '/' +let is_absolute (path : string) : bool = path <> "" && Fpath.is_abs (Fpath.v path) let realpath_opt (path : string) : string option = try Some (Unix.realpath path) with Unix.Unix_error _ -> None
@@ -4,4 +4,4 @@ (foreign_stubs (language c) (names ptrace_stubs)) - (libraries unix yojson camomile ocaml-git)) + (libraries unix yojson camomile ocaml-git fpath))