changeset 13946:f5e8ab42c708

mod_http_file_share: Check that files are still there with correct size Failed uploads can leave behind unused slots. Files shouldn't change size after they have been successfully uploaded, but might as well double check it.
author Kim Alvefur <zash@zash.se>
date Sat, 04 Dec 2021 18:56:51 +0100
parents b609c777956a
children 0f482af5b882
files plugins/mod_http_file_share.lua
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Fri Sep 12 17:05:42 2025 +0200
+++ b/plugins/mod_http_file_share.lua	Sat Dec 04 18:56:51 2021 +0100
@@ -568,9 +568,21 @@
 	local iter = assert(uploads:find(nil));
 
 	local count, sum = 0, 0;
-	for _, file in iter do
-		sum = sum + tonumber(file.attr.size);
+	for slot_id, file in iter do
 		count = count + 1;
+		local expected_size = tonumber(file.attr.size);
+		local filename = get_filename(slot_id);
+		local actual_size, err = lfs.attributes(filename, "size");
+		if not actual_size then
+			module:log("warn", "Missing file for upload slot %s: %s", slot_id, err);
+			count = count - 1;
+		elseif actual_size ~= expected_size then
+			module:log("warn", "Size mismatch for upload slot %s, expected %s, actual %s", slot_id, B(expected_size), B(actual_size));
+			-- TODO delete?
+			sum = sum + actual_size;
+		else
+			sum = sum + expected_size;
+		end
 	end
 
 	module:log("info", "Uploaded files total: %s in %d files", B(sum), count);