multipart upload: avoid some extra lines and general code style fixes

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-09-29 16:34:18 +02:00
parent dafe441609
commit aad755eb35

View File

@ -1226,15 +1226,13 @@ sub file_upload_multipart {
//sxx //sxx
) { ) {
assert_form_disposition($1); assert_form_disposition($1);
die "wrong field `name` for file upload, expected `filename` - abort upload" die "wrong field name '$2' for file upload, expected 'filename'" if $2 ne "filename";
if $2 ne "filename";
$rstate->{phase} = 2; $rstate->{phase} = 2;
$rstate->{params}->{filename} = $trim->($3); $rstate->{params}->{filename} = $trim->($3);
} }
} }
# Phase 2 - dump content into file if ($rstate->{phase} == 2) { # Phase 2 - dump content into file
if ($rstate->{phase} == 2) {
my ($data, $write_length); my ($data, $write_length);
if ($hdl->{rbuf} =~ s/^(.*?)${newline_re}?+${close_delim_re}.*$//s) { if ($hdl->{rbuf} =~ s/^(.*?)${newline_re}?+${close_delim_re}.*$//s) {
$data = $1; $data = $1;
@ -1252,28 +1250,21 @@ sub file_upload_multipart {
} }
} }
# Phase 100 - transfer finished if ($rstate->{phase} == 100) { # Phase 100 - transfer finished
if ($rstate->{phase} == 100) {
$rstate->{md5sum} = $rstate->{ctx}->hexdigest; $rstate->{md5sum} = $rstate->{ctx}->hexdigest;
my $elapsed = tv_interval($rstate->{starttime}); my $elapsed = tv_interval($rstate->{starttime});
my $rate = int($rstate->{bytes} / ($elapsed * 1024 * 1024)); syslog('info', "multipart upload complete (size: %d time: %.1fs rate: %.2fMiB/s md5sum: %s)",
syslog('info', $rstate->{bytes}, $elapsed, $rstate->{bytes} / ($elapsed * 1024 * 1024), $rstate->{md5sum}
"multipart upload complete (size: %d time: %ds rate: %.2fMiB/s md5sum: %s)",
$rstate->{bytes}, $elapsed, $rate, $rstate->{md5sum}
); );
$self->handle_api2_request($reqstate, $auth, $method, $path, $rstate); $self->handle_api2_request($reqstate, $auth, $method, $path, $rstate);
} }
$rstate->{read} += $startlen - length($hdl->{rbuf}); $rstate->{read} += $startlen - length($hdl->{rbuf});
if ( if ($rstate->{read} + length($hdl->{rbuf}) >= $rstate->{size} && $rstate->{phase} != 100) {
$rstate->{read} + length($hdl->{rbuf}) >= $rstate->{size}
&& $rstate->{phase} != 100
) {
die "upload failed"; die "upload failed";
} }
}; };
if (my $err = $@) { if (my $err = $@) {
syslog('err', $err); syslog('err', $err);