8000 Handle relative path (instead of absolute) by dinosaure · Pull Request #23 · dinosaure/docteur · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Handle relative path (instead of absolute) #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ $ docteur.make git@github.com:dinosaure/docteur disk.img
$ docteur.make https://github.com/dinosaure/docteur disk.img
$ docteur.make https://user:password@github.com/dinosaure/docteur disk.img
$ docteur.make git://github.com/dinosaure/docteur disk.img
$ docteur.make relativize://directory disk.img
; can be a simple directory which will be prepend by $PWD
$ docteur.make file://$(pwd)/ disk.img
; assume that $(pwd) is a local Git repository
; $(pwd)/.git exists
Expand Down
41 changes: 35 additions & 6 deletions bin/make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,18 @@ let fetch_local_git_repository edn want path output block_size =
match path' with
| Ok path' when Fpath.equal path path' -> Lwt.return_some (ic, oc)
| _ -> Lwt.return_none)
| `Scheme "relative" -> (
let cwd = Sys.getcwd () in
let path' =
match Fpath.of_string (host ^ rest) with
| Ok v when Fpath.is_rooted ~root v ->
let rst = Option.get (Fpath.relativize ~root v) in
Ok Fpath.(v cwd // rst)
| Ok rst -> Ok Fpath.(v cwd // rst)
| Error _ as err -> err in
match path' with
| Ok path' when Fpath.equal path path' -> Lwt.return_some (ic, oc)
| _ -> Lwt.return_none)
| _ -> Lwt.return_none in
let ctx =
let open Mimic in
Expand All @@ -499,7 +511,8 @@ let fetch_local_git_repository edn want path output block_size =
|> Mimic.fold git_transmission
Fun.[ req git_scheme ]
~k:(function
| `Scheme "file" -> Lwt.return_some `Exec | _ -> Lwt.return_none)
| `Scheme "file" | `Scheme "relativize" -> Lwt.return_some `Exec
| _ -> Lwt.return_none)
|> Mimic.fold fifo_edn
Fun.[ req git_scheme; req git_hostname; req git_path ]
~k:k0 in
Expand All @@ -521,12 +534,28 @@ let fetch_local_git_repository edn want path output block_size =

let fetch edn want date_time output block_size =
match edn with
| { Smart_git.Endpoint.scheme = `Scheme "file"; path; hostname; _ } -> (
| {
Smart_git.Endpoint.scheme = `Scheme (("file" | "relativize") as scheme);
path;
hostname;
_;
} -> (
let path =
match Fpath.of_string (hostname ^ path) with
| Ok v when Fpath.is_rooted ~root v -> Ok v
| Ok x -> Ok Fpath.(root // x)
| Error _ as err -> err in
match scheme with
| "file" -> (
match Fpath.of_string (hostname ^ path) with
| Ok v when Fpath.is_rooted ~root v -> Ok v
| Ok x -> Ok Fpath.(root // x)
| Error _ as err -> err)
| "relativize" -> (
let cwd = Sys.getcwd () in
match Fpath.of_string (hostname ^ path) with
| Ok v when Fpath.is_rooted ~root v ->
let rst = Option.get (Fpath.relativize ~root v) in
Ok Fpath.(v cwd // rst)
| Ok rst -> Ok Fpath.(v cwd // rst)
| Error _ as err -> err)
| _ -> assert false in
path |> R.open_error_msg |> Lwt.return >>? fun path ->
is_a_git_repository path >>? function
| true -> fetch_local_git_repository edn want path output block_size
Expand Down
8 changes: 7 additions & 1 deletion test/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ Simple disk.img
author : "Dr. Greenthumb" <noreply@cypress.hill>
root : 7d8a9e386b602e1bd8cd8f226a461a87ccf372e3



$ docteur.make -d 2020-10-10T08:00:00+00:00 relativize://store disk.img
$ docteur.verify disk.img
commit : ca71a852f6c2d16bf04691f13b8a7edeadb15b80
author : "Dr. Greenthumb" <noreply@cypress.hill>
root : 7d8a9e386b602e1bd8cd8f226a461a87ccf372e3

0