Skip to content

Commit

Permalink
Add test case for @LongLink implicit dir
Browse files Browse the repository at this point in the history
  • Loading branch information
reynir committed Sep 7, 2023
1 parent 458723a commit ed63bd9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Binary file added lib_test/long-implicit-dir.tar
Binary file not shown.
21 changes: 21 additions & 0 deletions lib_test/parse_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ let can_list_pax_implicit_dir () =
Alcotest.(check link) "is directory" Tar.Header.Link.Directory hdr.link_indicator;
Alcotest.(check string) "filename is patched" "clearly/a/directory/" hdr.file_name)

(* Sample tar generated with commit 1583f71ea33b2836d3fb996ac7dc35d55abe2777:
[let buf =
let long_name = "some/long/name/for/a/directory/" in
let long_hdr = Tar.Header.make ~link_indicator:Tar.Header.Link.LongName "././@LongLink" Int64.(succ (of_int (String.length long_name))) in
let hdr = Tar.Header.make "some/long/name" 0L in
let buf = Cstruct.create ((3+2) * 512) in
let level = Tar.Header.GNU in
Tar.Header.marshal ~level buf long_hdr;
Cstruct.blit_from_string long_name 0 buf 512 (String.length long_name);
Tar.Header.marshal ~level (Cstruct.shift buf 1024) hdr;
buf] *)
let can_list_longlink_implicit_dir () =
let fd = Unix.openfile "lib_test/long-implicit-dir.tar" [ O_RDONLY; O_CLOEXEC ] 0x0 in
Fun.protect ~finally:(fun () -> Unix.close fd)
(fun () ->
let (hdr, _global) = Tar_unix.get_next_header ~global:None fd in
Alcotest.(check link) "is directory" Tar.Header.Link.Directory hdr.link_indicator;
Alcotest.(check string) "filename is patched" "some/long/name/for/a/directory/" hdr.file_name)


let starts_with ~prefix s =
let len_s = String.length s
and len_pre = String.length prefix in
Expand Down Expand Up @@ -344,6 +364,7 @@ let () =
"can read pax long names and links" >:: can_list_long_pax_tar;
"can read pax header with implicit directory" >:: can_list_pax_implicit_dir;
"can transform tars" >:: can_transform_tar;
"can read @LongLink with implicit directory" >:: can_list_longlink_implicit_dir;
]
in
let ( >:: ) desc f = Alcotest_lwt.test_case desc `Quick f in
Expand Down

0 comments on commit ed63bd9

Please sign in to comment.