fs_query: support querying file sizes

By adding an attribute 'size="yes"' to a query, one instructs fs_query to
report also the size of each queried file as attribute 'size' of the
corresponding 'file' node.

Ref #4032
This commit is contained in:
Martin Stein 2021-04-24 10:48:36 +02:00 committed by Christian Helmuth
parent 3ed26e7bb2
commit dd587c6712
2 changed files with 7 additions and 0 deletions

View File

@ -12,3 +12,7 @@ content of the queried files is supplemented as body of the '<file>' nodes.
The reported content is limited to 4 KiB per file. If the content is valid
XML, the '<file>' node contains an attribute 'xml="yes"' indicating that
the XML information is inserted as is. Otherwise, the content is sanitized.
Furthermore, a query can contain a 'size="yes"' attribute. If set, the size of
each queried file is reported as number of bytes through an attribute 'size' in
the corresponding '<file>' node.

View File

@ -88,6 +88,9 @@ struct Fs_query::Watched_file
xml.node("file", [&] () {
xml.attribute("name", _name);
if (query.attribute_value("size", false))
xml.attribute("size", dir.file_size(_name));
if (_rwx.writeable)
xml.attribute("writeable", "yes");