Skip to content
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

Fix tar transfer: use GNU tar format instead of UStar for copy operations #82

Merged
merged 2 commits into from
Oct 27, 2021
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### unreleased

- Use GNU tar format instead of UStar for `copy` operations (@TheLortex ...).
This enables copying from sources containing long file names (>100 characters).

- Add support for secrets (@TheLortex #63, reviewed by @talex5).
The obuilder spec's `run` command supports a new `secrets` fields, which allows to temporarily
mount secret files in an user-specified location. The sandbox build context has an additional
Expand Down
1 change: 1 addition & 0 deletions lib/obuilder.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ module Manifest = Manifest
module Escape = Escape
module Os = Os
module Db = Db
module Tar_transfer = Tar_transfer
2 changes: 1 addition & 1 deletion lib/tar_transfer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Tar_lwt_unix = struct
module HW = Tar.HeaderWriter(Lwt)(Writer)

let write_block (header: Tar.Header.t) (body: Lwt_unix.file_descr -> unit Lwt.t) (fd : Lwt_unix.file_descr) =
HW.write ~level:Tar.Header.Ustar header fd
HW.write ~level:Tar.Header.GNU header fd
>>= fun () ->
body fd >>= fun () ->
Writer.really_write fd (Tar.Header.zero_padding header)
Expand Down
28 changes: 28 additions & 0 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,31 @@ let test_delete _switch () =
Alcotest.(check build_result) "Build 2 result" (Ok "B") result2;
Lwt.return_unit

let test_tar_long_filename _switch () =
let do_test length =
Logs.info (fun m -> m "Test copy length %d " length);
Lwt_io.with_temp_dir ~prefix:"test-copy-src-" @@ fun src_dir ->
Lwt_io.with_temp_dir ~prefix:"test-copy-dst-" @@ fun dst_dir ->
let filename = String.make length 'a' in
Lwt_io.(with_file ~mode:output)
(src_dir / filename)
(fun ch -> Lwt_io.write ch "file-data")
>>= fun () ->
Lwt_unix.openfile (dst_dir / "out.tar") [Lwt_unix.O_WRONLY; Lwt_unix.O_CREAT] 0
>>= fun to_untar ->
let src_manifest = Manifest.generate ~exclude:[] ~src_dir "." |> Result.get_ok in
let user = {Spec.uid=1000; gid=1000} in
Tar_transfer.send_file
~src_dir
~src_manifest
~dst:dst_dir
~user
~to_untar
in
do_test 80 >>= fun () ->
do_test 160 >>= fun () ->
do_test 240

let sexp = Alcotest.of_pp Sexplib.Sexp.pp_hum

let remove_line_indents = function
Expand Down Expand Up @@ -674,6 +699,9 @@ let () =
test_case "Simple" `Quick test_secrets_simple;
test_case "No secret provided" `Quick test_secrets_not_provided;
];
"tar_transfer", [
test_case "Long filename" `Quick test_tar_long_filename;
];
"manifest", [
test_case "Copy" `Quick test_copy;
];
Expand Down