mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-28 05:10:44 +00:00
Improve remove_dir_all
errors (#346)
* feat: Improve remove_dir_all errors * feat: Small improvements of download_file fn * feat: Uinstall now deletes everything inside the Xtensa Rust toolchain folder
This commit is contained in:
parent
2ac988bfea
commit
5219673fb8
@ -44,7 +44,7 @@ pub enum Error {
|
||||
MissingRust,
|
||||
|
||||
#[diagnostic(code(espup::remove_directory))]
|
||||
#[error("{} Failed to remove '{0}' directory.", emoji::ERROR)]
|
||||
#[error("{} Failed to remove '{0}'.", emoji::ERROR)]
|
||||
RemoveDirectory(String),
|
||||
|
||||
#[error(transparent)]
|
||||
|
@ -179,7 +179,8 @@ pub fn uninstall_gcc_toolchains(toolchain_path: &Path) -> Result<(), Error> {
|
||||
.replace(&format!("{gcc_path};"), ""),
|
||||
);
|
||||
}
|
||||
remove_dir_all(gcc_path)?;
|
||||
remove_dir_all(&gcc_path)
|
||||
.map_err(|_| Error::RemoveDirectory(gcc_path.display().to_string()))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,9 @@ impl Llvm {
|
||||
);
|
||||
set_environment_variable("PATH", &updated_path)?;
|
||||
}
|
||||
remove_dir_all(toolchain_path.join(CLANG_NAME))?;
|
||||
let path = toolchain_path.join(CLANG_NAME);
|
||||
remove_dir_all(&path)
|
||||
.map_err(|_| Error::RemoveDirectory(path.display().to_string()))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ pub async fn download_file(
|
||||
emoji::WRENCH,
|
||||
output_directory
|
||||
);
|
||||
if let Err(_e) = create_dir_all(output_directory) {
|
||||
if create_dir_all(output_directory).is_err() {
|
||||
return Err(Error::CreateDirectory(output_directory.to_string()));
|
||||
}
|
||||
}
|
||||
@ -136,10 +136,10 @@ pub async fn download_file(
|
||||
}
|
||||
} else {
|
||||
info!("{} Creating file: '{}'", emoji::WRENCH, file_path);
|
||||
let mut out = File::create(file_path)?;
|
||||
let mut out = File::create(&file_path)?;
|
||||
out.write_all(&bytes)?;
|
||||
}
|
||||
Ok(format!("{output_directory}/{file_name}"))
|
||||
Ok(file_path)
|
||||
}
|
||||
|
||||
/// Installs or updates the Espressif Rust ecosystem.
|
||||
|
@ -20,7 +20,7 @@ use regex::Regex;
|
||||
use std::{
|
||||
env,
|
||||
fmt::Debug,
|
||||
fs::{read_dir, remove_dir_all},
|
||||
fs::{read_dir, remove_dir_all, remove_file},
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
@ -158,14 +158,21 @@ impl XtensaRust {
|
||||
info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH);
|
||||
let dir = read_dir(toolchain_path)?;
|
||||
for entry in dir {
|
||||
let subdir_name = entry.unwrap().path().display().to_string();
|
||||
if !subdir_name.contains(RISCV_GCC)
|
||||
&& !subdir_name.contains(ESP32_GCC)
|
||||
&& !subdir_name.contains(ESP32S2_GCC)
|
||||
&& !subdir_name.contains(ESP32S3_GCC)
|
||||
&& !subdir_name.contains(CLANG_NAME)
|
||||
let entry_path = entry.unwrap().path();
|
||||
let entry_name = entry_path.display().to_string();
|
||||
if !entry_name.contains(RISCV_GCC)
|
||||
&& !entry_name.contains(ESP32_GCC)
|
||||
&& !entry_name.contains(ESP32S2_GCC)
|
||||
&& !entry_name.contains(ESP32S3_GCC)
|
||||
&& !entry_name.contains(CLANG_NAME)
|
||||
{
|
||||
remove_dir_all(Path::new(&subdir_name)).unwrap();
|
||||
if entry_path.is_dir() {
|
||||
remove_dir_all(Path::new(&entry_name))
|
||||
.map_err(|_| Error::RemoveDirectory(entry_name))?;
|
||||
} else {
|
||||
// If the entry is a file, delete the file
|
||||
remove_file(&entry_name)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user