Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

chore(solc): also rm cache dir if empty #822

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ethers-solc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,25 @@ impl<Artifacts: ArtifactOutput> Project<Artifacts> {
}

/// Removes the project's artifacts and cache file
///
/// If the cache file was the only file in the folder, this also removes the empty folder.
pub fn cleanup(&self) -> std::result::Result<(), SolcIoError> {
tracing::trace!("clean up project");
if self.cache_path().exists() {
std::fs::remove_file(self.cache_path())
.map_err(|err| SolcIoError::new(err, self.cache_path()))?;
if let Some(cache_folder) = self.cache_path().parent() {
// remove the cache folder if the cache file was the only file
if cache_folder
.read_dir()
.map_err(|err| SolcIoError::new(err, cache_folder))?
.next()
.is_none()
{
std::fs::remove_dir(cache_folder)
.map_err(|err| SolcIoError::new(err, cache_folder))?;
}
}
tracing::trace!("removed cache file \"{}\"", self.cache_path().display());
}
if self.paths.artifacts.exists() {
Expand Down