Mercurial > prosody-modules
annotate mod_storage_xmlarchive/datamanager_append_raw.lib.lua @ 5173:460f78654864
mod_muc_rtbl: also filter messages
This was a bit tricky because we don't want to run the JIDs
through SHA256 on each message. Took a while to come up with this
simple plan of just caching the SHA256 of the JIDs on the
occupants.
This will leave some dirt in the occupants after unloading the
module, but that should be ok; once they cycle the room, the
hashes will be gone.
This is direly needed, otherwise, there is a tight race between
the moderation activities and the actors joining the room.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 21 Feb 2023 21:37:27 +0100 |
parents | f4ab0966ba89 |
children |
rev | line source |
---|---|
2289
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local io_open = io.open; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local dm = require "core.storagemanager".olddm; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 -- Append a blob of data to a file |
2343
f4ab0966ba89
mod_storage_xmlarchive: Fix name in datamanager monkeypatch (fixes #774)
Kim Alvefur <zash@zash.se>
parents:
2289
diff
changeset
|
5 function dm.append_raw(username, host, datastore, ext, data) |
2289
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 if type(data) ~= "string" then return; end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local filename = dm.getpath(username, host, datastore, ext, true); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local ok; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local f, msg = io_open(filename, "r+"); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 if not f then |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 -- File did probably not exist, let's create it |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 f, msg = io_open(filename, "w"); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 if not f then |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 return nil, msg, "open"; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local pos = f:seek("end"); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 ok, msg = f:write(data); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 if not ok then |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 f:close(); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 return ok, msg, "write"; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 ok, msg = f:close(); |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 if not ok then |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 return ok, msg; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 return true, pos; |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
aa984980a4dc
mod_storage_xmlarchive: Include the missing append_raw() for 0.9 compatibility
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 |