0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

modules/media: Additional checks / cleanup.

This commit is contained in:
Jason Volk 2018-04-25 18:44:02 -07:00
parent e2568457f4
commit bffff30ac3
2 changed files with 20 additions and 12 deletions

View file

@ -88,14 +88,12 @@ write_file(const m::room &room,
pathbuf, pathlen + copy(pathpart, hash)
};
if(!fs::exists(path))
wrote += size(fs::write(path, block));
wrote += size(fs::overwrite(path, block));
off += blksz;
}
assert(off == size(content));
assert(wrote <= off);
assert(wrote == off);
return wrote;
}
@ -151,6 +149,16 @@ read_each_block(const m::room &room,
fs::read(path, buf)
};
if(unlikely(size(block) != blksz)) throw error
{
"File [%s] block [%s] (%s) blksz %zu != %zu",
string_view{room.room_id},
string_view{at<"event_id"_>(event)},
path,
blksz,
size(block)
};
assert(size(block) == blksz);
ret += size(block);
closure(block);

View file

@ -281,32 +281,32 @@ get__thumbnail_local(client &client,
client, http::OK, content_type, file_size
};
size_t sent{0};
const auto sink{[&client, &sent]
size_t sent_size{0};
const auto sink{[&client, &sent_size]
(const const_buffer &block)
{
sent += client.write_all(block);
sent_size += client.write_all(block);
}};
const size_t read
const size_t read_size
{
read_each_block(room, sink)
};
if(unlikely(read != file_size)) log::error
if(unlikely(read_size != 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
read_size
};
// Have to kill client here after failing content length expectation.
if(unlikely(read != file_size))
if(unlikely(read_size != file_size))
client.close(net::dc::RST, net::close_ignore);
assert(read == sent);
assert(read_size == sent_size);
return response;
}