os/vfs.h: handle corner case in join function

When specifying "/" or "" as rel_path to the 'Directory' constructor,
the constructed directory should refer to the same directory. The
implementation of the join utility did not consider this corner case. It
occurred during the attempt to use fs_query with "/" given as path.

This patch also adds a Directory::Entry::dir accessor that returns true
if the entry is a directory.

Fixes #3630
This commit is contained in:
Norman Feske 2020-01-31 21:05:26 +01:00 committed by Christian Helmuth
parent a888041ba4
commit 52e582132f
1 changed files with 8 additions and 1 deletions

View File

@ -50,13 +50,14 @@ struct Genode::Directory : Noncopyable, Interface
Entry() { }
using Dirent_type = Vfs::Directory_service::Dirent_type;
public:
void print(Output &out) const
{
using Genode::print;
using Vfs::Directory_service;
using Dirent_type = Directory_service::Dirent_type;
print(out, _dirent.name.buf, " (");
switch (_dirent.type) {
@ -74,6 +75,8 @@ struct Genode::Directory : Noncopyable, Interface
Name name() const { return Name(Cstring(_dirent.name.buf)); }
Vfs::Directory_service::Dirent_type type() const { return _dirent.type; }
bool dir() const { return _dirent.type == Dirent_type::DIRECTORY; }
};
enum { MAX_PATH_LEN = 256 };
@ -84,6 +87,10 @@ struct Genode::Directory : Noncopyable, Interface
{
char const *p = y.string();
while (*p == '/') ++p;
if (x == "/")
return Path("/", p);
return Path(x, "/", p);
}