mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 06:05:19 +00:00
455cdc8b37
Refactor HTTP and github release downloading into util Lazily download / upgrade the copilot LSP from Zed Co-authored-by: Max <max@zed.dev> Co-Authored-By: Antonio <antonio@zed.dev>
28 lines
918 B
Rust
28 lines
918 B
Rust
use std::path::Path;
|
|
|
|
use smol::{fs, stream::StreamExt};
|
|
|
|
use crate::ResultExt;
|
|
|
|
// Removes all files and directories matching the given predicate
|
|
pub async fn remove_matching<F>(dir: &Path, predicate: F)
|
|
where
|
|
F: Fn(&Path) -> bool,
|
|
{
|
|
if let Some(mut entries) = fs::read_dir(dir).await.log_err() {
|
|
while let Some(entry) = entries.next().await {
|
|
if let Some(entry) = entry.log_err() {
|
|
let entry_path = entry.path();
|
|
if predicate(entry_path.as_path()) {
|
|
if let Ok(metadata) = fs::metadata(&entry_path).await {
|
|
if metadata.is_file() {
|
|
fs::remove_file(&entry_path).await.log_err();
|
|
} else {
|
|
fs::remove_dir_all(&entry_path).await.log_err();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|