mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
modules/media: Additional checks / cleanup.
This commit is contained in:
parent
e2568457f4
commit
bffff30ac3
2 changed files with 20 additions and 12 deletions
|
@ -88,14 +88,12 @@ write_file(const m::room &room,
|
||||||
pathbuf, pathlen + copy(pathpart, hash)
|
pathbuf, pathlen + copy(pathpart, hash)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!fs::exists(path))
|
wrote += size(fs::overwrite(path, block));
|
||||||
wrote += size(fs::write(path, block));
|
|
||||||
|
|
||||||
off += blksz;
|
off += blksz;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(off == size(content));
|
assert(off == size(content));
|
||||||
assert(wrote <= off);
|
assert(wrote == off);
|
||||||
return wrote;
|
return wrote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +149,16 @@ read_each_block(const m::room &room,
|
||||||
fs::read(path, buf)
|
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);
|
assert(size(block) == blksz);
|
||||||
ret += size(block);
|
ret += size(block);
|
||||||
closure(block);
|
closure(block);
|
||||||
|
|
|
@ -281,32 +281,32 @@ get__thumbnail_local(client &client,
|
||||||
client, http::OK, content_type, file_size
|
client, http::OK, content_type, file_size
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t sent{0};
|
size_t sent_size{0};
|
||||||
const auto sink{[&client, &sent]
|
const auto sink{[&client, &sent_size]
|
||||||
(const const_buffer &block)
|
(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)
|
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",
|
media_log, "File %s/%s [%s] size mismatch: expected %zu got %zu",
|
||||||
hostname,
|
hostname,
|
||||||
mediaid,
|
mediaid,
|
||||||
string_view{room.room_id},
|
string_view{room.room_id},
|
||||||
file_size,
|
file_size,
|
||||||
read
|
read_size
|
||||||
};
|
};
|
||||||
|
|
||||||
// Have to kill client here after failing content length expectation.
|
// 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);
|
client.close(net::dc::RST, net::close_ignore);
|
||||||
|
|
||||||
assert(read == sent);
|
assert(read_size == sent_size);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue