Skip to content

Commit

Permalink
improve registry cleanpu
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jul 9, 2022
1 parent 7b86267 commit 0497f93
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
- better .cargo/bin handling:
- get a list of all the files on "pre"/"restore"
- move the files out of the way on "post"/"save" and move them back afterwards
- better .cargo/registry handling:
- rather implement better cleaning logic for the registry
10 changes: 7 additions & 3 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = path.join(CARGO_HOME, "registry", "src");
await io.rmRF(srcDir);
// `.cargo/registry/index`
Expand All @@ -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 fs.promises.opendir(path.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(path.join(dir.path, ".cache"));
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(path.join(dir.path, ".git"))) {
await io.rmRF(path.join(dir.path, ".cache"));
}
// TODO: else, clean `.cache` based on the `packages`
}
}
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
Expand All @@ -61933,6 +61936,7 @@ async function cleanRegistry(packages) {
// or `.cargo/registry/cache/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.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);
}
Expand Down
10 changes: 7 additions & 3 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`));
Expand All @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export async function cleanBin() {

export async function cleanRegistry(packages: Packages) {
// `.cargo/registry/src`
// we can remove this completely, as cargo will recreate this from `cache`
const srcDir = path.join(CARGO_HOME, "registry", "src");
await io.rmRF(srcDir);

Expand All @@ -104,9 +105,11 @@ export async function cleanRegistry(packages: Packages) {
// or `.cargo/registry/index/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.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(path.join(dir.path, ".cache"));
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(path.join(dir.path, ".git"))) {
await io.rmRF(path.join(dir.path, ".cache"));
}
// TODO: else, clean `.cache` based on the `packages`
}
}

Expand All @@ -120,6 +123,7 @@ export async function cleanRegistry(packages: Packages) {
// or `.cargo/registry/cache/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.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);
}
Expand Down
1 change: 1 addition & 0 deletions tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fn main() {
println!("Hello, world!");
}

#[cfg(test)]
fn some_fn(input: bool) -> usize {
if input {
2 + 4
Expand Down

0 comments on commit 0497f93

Please sign in to comment.