3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-04-27 21:55:52 +00:00

save before clearing

This commit is contained in:
Jonathan Kelley 2025-01-28 21:41:21 -08:00
parent 8c8c35255e
commit 6f58383b83
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
4 changed files with 86 additions and 105 deletions

28
dist/restore/index.js vendored
View file

@ -87160,34 +87160,6 @@ async function cleanProfileTarget(profileDir, packages, checkTimestamp, incremen
return;
}
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
// Keep the incremental folder if incremental builds are enabled
if (incremental) {
keepProfile.add("incremental");
// Traverse the incremental folder recursively and collect the modified times in a map
const incrementalDir = external_path_default().join(profileDir, "incremental");
const modifiedTimes = new Map();
const fillModifiedTimes = async (dir) => {
const dirEntries = await external_fs_default().promises.opendir(dir);
for await (const dirent of dirEntries) {
if (dirent.isDirectory()) {
await fillModifiedTimes(external_path_default().join(dir, dirent.name));
}
else {
const fileName = external_path_default().join(dir, dirent.name);
const { mtime } = await external_fs_default().promises.stat(fileName);
modifiedTimes.set(fileName, mtime.getTime());
}
}
};
await fillModifiedTimes(incrementalDir);
// Write the modified times to the incremental folder
lib_core.debug(`writing incremental-restore.json for ${incrementalDir} files`);
for (const file of modifiedTimes.keys()) {
lib_core.debug(` ${file} -> ${modifiedTimes.get(file)}`);
}
const contents = JSON.stringify({ modifiedTimes });
await external_fs_default().promises.writeFile(external_path_default().join(incrementalDir, "incremental-restore.json"), contents);
}
await rmExcept(profileDir, keepProfile);
const keepPkg = new Set(packages.map((p) => p.name));
await rmExcept(external_path_default().join(profileDir, "build"), keepPkg, checkTimestamp);