0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 23:10:54 +01:00

modules/media: Add error logging; various cleanup.

This commit is contained in:
Jason Volk 2018-04-24 18:26:35 -07:00
parent a13c11c93c
commit bc79fabfef
4 changed files with 48 additions and 16 deletions

View file

@ -127,7 +127,20 @@ get__download_local(client &client,
sent += write_all(*client.sock, block); sent += write_all(*client.sock, block);
}); });
assert(sent == file_size); if(unlikely(read != file_size)) log::error
{
media_log, "File %s/%s [%s] size mismatch: expected %zu got %zu",
server,
file,
string_view{room.room_id},
file_size,
read
};
// Have to kill client here after failing content length expectation.
if(unlikely(read != file_size))
client.close(net::dc::RST, net::close_ignore);
return {}; return {};
} }

View file

@ -16,9 +16,15 @@ IRCD_MODULE
"11.7 :Content respository" "11.7 :Content respository"
}; };
decltype(media_log)
media_log
{
"media"
};
size_t size_t
write_file(const m::room &room, write_file(const m::room &room,
const string_view &content, const const_buffer &content,
const string_view &content_type) const string_view &content_type)
{ {
//TODO: TXN //TODO: TXN
@ -95,7 +101,7 @@ write_file(const m::room &room,
size_t size_t
read_each_block(const m::room &room, read_each_block(const m::room &room,
const std::function<void (const string_view &)> &closure) const std::function<void (const const_buffer &)> &closure)
{ {
const auto lpath const auto lpath
{ {
@ -118,7 +124,7 @@ read_each_block(const m::room &room,
}; };
size_t ret{0}; size_t ret{0};
m::room::messages it{room, 0}; m::room::messages it{room, 1};
for(; bool(it); ++it) for(; bool(it); ++it)
{ {
const m::event &event{*it}; const m::event &event{*it};
@ -140,7 +146,7 @@ read_each_block(const m::room &room,
pathbuf, pathlen + copy(pathpart, hash) pathbuf, pathlen + copy(pathpart, hash)
}; };
const string_view &block const const_buffer &block
{ {
fs::read(path, buf) fs::read(path, buf)
}; };

View file

@ -10,6 +10,9 @@
using namespace ircd; using namespace ircd;
extern mapi::header IRCD_MODULE;
extern log::log media_log;
extern "C" m::room::id extern "C" m::room::id
file_room_id(m::room::id::buf &out, file_room_id(m::room::id::buf &out,
const string_view &server, const string_view &server,
@ -19,5 +22,5 @@ m::room::id::buf
file_room_id(const string_view &server, file_room_id(const string_view &server,
const string_view &file); const string_view &file);
size_t read_each_block(const m::room &, const std::function<void (const string_view &)> &); size_t read_each_block(const m::room &, const std::function<void (const const_buffer &)> &);
size_t write_file(const m::room &room, const string_view &content, const string_view &content_type); size_t write_file(const m::room &room, const const_buffer &content, const string_view &content_type);

View file

@ -221,18 +221,15 @@ try
content_type content_type
}; };
// Send it off to user first
const resource::response response
{
client, remote_request.in.content, content_type
};
const size_t written const size_t written
{ {
write_file(room, remote_request.in.content, content_type) write_file(room, remote_request.in.content, content_type)
}; };
return response; return resource::response
{
client, remote_request.in.content, content_type
};
} }
catch(const ircd::server::unavailable &e) catch(const ircd::server::unavailable &e)
{ {
@ -286,7 +283,7 @@ get__thumbnail_local(client &client,
size_t sent{0}; size_t sent{0};
const auto sink{[&client, &sent] const auto sink{[&client, &sent]
(const string_view &block) (const const_buffer &block)
{ {
sent += client.write_all(block); sent += client.write_all(block);
}}; }};
@ -296,7 +293,20 @@ get__thumbnail_local(client &client,
read_each_block(room, sink) read_each_block(room, sink)
}; };
assert(read == file_size); if(unlikely(read != file_size)) log::error
{
media_log, "File %s/%s [%s] size mismatch: expected %zu got %zu",
hostname,
mediaid,
string_view{room.room_id},
file_size,
read
};
// Have to kill client here after failing content length expectation.
if(unlikely(read != file_size))
client.close(net::dc::RST, net::close_ignore);
assert(read == sent); assert(read == sent);
return response; return response;
} }