diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:11:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-27 22:11:26 +0100 |
commit | fcb7f6f2337ca31882d61723b87fc249a239ff1b (patch) | |
tree | 80f473ee6a2534df632b0ffe4f0bfb4e28fdf805 | |
parent | f2f0965edd46ad8ba0bc9fdd936cdc9fdb55f690 (diff) | |
download | serenity-fcb7f6f2337ca31882d61723b87fc249a239ff1b.zip |
FileManager: Use stat() when activating a file/directory
This makes it possible to open symlinks to directories by activating
them (via double click, for example.) :^)
Fixes #21.
-rw-r--r-- | Applications/FileManager/DirectoryView.cpp | 13 | ||||
-rw-r--r-- | Applications/FileManager/main.cpp | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index d77c139f0d..0f5818c391 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -55,11 +55,20 @@ void DirectoryView::handle_activation(const GModelIndex& index) dbgprintf("on activation: %d,%d, this=%p, m_model=%p\n", index.row(), index.column(), this, m_model.ptr()); auto& node = model().node(index); auto path = node.full_path(model()); - if (node.is_directory()) { + + struct stat st; + if (stat(path.characters(), &st) < 0) { + perror("stat"); + return; + } + + if (S_ISDIR(st.st_mode)) { open(path); return; } - if (node.is_executable()) { + + // FIXME: This doesn't seem like the right way to fully detect executability. + if (st.st_mode & S_IXUSR) { if (fork() == 0) { int rc = execl(path.characters(), path.characters(), nullptr); if (rc < 0) diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index c9ce285c80..7634596c21 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -140,7 +140,7 @@ int main(int argc, char** argv) struct stat st; // If the directory no longer exists, we find a parent that does. - while (lstat(current_path.characters(), &st) != 0) { + while (stat(current_path.characters(), &st) != 0) { directory_view->open_parent_directory(); current_path = directory_view->path(); if (current_path == directories_model->root_path()) { |