diff options
author | Andres Vieira <anvieiravazquez@gmail.com> | 2020-04-26 15:56:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-28 10:00:12 +0200 |
commit | a1bcd9ca8aa345ec7c7573dfc3d9471366e73437 (patch) | |
tree | d0ce4782439c8eea35cb4f1c061d82384d20ba8e /Applications/FileManager/main.cpp | |
parent | 24b9e57b150ec03c6cfc60cb3492959460f381cb (diff) | |
download | serenity-a1bcd9ca8aa345ec7c7573dfc3d9471366e73437.zip |
FileManager: Disables mkdir action if permissions don't allow it
Now the "New directory..." contextual menu is disabled if the current
user doesn't have enough permissions to create a node in the current
path.
This prevents the user going to the "New Directory" InputBox, writing
an appropriate name and accepting just to find they can't even do it :)
Diffstat (limited to 'Applications/FileManager/main.cpp')
-rw-r--r-- | Applications/FileManager/main.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp index a2768ab526..3acdb42164 100644 --- a/Applications/FileManager/main.cpp +++ b/Applications/FileManager/main.cpp @@ -654,8 +654,15 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio tree_view.update(); } - go_forward_action->set_enabled(directory_view.path_history_position() - < directory_view.path_history_size() - 1); + struct stat st; + if (lstat(new_path.characters(), &st)) { + perror("stat"); + return; + } + + auto can_write_in_path = access(new_path.characters(), W_OK) == 0; + mkdir_action->set_enabled(can_write_in_path); + go_forward_action->set_enabled(directory_view.path_history_position() < directory_view.path_history_size() - 1); go_back_action->set_enabled(directory_view.path_history_position() > 0); open_parent_directory_action->set_enabled(new_path != "/"); }; |