From 221b368014b13350cab5dd18ce0a33eb9e2c0562 Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Sat, 22 Nov 2014 18:01:14 +0100 Subject: [PATCH 1/2] Remove temporary file with configurable delay --- bot/bot.lua | 12 +++++++++++- bot/config.json | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index c4d3f51..b77f3cb 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -29,6 +29,11 @@ function ok_cb(extra, success, result) end + -- Callback to remove tmp files + function rmtmp_cb(file_path, success, result) + os.remove(file_path) + end + function msg_valid(msg) if msg.text == nil then return false @@ -145,7 +150,7 @@ return result end - function download_to_file( url ) + function download_to_file( url , noremove ) print("url to download: "..url) req, c, h = http.request(url) htype = h["content-type"] @@ -171,6 +176,11 @@ file = io.open(file_path, "w+") file:write(req) file:close() + + if noremove~=nil then + postpone(rmtmp_cb, file_path, config.rmtmp_delay) + end + return file_path end diff --git a/bot/config.json b/bot/config.json index 794fac4..7c20281 100644 --- a/bot/config.json +++ b/bot/config.json @@ -1,4 +1,5 @@ { + "rmtmp_delay": 20, "google_api_key": "", "log_file": "/var/www/html/log.txt", "sh_enabled": false, @@ -10,4 +11,4 @@ "consumer_secret": "" }, "values": { } -} \ No newline at end of file +} From aa4a09f13c6ba336ad3e5abc27b4e4f6b4e69f4d Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Sat, 22 Nov 2014 18:05:13 +0100 Subject: [PATCH 2/2] Correct condition --- bot/bot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index b77f3cb..0cc9c3d 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -177,7 +177,7 @@ file:write(req) file:close() - if noremove~=nil then + if noremove == nil then postpone(rmtmp_cb, file_path, config.rmtmp_delay) end