fs_query: gracefully deal with missing directories

The fs_query component used to exit with an uncaught exception if a queried
directory didn't exist. Now, fs_query will catch this event and simply skip the
affected query, thereby indicating to the user the inexistence of the
queried directory.

Ref #4032
This commit is contained in:
Martin Stein 2021-03-25 15:15:45 +01:00 committed by Christian Helmuth
parent 026b117a63
commit 6bfdddd0b5
2 changed files with 21 additions and 1 deletions

View File

@ -81,7 +81,9 @@ install_config {
<resource name="RAM" quantum="2M"/>
<config>
<vfs> <dir name="fs"> <fs writeable="yes"/> </dir> </vfs>
<query path="/fs/items/non_existent_1"/>
<query path="/fs/items" content="yes"/>
<query path="/fs/non_existent_2" content="yes"/>
</config>
</start>
@ -154,6 +156,19 @@ install_config {
</config>
</start>
<start name="/bin/bash" caps="500">
<config>
<libc stdin="/dev/null" stdout="/dev/log" stderr="/dev/log" rtc="/dev/null"/>
<vfs>
<dir name="fs"> <fs writeable="yes"/> </dir>
<dir name="dev"> <log/> <null/> </dir>
</vfs>
<arg value="/bin/bash"/>
<arg value="-c"/>
<arg value="echo updated > /fs/items/3"/>
</config>
</start>
<start name="/bin/sleep" caps="500">
<config>
<libc stdin="/dev/null" stdout="/dev/log" stderr="/dev/log"/>

View File

@ -234,7 +234,12 @@ struct Fs_query::Main : Vfs::Watch_response_handler
config.for_each_sub_node("query", [&] (Xml_node query) {
Directory::Path const path = query.attribute_value("path", Directory::Path());
new (_heap) Registered<Watched_directory>(_dirs, _heap, _root_dir, path, *this);
try {
new (_heap)
Registered<Watched_directory>(
_dirs, _heap, _root_dir, path, *this);
}
catch (Genode::Directory::Nonexistent_directory) { }
});
_reporter.generate([&] (Xml_generator &xml) {