From cd76558dff6dab21b637483f210a0d2e8dfb16de Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 3 Sep 2023 15:51:25 +0100 Subject: [PATCH] Sanity check the path before attempting to construct app This reduce the number of concurrent tasks, at the cost of increased spawn latency --- src/main.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7bac30a..d4af63e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,14 +67,30 @@ fn get_dokku_root() -> Option { 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) -> axum::Json> { 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)); }