Skip to content

Commit

Permalink
fix(pkg): Check that git repo dir is accessible (#9019)
Browse files Browse the repository at this point in the history
* fix(pkg): Check that git repo dir is accessible

Instead of going ahead and running git against something that is not an
accessible directory, this will at least raise an exception.

Are there better ways to solve it? Except for showing a possibly better
error message, not really - if someone has replaced the folder with
something we can't access there is no other option than to fail in some
way or other.

Signed-off-by: Marek Kubica <marek@tarides.com>
  • Loading branch information
Leonidas-from-XIV authored Oct 29, 2023
1 parent 70f4bf3 commit 55e60de
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/dune_pkg/rev_store.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ let show { dir } (Rev rev) path =

let load_or_create ~dir =
let t = { dir } in
(* TODO might as well double check it's a directory *)
match Path.exists dir with
| true -> Fiber.return t
| false ->
Path.mkdir_p dir;
let+ () = run t [ "init"; "--bare" ] in
t
let* () = Fiber.return () in
let+ () =
match Fpath.mkdir_p (Path.to_string dir) with
| Already_exists -> Fiber.return ()
| Created -> run t [ "init"; "--bare" ]
| exception Unix.Unix_error (e, x, y) ->
User_error.raise
[ Pp.textf "%s isn't a directory" (Path.to_string_maybe_quoted dir)
; Pp.textf "reason: %s" (Unix_error.Detailed.to_string_hum (e, x, y))
]
~hints:[ Pp.text "delete this file or check its permissions" ]
in
t
;;

module Remote = struct
Expand Down

0 comments on commit 55e60de

Please sign in to comment.