unfetch: Remove source.tar if distclean or no hash

This commit is contained in:
Wildan M 2026-07-13 06:17:01 +07:00
parent d82e572598
commit d9927e67a7
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79

View File

@ -863,7 +863,7 @@ fn handle_nonstop_fail(recipe: &CookRecipe) -> cookbook::Result<()> {
Ok(())
}
fn handle_clean(recipe: &CookRecipe, _config: &CliConfig, command: &CliCommand) -> Result<bool> {
fn handle_clean(recipe: &CookRecipe, config: &CliConfig, command: &CliCommand) -> Result<bool> {
let mut dir = recipe.dir.join("target");
let mut cached = true;
let unfetch = matches!(*command, CliCommand::Unfetch);
@ -879,10 +879,25 @@ fn handle_clean(recipe: &CookRecipe, _config: &CliConfig, command: &CliCommand)
remove_all(&dir)?;
cached = false;
}
let dir = recipe.dir.join("source");
if dir.exists() && unfetch {
remove_all(&dir)?;
cached = false;
if unfetch {
let dir = recipe.dir.join("source");
if dir.exists() {
remove_all(&dir)?;
cached = false;
}
let tar = recipe.dir.join("source.tar");
// remove tar if there's no blake3 or `make distclean`
if tar.is_file() {
if let Some(SourceRecipe::Tar { blake3, .. }) = &recipe.recipe.source
&& blake3.is_none()
{
remove_all(&tar)?;
cached = false;
} else if config.all {
remove_all(&tar)?;
cached = false;
}
}
}
Ok(cached)
}