diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:10:19 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:10:19 +0100 |
commit | f2f0965edd46ad8ba0bc9fdd936cdc9fdb55f690 (patch) | |
tree | ccb23271326da68e9aad821ead56fbd0e0cc7aa7 /Libraries/LibGUI | |
parent | c64904a4836c85645b63f0fb6c5c0b67cd2ccca0 (diff) | |
download | serenity-f2f0965edd46ad8ba0bc9fdd936cdc9fdb55f690.zip |
LibGUI: Have GFileSystemModel use stat instead of lstat for the root
This allows you to set the GFileSystemModel root to a symlink to a
directory and it nicely opens that directory like you would expect.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r-- | Libraries/LibGUI/GFileSystemModel.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibGUI/GFileSystemModel.h | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/Libraries/LibGUI/GFileSystemModel.cpp b/Libraries/LibGUI/GFileSystemModel.cpp index 0aa57d8c3d..90bb4a60f4 100644 --- a/Libraries/LibGUI/GFileSystemModel.cpp +++ b/Libraries/LibGUI/GFileSystemModel.cpp @@ -49,12 +49,16 @@ GModelIndex GFileSystemModel::Node::index(const GFileSystemModel& model, int col ASSERT_NOT_REACHED(); } -bool GFileSystemModel::Node::fetch_data_using_lstat(const String& full_path) +bool GFileSystemModel::Node::fetch_data(const String& full_path, bool is_root) { struct stat st; - int rc = lstat(full_path.characters(), &st); + int rc; + if (is_root) + rc = stat(full_path.characters(), &st); + else + rc = lstat(full_path.characters(), &st); if (rc < 0) { - perror("lstat"); + perror("stat/lstat"); return false; } @@ -64,7 +68,6 @@ bool GFileSystemModel::Node::fetch_data_using_lstat(const String& full_path) gid = st.st_gid; inode = st.st_ino; mtime = st.st_mtime; - return true; } @@ -86,7 +89,7 @@ void GFileSystemModel::Node::traverse_if_needed(const GFileSystemModel& model) String name = di.next_path(); String child_path = String::format("%s/%s", full_path.characters(), name.characters()); NonnullOwnPtr<Node> child = make<Node>(); - bool ok = child->fetch_data_using_lstat(child_path); + bool ok = child->fetch_data(child_path, false); if (!ok) continue; if (model.m_mode == DirectoriesOnly && !S_ISDIR(child->mode)) @@ -126,7 +129,7 @@ void GFileSystemModel::Node::reify_if_needed(const GFileSystemModel& model) traverse_if_needed(model); if (mode != 0) return; - fetch_data_using_lstat(full_path(model)); + fetch_data(full_path(model), parent == nullptr); } String GFileSystemModel::Node::full_path(const GFileSystemModel& model) const diff --git a/Libraries/LibGUI/GFileSystemModel.h b/Libraries/LibGUI/GFileSystemModel.h index 977b35e2bd..4716c6f876 100644 --- a/Libraries/LibGUI/GFileSystemModel.h +++ b/Libraries/LibGUI/GFileSystemModel.h @@ -88,7 +88,7 @@ public: GModelIndex index(const GFileSystemModel&, int column) const; void traverse_if_needed(const GFileSystemModel&); void reify_if_needed(const GFileSystemModel&); - bool fetch_data_using_lstat(const String& full_path); + bool fetch_data(const String& full_path, bool is_root); }; static NonnullRefPtr<GFileSystemModel> create(const StringView& root_path = "/", Mode mode = Mode::FilesAndDirectories) |