Comparison

plugins/mod_http_file_share.lua @ 12005:797197b8607e

mod_http_file_share: Fix deletion counter Before aa60f4353001 each loop had its own counter, seems incrementing of one of them was lost. But only one is needed anyhow.
author Kim Alvefur <zash@zash.se>
date Sat, 04 Dec 2021 14:28:04 +0100
parent 12004:a2a0e00cbd24
child 12006:62a466e60515
comparison
equal deleted inserted replaced
12004:a2a0e00cbd24 12005:797197b8607e
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 i = 0; 481 local n = 0;
482 local size_sum = 0; 482 local size_sum = 0;
483 local n = 0;
484 local problem_deleting = false; 483 local problem_deleting = false;
485 for slot_id, slot_info in iter do 484 for slot_id, slot_info in iter do
486 i = i + 1; 485 n = n + 1;
487 upload_cache:set(slot_id, nil); 486 upload_cache:set(slot_id, nil);
488 local filename = get_filename(slot_id); 487 local filename = get_filename(slot_id);
489 local deleted, err, errno = os.remove(filename); 488 local deleted, err, errno = os.remove(filename);
490 if deleted or errno == ENOENT then 489 if deleted or errno == ENOENT then
491 size_sum = size_sum + tonumber(slot_info.attr.size); 490 size_sum = size_sum + tonumber(slot_info.attr.size);
492 obsolete_uploads:push(slot_id); 491 obsolete_uploads:push(slot_id);
493 else 492 else
494 module:log("error", "Could not delete file %q: %s", filename, err); 493 module:log("error", "Could not delete file %q: %s", filename, err);
495 problem_deleting = true; 494 problem_deleting = true;
496 end 495 end
497 if i % 100 == 0 then sleep(0.1); end 496 if n % 100 == 0 then sleep(0.1); end
498 end 497 end
499 498
500 -- 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
501 -- deleted and that needs to be cleared from the database 500 -- deleted and that needs to be cleared from the database
502 501