Skip to content

Commit 36970a0

Browse files
committed
drain the remaining bytes only for compressed case
Signed-off-by: Changlei Li <changlei.li@citrix.com>
1 parent 37de895 commit 36970a0

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

ocaml/xapi/import.ml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ let with_open_archive fd ?length f =
22512251
retry_with_compression := false ;
22522252
let xml = read_xml hdr fd in
22532253
Tar_helpers.skip fd (Tar.Header.compute_zero_padding_length hdr) ;
2254-
f xml fd
2254+
f ~compressed:false xml fd
22552255
with e ->
22562256
if not !retry_with_compression then raise e ;
22572257
let decompress =
@@ -2297,7 +2297,7 @@ let with_open_archive fd ?length f =
22972297
assert_filename_is hdr ;
22982298
let xml = read_xml hdr pipe_out in
22992299
Tar_helpers.skip pipe_out (Tar.Header.compute_zero_padding_length hdr) ;
2300-
f xml pipe_out
2300+
f ~compressed:true xml pipe_out
23012301
)
23022302
(fun () ->
23032303
ignore_exn (fun () -> Unix.close pipe_out) ;
@@ -2448,32 +2448,33 @@ let metadata_handler (req : Request.t) s _ =
24482448
in
24492449
Http_svr.headers s headers ;
24502450
with_open_archive s ?length:req.Request.content_length
2451-
(fun metadata s ->
2451+
(fun ~compressed metadata s ->
24522452
debug "Got XML" ;
24532453
(* Skip trailing two zero blocks *)
24542454
Tar_helpers.skip s (Tar.Header.length * 2) ;
24552455
(* Drain any remaining body bytes (e.g. tar RECORDSIZE padding)
24562456
to prevent EPIPE on the client. See CA-426637. *)
2457-
Option.iter
2458-
(fun content_length ->
2457+
( match (compressed, req.Request.content_length) with
2458+
| false, Some content_length ->
24592459
let file_size = String.length metadata in
24602460
let zero_pad =
24612461
(Tar.Header.length - (file_size mod Tar.Header.length))
24622462
mod Tar.Header.length
24632463
in
24642464
let consumed =
2465-
Tar.Header.length + file_size + zero_pad
2465+
Tar.Header.length
2466+
+ file_size
2467+
+ zero_pad
24662468
+ (Tar.Header.length * 2)
24672469
in
24682470
let remaining = Int64.to_int content_length - consumed in
24692471
if remaining > 0 then (
24702472
debug "Draining %d remaining body bytes" remaining ;
2471-
(try Tar_helpers.skip s remaining
2472-
with End_of_file -> ()
2473-
)
2473+
try Tar_helpers.skip s remaining with End_of_file -> ()
24742474
)
2475-
)
2476-
req.Request.content_length ;
2475+
| _ ->
2476+
()
2477+
) ;
24772478
let header = metadata |> Xmlrpc.of_string |> header_of_rpc in
24782479
assert_compatible ~__context header.version ;
24792480
if full_restore then
@@ -2523,8 +2524,9 @@ let metadata_handler (req : Request.t) s _ =
25232524

25242525
let stream_import __context rpc session_id s content_length refresh_session
25252526
config =
2526-
with_open_archive s ?length:content_length (fun metadata s ->
2527+
with_open_archive s ?length:content_length (fun ~compressed metadata s ->
25272528
debug "Got XML" ;
2529+
ignore compressed ;
25282530
let vmrefs =
25292531
let header = metadata |> Xmlrpc.of_string |> header_of_rpc in
25302532
assert_compatible ~__context header.version ;

0 commit comments

Comments
 (0)