1
Fork 0

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:
Jake Howard 2023-09-03 15:51:25 +01:00
parent 9f6d2d7b3b
commit cd76558dff
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -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));
}