Mercurial > prosody-modules
comparison mod_http_upload/mod_http_upload.lua @ 2688:ef80c9d0ebff
mod_http_upload: Remove unused upload slots
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 15 Apr 2017 15:51:29 +0200 |
| parents | 5f0b755b42a3 |
| children | 0fc706855af9 |
comparison
equal
deleted
inserted
replaced
| 2687:5f0b755b42a3 | 2688:ef80c9d0ebff |
|---|---|
| 77 if not max_age then return true; end | 77 if not max_age then return true; end |
| 78 local uploads, err = datamanager.list_load(username, host, module.name); | 78 local uploads, err = datamanager.list_load(username, host, module.name); |
| 79 if not uploads then return true; end | 79 if not uploads then return true; end |
| 80 uploads = array(uploads); | 80 uploads = array(uploads); |
| 81 local expiry = os.time() - max_age; | 81 local expiry = os.time() - max_age; |
| 82 local upload_window = os.time() - 900; | |
| 82 uploads:filter(function (item) | 83 uploads:filter(function (item) |
| 83 if item.time < expiry then | 84 if item.time < expiry then |
| 84 local deleted, whynot = os.remove(item.filename); | 85 local deleted, whynot = os.remove(item.filename); |
| 85 if not deleted then | 86 if not deleted then |
| 86 module:log("warn", "Could not delete expired upload %s: %s", item.filename, whynot or "delete failed"); | 87 module:log("warn", "Could not delete expired upload %s: %s", item.filename, whynot or "delete failed"); |
| 87 end | 88 end |
| 88 return false; | 89 return false; |
| 90 elseif item.time < upload_window and not lfs.attributes(item.filename) then | |
| 91 return false; -- File was not uploaded or has been deleted since | |
| 89 end | 92 end |
| 90 return true; | 93 return true; |
| 91 end); | 94 end); |
| 92 return datamanager.list_store(username, host, module.name, uploads); | 95 return datamanager.list_store(username, host, module.name, uploads); |
| 93 end | 96 end |
