vfs/dir_fs: allow opening empty dirs

Adapts Dir_file_system::open_composite_dirs in a way that it returns "success"
when the leaf node of the path is an empty directory but "lookup failed", as
usual, if one of the other directories on the way to the leaf node is empty.

I couldn't find a technical reason why we used to return "lookup failed" when
only the leaf node was empty.

The commit also adds a test for en empty root directory and empty
sub-directories to the fs_query run script.

Fixes #4198
This commit is contained in:
Martin Stein
2021-06-15 14:32:27 +02:00
committed by Christian Helmuth
parent 6bfdddd0b5
commit 16c4aacf34
2 changed files with 74 additions and 2 deletions

View File

@ -617,7 +617,31 @@ class Vfs::Dir_file_system : public File_system
Opendir_result open_composite_dirs(char const *sub_path,
Dir_vfs_handle &dir_vfs_handle)
{
Opendir_result res = OPENDIR_ERR_LOOKUP_FAILED;
Opendir_result res;
if (strcmp(sub_path, "/")) {
/*
* If there are still directory names in the sub-path, we have
* not reached the leaf node of the original path so far.
* Therefore, if the current directory is empty, this means
* that the original path refers to a directory that doesn't
* exist. Consequently, the result defaults to a
* "lookup failed" error.
*/
res = OPENDIR_ERR_LOOKUP_FAILED;
} else {
/*
* We have reached the leaf node of the original path.
* Therefore the directory referenced by the original path is
* the one that we are at. Consequently, we can let the result
* default to "success" regardless of whether the directory is
* empty. However, if there are any sub-file-systems, we will
* go on and store handles for them in the registry.
*/
res = OPENDIR_OK;
}
try {
for (File_system *fs = _first_file_system; fs; fs = fs->next) {
Vfs_handle *sub_dir_handle = nullptr;