Skip to content

Commit

Permalink
remove result (tar requires ocaml 4.03.0 anyways), require 4.05.0 for…
Browse files Browse the repository at this point in the history
… tar-mirage
  • Loading branch information
hannesm committed Mar 2, 2019
1 parent aee659c commit d373f75
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
- PINS="tar:. tar-unix:. tar-mirage:."
matrix:
- DISTRO="alpine" OCAML_VERSION="4.03" PACKAGE="tar-unix"
- DISTRO="alpine" OCAML_VERSION="4.04" PACKAGE="tar-mirage"
- DISTRO="alpine" OCAML_VERSION="4.04" PACKAGE="tar-unix"
- DISTRO="alpine" OCAML_VERSION="4.05" PACKAGE="tar-mirage"
- DISTRO="alpine" OCAML_VERSION="4.06" PACKAGE="tar-unix"
- DISTRO="alpine" OCAML_VERSION="4.07" PACKAGE="tar-mirage"
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
(name tar)
(public_name tar)
(wrapped false)
(libraries result cstruct re.str)
(libraries cstruct re.str)
(flags :standard -safe-string)
(preprocess (pps ppx_cstruct)))
44 changes: 22 additions & 22 deletions lib/tar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ module HeaderReader(Async: ASYNC)(Reader: READER with type 'a t = 'a Async.t) =
open Reader


let read ?level (ifd: Reader.in_channel) : (Header.t, [ `Eof ]) Result.result t =
let read ?level (ifd: Reader.in_channel) : (Header.t, [ `Eof ]) result t =
let level = Header.get_level level in
(* We might need to read 2 headers at once if we encounter a Pax header *)
let buffer = Cstruct.create Header.length in
Expand Down Expand Up @@ -589,8 +589,8 @@ module HeaderReader(Async: ASYNC)(Reader: READER with type 'a t = 'a Async.t) =
begin match Header.unmarshal ~level ~extended real_header_buf with
| None ->
(* Corrupt pax headers *)
return (Result.Error `Eof)
| Some x -> return (Result.Ok x)
return (Error `Eof)
| Some x -> return (Ok x)
end
| Some x when x.Header.link_indicator = Header.Link.LongLink && x.Header.file_name = longlink ->
let extra_header_buf = Cstruct.create (Int64.to_int x.Header.file_size) in
Expand All @@ -601,19 +601,19 @@ module HeaderReader(Async: ASYNC)(Reader: READER with type 'a t = 'a Async.t) =
let file_name = Cstruct.(to_string @@ sub extra_header_buf 0 (len extra_header_buf - 1)) in
begin next ()
>>= function
| None -> return (Result.Error `Eof)
| Some x -> return (Result.Ok { x with file_name })
| None -> return (Error `Eof)
| Some x -> return (Ok { x with file_name })
end
| Some x -> return (Result.Ok x)
| Some x -> return (Ok x)
| None ->
begin
next ()
>>= function
| Some x -> return (Result.Ok x)
| None -> return (Result.Error `Eof)
| Some x -> return (Ok x)
| None -> return (Error `Eof)
end in

let rec read_header (file_name, link_name, hdr) : (Header.t, [`Eof]) Result.result Async.t =
let rec read_header (file_name, link_name, hdr) : (Header.t, [`Eof]) result Async.t =
let raw_link_indicator = Header.get_hdr_link_indicator buffer in
if (raw_link_indicator = 75 || raw_link_indicator = 76) && level = Header.GNU then
let data = Cstruct.create (Int64.to_int hdr.Header.file_size) in
Expand All @@ -625,20 +625,20 @@ module HeaderReader(Async: ASYNC)(Reader: READER with type 'a t = 'a Async.t) =
let data = Header.unmarshal_string (Cstruct.to_string data) in
get_hdr ()
>>= function
| Result.Error `Eof -> return (Result.Error `Eof)
| Result.Ok hdr ->
| Error `Eof -> return (Error `Eof)
| Ok hdr ->
if raw_link_indicator = 75
then read_header (file_name, data, hdr)
else read_header (data, link_name, hdr)
else begin
let link_name = if link_name = "" then hdr.Header.link_name else link_name in
let file_name = if file_name = "" then hdr.Header.file_name else file_name in
return (Result.Ok {hdr with Header.link_name; file_name })
return (Ok {hdr with Header.link_name; file_name })
end in
get_hdr ()
>>= function
| Result.Error `Eof -> return (Result.Error `Eof)
| Result.Ok hdr ->
| Error `Eof -> return (Error `Eof)
| Ok hdr ->
read_header ("", "", hdr)

end
Expand Down Expand Up @@ -775,11 +775,11 @@ module Make (IO : IO) = struct
skips past the zero padding to the next header *)
let with_next_file (fd: IO.in_channel) (f: IO.in_channel -> Header.t -> 'a) =
match HR.read fd with
| Result.Ok hdr ->
| Ok hdr ->
(* NB if the function 'f' fails we're boned *)
finally (fun () -> f fd hdr)
(fun () -> Reader.skip fd (Header.compute_zero_padding_length hdr))
| Result.Error `Eof -> raise Header.End_of_stream
| Error `Eof -> raise Header.End_of_stream

(** List the contents of a tar *)
let list ?level fd =
Expand All @@ -788,11 +788,11 @@ module Make (IO : IO) = struct
try
while true do
match HR.read ~level fd with
| Result.Ok hdr ->
| Ok hdr ->
list := hdr :: !list;
Reader.skip fd (Int64.to_int hdr.Header.file_size);
Reader.skip fd (Header.compute_zero_padding_length hdr)
| Result.Error `Eof -> raise Header.End_of_stream
| Error `Eof -> raise Header.End_of_stream
done;
List.rev !list;
with
Expand Down Expand Up @@ -821,14 +821,14 @@ module Make (IO : IO) = struct
try
while true do
match HR.read ifd with
| Result.Ok hdr ->
| Ok hdr ->
let size = hdr.Header.file_size in
let padding = Header.compute_zero_padding_length hdr in
let ofd = dest hdr in
copy_n ifd ofd size;
IO.close_out ofd;
Reader.skip ifd padding
| Result.Error `Eof -> raise Header.End_of_stream
| Error `Eof -> raise Header.End_of_stream
done
with
| End_of_file -> failwith "Unexpected end of file while reading stream"
Expand All @@ -850,8 +850,8 @@ module Make (IO : IO) = struct
include Header

let get_next_header ?level ic = match HR.read ?level ic with
| Result.Ok hdr -> hdr
| Result.Error `Eof -> raise Header.End_of_stream
| Ok hdr -> hdr
| Error `Eof -> raise Header.End_of_stream

end
end
2 changes: 1 addition & 1 deletion lib/tar.mli
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module HeaderReader(Async: ASYNC)(Reader: READER with type 'a t = 'a Async.t) :
zero-filled blocks are discovered. Assumes stream is positioned at the
possible start of a header block. End_of_file is thrown if the stream
unexpectedly fails *)
val read : ?level:Header.compatibility -> Reader.in_channel -> (Header.t, [`Eof]) Result.result Async.t
val read : ?level:Header.compatibility -> Reader.in_channel -> (Header.t, [`Eof]) result Async.t
end

module HeaderWriter(Async: ASYNC)(Writer: WRITER with type 'a t = 'a Async.t) : sig
Expand Down
4 changes: 2 additions & 2 deletions mirage/tar_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ module Make_KV_RO (BLOCK : Mirage_block_lwt.S) = struct
let in_channel = { Reader.b; offset = 0L; info } in
let rec loop map =
HR.read in_channel >>= function
| Result.Error `Eof -> Lwt.return map
| Result.Ok tar ->
| Error `Eof -> Lwt.return map
| Ok tar ->
let filename = trim_slash tar.Tar.Header.file_name in
let data_tar_offset = Int64.div in_channel.Reader.offset 512L in
let v_or_d = if is_dict filename then Dict (tar, StringMap.empty) else Value (tar, data_tar_offset) in
Expand Down
3 changes: 1 addition & 2 deletions tar-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ homepage: "https://github.com/mirage/ocaml-tar"
doc: "https://mirage.github.io/ocaml-tar/"
bug-reports: "https://github.com/mirage/ocaml-tar/issues"
depends: [
"ocaml" {>= "4.04.2"}
"ocaml" {>= "4.05.0"}
"dune" {build & >= "1.0"}
"tar"
"cstruct" {>= "1.9.0"}
"re" {>="1.7.2"}
"result"
"mirage-block-unix" {with-test & >= "2.5.0"}
"mirage-kv" {>= "2.0.0"}
"mirage-kv-lwt" {>= "2.0.0"}
Expand Down
1 change: 0 additions & 1 deletion tar-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ depends: [
"cstruct" {>= "1.9.0"}
"cstruct-lwt"
"re"
"result"
"lwt"
]
build: [
Expand Down
1 change: 0 additions & 1 deletion tar.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ depends: [
"ppx_cstruct" {>= "3.1.0"}
"cstruct" {>= "1.9.0"}
"re"
"result"
]
build: [
["dune" "subst"] {pinned}
Expand Down
4 changes: 2 additions & 2 deletions unix/tar_lwt_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ module Header = struct
let get_next_header ?level ic =
HR.read ?level ic
>>= function
| Result.Error `Eof -> return None
| Result.Ok hdr -> return (Some hdr)
| Error `Eof -> return None
| Ok hdr -> return (Some hdr)

(** Return the header needed for a particular file on disk *)
let of_file ?level (file: string) : t Lwt.t =
Expand Down

0 comments on commit d373f75

Please sign in to comment.