Sanity check the path before attempting to construct app
This reduce the number of concurrent tasks, at the cost of increased spawn latency
This commit is contained in:
parent
9f6d2d7b3b
commit
cd76558dff
1 changed files with 16 additions and 0 deletions
16
src/main.rs
16
src/main.rs
|
@ -67,14 +67,30 @@ fn get_dokku_root() -> Option<std::path::PathBuf> {
|
|||
None
|
||||
}
|
||||
|
||||
fn osstring_starts_with(data: std::ffi::OsString, prefix: char) -> bool {
|
||||
match data.into_string() {
|
||||
Ok(s) => matches!(s.chars().next(), Some(c) if c == prefix),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn hosts(State(state): State<AppState>) -> axum::Json<Vec<DokkuApp>> {
|
||||
let mut dir_entries = state.dokku_root.read_dir().await.unwrap();
|
||||
|
||||
let mut join_set = JoinSet::new();
|
||||
|
||||
while let Some(Ok(dir_entry)) = dir_entries.next().await {
|
||||
// Skip hidden folders / files
|
||||
if osstring_starts_with(dir_entry.file_name(), '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let path = dir_entry.path();
|
||||
|
||||
if !path.is_dir().await {
|
||||
continue;
|
||||
}
|
||||
|
||||
join_set.spawn(DokkuApp::try_from_path(path));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue