]> git.proxmox.com Git - pve-http-server.git/commitdiff
anyevent: move unlink from http-server to endpoint
authorLorenz Stechauner <l.stechauner@proxmox.com>
Tue, 31 Aug 2021 10:16:28 +0000 (12:16 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 4 Oct 2021 08:00:23 +0000 (10:00 +0200)
any uploaded file has to be deleted by the corrosponding
endpoint. the file upload was only used by the 'upload to
storage' feature in pve.

this change allows the endpoint to delete the file itself,
making the old and racey`sleep 1` (waiting until the worker
has opened the file) obsolete.

this change breaks all pve-manager versions, in which the
worker does not unlink the temp file itself.

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
src/PVE/APIServer/AnyEvent.pm

index cd778064ff35c96aed714259734baa58224b6de1..86d0e2e401e0fd0409e8898907e6d466b943028a 100644 (file)
@@ -114,7 +114,7 @@ sub log_aborted_request {
 }
 
 sub cleanup_reqstate {
-    my ($reqstate) = @_;
+    my ($reqstate, $deletetmpfile) = @_;
 
     delete $reqstate->{log};
     delete $reqstate->{request};
@@ -123,7 +123,7 @@ sub cleanup_reqstate {
     delete $reqstate->{starttime};
 
     if ($reqstate->{tmpfilename}) {
-       unlink $reqstate->{tmpfilename};
+       unlink $reqstate->{tmpfilename} if $deletetmpfile;
        delete $reqstate->{tmpfilename};
     }
 }
@@ -131,7 +131,7 @@ sub cleanup_reqstate {
 sub client_do_disconnect {
     my ($self, $reqstate) = @_;
 
-    cleanup_reqstate($reqstate);
+    cleanup_reqstate($reqstate, 1);
 
     my $shutdown_hdl = sub {
        my $hdl = shift;
@@ -168,7 +168,7 @@ sub client_do_disconnect {
 sub finish_response {
     my ($self, $reqstate) = @_;
 
-    cleanup_reqstate($reqstate);
+    cleanup_reqstate($reqstate, 0);
 
     my $hdl = $reqstate->{hdl};
     return if !$hdl; # already disconnected