From 52e582132ffc53f92dfc3aa599b68dac128dc62b Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 31 Jan 2020 21:05:26 +0100 Subject: [PATCH] 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 --- repos/os/include/os/vfs.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/repos/os/include/os/vfs.h b/repos/os/include/os/vfs.h index 094b3072fc..0996b81587 100644 --- a/repos/os/include/os/vfs.h +++ b/repos/os/include/os/vfs.h @@ -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); }