Skip to content

Commit

Permalink
Merge branch 'v2.5.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
reynir committed Jun 13, 2023
2 parents cffe194 + 1e3b706 commit fb02ab9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- `tar`: support pax Global Extended Headers. This adds state to tar parsing.
(#119, #120, @MisterDA)

## v2.5.0 (2023-06-06)

- File names and link names are used from PAX headers when parsing (reported by @gravicappa, fixed in #128 by @reynir)

## v2.4.0 (2023-03-30)

- Switch to alcotest for tests (@MisterDA, review by @reynir, #121)
Expand Down
16 changes: 10 additions & 6 deletions lib/tar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,13 @@ module Header = struct
(* GNU tar and Posix differ in interpretation of the character following ustar. For Posix, it should be '\0' but GNU tar uses ' ' *)
String.length magic >= 5 && (String.sub magic 0 5 = "ustar") in
let prefix = if ustar then get_hdr_prefix c else "" in
let file_name =
let file_name = get_hdr_file_name c in
if file_name = "" then prefix
else if prefix = "" then file_name
else Filename.concat prefix file_name in
let file_name = match extended.Extended.path with
| Some path -> path
| None ->
let file_name = get_hdr_file_name c in
if file_name = "" then prefix
else if prefix = "" then file_name
else Filename.concat prefix file_name in
let file_mode = get_hdr_file_mode c in
let user_id = match extended.Extended.user_id with
| None -> get_hdr_user_id c
Expand All @@ -570,7 +572,9 @@ module Header = struct
let devmajor = if ustar then get_hdr_devmajor c else 0 in
let devminor = if ustar then get_hdr_devminor c else 0 in

let link_name = get_hdr_link_name c in
let link_name = match extended.Extended.link_path with
| Some link_path -> link_path
| None -> get_hdr_link_name c in
Some (make ~file_mode ~user_id ~group_id ~mod_time ~link_indicator
~link_name ~uname ~gname ~devmajor ~devminor file_name file_size)

Expand Down
Binary file added lib_test/long-pax.tar
Binary file not shown.
17 changes: 17 additions & 0 deletions lib_test/parse_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ let can_list_longlink_tar () =
Alcotest.(check (list string)) "respects filenames" expected filenames
) ~finally:(fun () -> Unix.close fd)

let can_list_long_pax_tar () =
let open Tar_unix in
let fd = Unix.openfile "lib_test/long-pax.tar" [ O_RDONLY; O_CLOEXEC ] 0x0 in
Fun.protect
(fun () ->
let all = Archive.list fd in
let filenames = List.map (fun h -> h.Tar.Header.file_name) all in
(* List.iteri (fun i x -> Printf.fprintf stderr "%d: %s\n%!" i x) filenames; *)
let expected = [
"t/";
"t/someveryveryverylonggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggname";
"t/someveryveryverylonggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggglink";
] in
Alcotest.(check (list string)) "respects filenames" expected filenames
) ~finally:(fun () -> Unix.close fd)

let starts_with ~prefix s =
let len_s = String.length s
and len_pre = String.length prefix in
Expand Down Expand Up @@ -304,6 +320,7 @@ let () =
"can_read_tar" >:: can_read_tar;
"can write pax headers" >:: can_write_pax;
"can read @Longlink" >:: can_list_longlink_tar;
"can read pax long names and links" >:: can_list_long_pax_tar;
"can transform tars" >:: can_transform_tar;
]
in
Expand Down

0 comments on commit fb02ab9

Please sign in to comment.