Add directory dialog
Some checks failed
CI / Check Style (push) Failing after 27s
CI / Run Clippy (push) Failing after 5m0s
CI / Run Tests (push) Failing after 10m1s

This commit is contained in:
2025-07-28 04:13:34 +02:00
parent 75ca414ef1
commit 77bdae5fff
3 changed files with 207 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
use std::{
collections::HashSet,
fs::{self, OpenOptions},
path::Path,
path::{Path, PathBuf},
};
use serde::Serialize;
@@ -13,6 +14,7 @@ pub struct Directory {
name: String,
path: String,
parent: Option<String>,
is_root: bool,
}
fn is_readable_and_writable(path: &Path) -> bool {
@@ -57,6 +59,7 @@ fn is_hidden(entry: &DirEntry) -> bool {
pub fn get_readable_writable_dirs(root: &Path) -> Vec<Directory> {
let mut dirs = Vec::new();
let mut all_paths = HashSet::new();
for entry in WalkDir::new(root)
.follow_links(false)
@@ -69,13 +72,27 @@ pub fn get_readable_writable_dirs(root: &Path) -> Vec<Directory> {
let path = entry.path();
if is_readable_and_writable(path) {
dirs.push(Directory {
name: entry.file_name().to_string_lossy().to_string(),
path: path.to_string_lossy().to_string(),
parent: path.parent().map(|p| p.to_string_lossy().to_string()),
});
all_paths.insert(path.to_path_buf());
}
}
for path in &all_paths {
let parent = path.parent().map(|p| p.to_string_lossy().to_string());
let is_root = parent
.as_ref()
.map(|p| !all_paths.contains(&PathBuf::from(p)))
.unwrap_or(true);
dirs.push(Directory {
name: path
.file_name()
.map(|f| f.to_string_lossy().to_string())
.unwrap_or_else(|| "/".to_string()),
path: path.to_string_lossy().to_string(),
parent,
is_root,
});
}
dirs
}