mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-30 06:10:37 +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,
|
MissingRust,
|
||||||
|
|
||||||
#[diagnostic(code(espup::remove_directory))]
|
#[diagnostic(code(espup::remove_directory))]
|
||||||
#[error("{} Failed to remove '{0}' directory.", emoji::ERROR)]
|
#[error("{} Failed to remove '{0}'.", emoji::ERROR)]
|
||||||
RemoveDirectory(String),
|
RemoveDirectory(String),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -179,7 +179,8 @@ pub fn uninstall_gcc_toolchains(toolchain_path: &Path) -> Result<(), Error> {
|
|||||||
.replace(&format!("{gcc_path};"), ""),
|
.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)?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ pub async fn download_file(
|
|||||||
emoji::WRENCH,
|
emoji::WRENCH,
|
||||||
output_directory
|
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()));
|
return Err(Error::CreateDirectory(output_directory.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,10 +136,10 @@ pub async fn download_file(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("{} Creating file: '{}'", emoji::WRENCH, file_path);
|
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)?;
|
out.write_all(&bytes)?;
|
||||||
}
|
}
|
||||||
Ok(format!("{output_directory}/{file_name}"))
|
Ok(file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Installs or updates the Espressif Rust ecosystem.
|
/// Installs or updates the Espressif Rust ecosystem.
|
||||||
|
@ -20,7 +20,7 @@ use regex::Regex;
|
|||||||
use std::{
|
use std::{
|
||||||
env,
|
env,
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
fs::{read_dir, remove_dir_all},
|
fs::{read_dir, remove_dir_all, remove_file},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
};
|
};
|
||||||
@ -158,14 +158,21 @@ impl XtensaRust {
|
|||||||
info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH);
|
info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH);
|
||||||
let dir = read_dir(toolchain_path)?;
|
let dir = read_dir(toolchain_path)?;
|
||||||
for entry in dir {
|
for entry in dir {
|
||||||
let subdir_name = entry.unwrap().path().display().to_string();
|
let entry_path = entry.unwrap().path();
|
||||||
if !subdir_name.contains(RISCV_GCC)
|
let entry_name = entry_path.display().to_string();
|
||||||
&& !subdir_name.contains(ESP32_GCC)
|
if !entry_name.contains(RISCV_GCC)
|
||||||
&& !subdir_name.contains(ESP32S2_GCC)
|
&& !entry_name.contains(ESP32_GCC)
|
||||||
&& !subdir_name.contains(ESP32S3_GCC)
|
&& !entry_name.contains(ESP32S2_GCC)
|
||||||
&& !subdir_name.contains(CLANG_NAME)
|
&& !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(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user