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

improve registry cleanpu

This commit is contained in:
Arpad Borsos 2022-07-09 19:20:02 +02:00
parent 7b8626742a
commit 0497f9301f
No known key found for this signature in database
GPG key ID: FC7BCA77824B3298
5 changed files with 22 additions and 11 deletions

10
dist/save/index.js vendored
View file

@ -61910,6 +61910,7 @@ async function cleanBin() {
}
async function cleanRegistry(packages) {
// `.cargo/registry/src`
// we can remove this completely, as cargo will recreate this from `cache`
const srcDir = external_path_default().join(CARGO_HOME, "registry", "src");
await io.rmRF(srcDir);
// `.cargo/registry/index`
@ -61919,9 +61920,11 @@ async function cleanRegistry(packages) {
// eg `.cargo/registry/index/github.com-1ecc6299db9ec823`
// or `.cargo/registry/index/index.crates.io-e139d0d48fed7772`
const dir = await external_fs_default().promises.opendir(external_path_default().join(indexDir.path, dirent.name));
// TODO: check for `.git` etc, for now we just always remove the `.cache`
// and leave other stuff untouched.
await io.rmRF(external_path_default().join(dir.path, ".cache"));
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(external_path_default().join(dir.path, ".git"))) {
await io.rmRF(external_path_default().join(dir.path, ".cache"));
}
// TODO: else, clean `.cache` based on the `packages`
}
}
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
@ -61933,6 +61936,7 @@ async function cleanRegistry(packages) {
// or `.cargo/registry/cache/index.crates.io-e139d0d48fed7772`
const dir = await external_fs_default().promises.opendir(external_path_default().join(cacheDir.path, dirent.name));
for await (const dirent of dir) {
// here we check that the downloaded `.crate` matches one from our dependencies
if (dirent.isFile() && !pkgSet.has(dirent.name)) {
await rm(dir.path, dirent);
}