Skip to content

Commit be7296f

Browse files
authored
fix(file-explorer): prevent entering files as directories (#5383)
The file_explorer example had two issues: 1. Used heuristic (contains '.') to detect files vs directories, which is unreliable 2. Tried to enter files as directories when clicked, causing errors Changes: - Use path.is_file() for accurate file detection - Use path.is_dir() check before entering a directory - Rename shadowed 'path' variable to 'path_display' Fixes #5368 Co-authored-by: BillionClaw <267901332+BillionClaw@users.noreply.github.com>
1 parent 049e441 commit be7296f

File tree

1 file changed

+7
-3
lines changed
  • examples/01-app-demos/file-explorer/src

1 file changed

+7
-3
lines changed

examples/01-app-demos/file-explorer/src/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ fn app() -> Element {
3131
for (dir_id, path) in files.read().path_names.iter().enumerate() {
3232
{
3333
let path_end = path.components().next_back().map(|p|p.as_os_str()).unwrap_or(path.as_os_str()).to_string_lossy();
34-
let path = path.display();
34+
let path_display = path.display();
35+
let is_file = path.is_file();
3536
rsx! {
36-
div { class: "folder", key: "{path}",
37+
div { class: "folder", key: "{path_display}",
3738
i { class: "material-icons",
3839
onclick: move |_| files.write().enter_dir(dir_id),
39-
if path_end.contains('.') {
40+
if is_file {
4041
"description"
4142
} else {
4243
"folder"
@@ -115,6 +116,9 @@ impl Files {
115116

116117
fn enter_dir(&mut self, dir_id: usize) {
117118
let path = &self.path_names[dir_id];
119+
if !path.is_dir() {
120+
return;
121+
}
118122
self.current_path.clone_from(path);
119123
self.reload_path_list();
120124
}

0 commit comments

Comments
 (0)