Comparison

plugins/mod_http_file_share.lua @ 12006:62a466e60515

mod_http_file_share: Rename variable for clarity
author Kim Alvefur <zash@zash.se>
date Sat, 04 Dec 2021 15:03:52 +0100
parent 12005:797197b8607e
child 12007:dc72581e04ff
comparison
equal deleted inserted replaced
12005:797197b8607e 12006:62a466e60515
476 elseif total_storage_limit then 476 elseif total_storage_limit then
477 module:log("debug", "Global quota %s / %s", "not yet calculated", B(total_storage_limit)); 477 module:log("debug", "Global quota %s / %s", "not yet calculated", B(total_storage_limit));
478 end 478 end
479 479
480 local obsolete_uploads = array(); 480 local obsolete_uploads = array();
481 local n = 0; 481 local num_expired = 0;
482 local size_sum = 0; 482 local size_sum = 0;
483 local problem_deleting = false; 483 local problem_deleting = false;
484 for slot_id, slot_info in iter do 484 for slot_id, slot_info in iter do
485 n = n + 1; 485 num_expired = num_expired + 1;
486 upload_cache:set(slot_id, nil); 486 upload_cache:set(slot_id, nil);
487 local filename = get_filename(slot_id); 487 local filename = get_filename(slot_id);
488 local deleted, err, errno = os.remove(filename); 488 local deleted, err, errno = os.remove(filename);
489 if deleted or errno == ENOENT then 489 if deleted or errno == ENOENT then
490 size_sum = size_sum + tonumber(slot_info.attr.size); 490 size_sum = size_sum + tonumber(slot_info.attr.size);
491 obsolete_uploads:push(slot_id); 491 obsolete_uploads:push(slot_id);
492 else 492 else
493 module:log("error", "Could not delete file %q: %s", filename, err); 493 module:log("error", "Could not delete file %q: %s", filename, err);
494 problem_deleting = true; 494 problem_deleting = true;
495 end 495 end
496 if n % 100 == 0 then sleep(0.1); end 496 if num_expired % 100 == 0 then sleep(0.1); end
497 end 497 end
498 498
499 -- obsolete_uploads now contains slot ids for which the files have been 499 -- obsolete_uploads now contains slot ids for which the files have been
500 -- deleted and that needs to be cleared from the database 500 -- deleted and that needs to be cleared from the database
501 501
502 local deletion_query = {["end"] = boundary_time}; 502 local deletion_query = {["end"] = boundary_time};
503 if not problem_deleting then 503 if not problem_deleting then
504 module:log("info", "All (%d, %s) expired files successfully deleted", n, B(size_sum)); 504 module:log("info", "All (%d, %s) expired files successfully deleted", num_expired, B(size_sum));
505 -- we can delete based on time 505 -- we can delete based on time
506 else 506 else
507 module:log("warn", "%d out of %d expired files could not be deleted", n-#obsolete_uploads, n); 507 module:log("warn", "%d out of %d expired files could not be deleted", num_expired-#obsolete_uploads, num_expired);
508 -- we'll need to delete only those entries where the files were 508 -- we'll need to delete only those entries where the files were
509 -- successfully deleted, and then try again with the failed ones. 509 -- successfully deleted, and then try again with the failed ones.
510 -- eventually the admin ought to notice and fix the permissions or 510 -- eventually the admin ought to notice and fix the permissions or
511 -- whatever the problem is. 511 -- whatever the problem is.
512 deletion_query = {ids = obsolete_uploads}; 512 deletion_query = {ids = obsolete_uploads};
521 if #obsolete_uploads == 0 then 521 if #obsolete_uploads == 0 then
522 module:log("debug", "No metadata to remove"); 522 module:log("debug", "No metadata to remove");
523 else 523 else
524 local removed, err = uploads:delete(nil, deletion_query); 524 local removed, err = uploads:delete(nil, deletion_query);
525 525
526 if removed == true or removed == n or removed == #obsolete_uploads then 526 if removed == true or removed == num_expired or removed == #obsolete_uploads then
527 module:log("debug", "Removed all metadata for expired uploaded files"); 527 module:log("debug", "Removed all metadata for expired uploaded files");
528 else 528 else
529 module:log("error", "Problem removing metadata for deleted files: %s", err); 529 module:log("error", "Problem removing metadata for deleted files: %s", err);
530 end 530 end
531 end 531 end