Update sysroot when deps reduced

This commit is contained in:
Wildan M 2026-02-03 17:41:30 +07:00
parent 9004c052db
commit 6cf581e939
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79
2 changed files with 41 additions and 3 deletions

View File

@ -518,9 +518,20 @@ fn build_deps_dir(
let sysroot_modified = modified_dir(&tags_dir).unwrap_or(SystemTime::UNIX_EPOCH);
if sysroot_modified < source_modified
|| sysroot_modified < deps_modified
|| dep_pkgars
.iter()
.any(|(pkg, _)| !tags_dir.join(pkg.as_str()).is_file())
|| !check_files_present(
&tags_dir,
&dep_pkgars
.iter()
.map(|(name, _)| {
// TODO: without_host should just return as_str
if name.is_host() {
&name.as_str()["host:".len()..]
} else {
name.as_str()
}
})
.collect(),
)?
{
log_to_pty!(logger, "DEBUG: updating '{}'", deps_dir.display());
remove_all(deps_dir)?;

View File

@ -1,5 +1,6 @@
use serde::Serialize;
use std::{
collections::BTreeSet,
fs,
io::{self, Write},
path::{Path, PathBuf},
@ -189,6 +190,32 @@ pub fn modified_dir_ignore_git(dir: &Path) -> Result<SystemTime, String> {
})
}
pub fn check_files_present(dir: &Path, expected_files: &BTreeSet<&str>) -> Result<bool, String> {
let entries = fs::read_dir(dir)
.map_err(|err| format!("failed to get list files of '{}': {:?}", dir.display(), err))?;
let mut matches = 0;
for entry_res in entries {
let entry = entry_res
.map_err(|err| format!("failed to get file entry of '{}': {:?}", dir.display(), err))?;
let filename = entry.file_name();
let Some(filename) = filename.to_str() else {
continue;
};
if expected_files.contains(&filename) {
matches += 1
} else if filename.starts_with('.') {
continue;
} else {
return Ok(false);
}
}
Ok(matches == expected_files.len())
}
pub fn rename(src: &Path, dst: &Path) -> Result<(), String> {
fs::rename(src, dst).map_err(|err| {
format!(