Skip to content

Commit

Permalink
fix: Handle removing non-empty directories and non-existing paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Exelord committed May 9, 2024
1 parent 0322b98 commit 936f05b
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions packages/nx/src/tasks-runner/cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { workspaceRoot } from '../utils/workspace-root';
import { mkdir, mkdirSync, pathExists, readFile, writeFile } from 'fs-extra';
import { mkdir, mkdirSync, pathExists, readFile, writeFile, remove } from 'fs-extra';
import { join } from 'path';
import { performance } from 'perf_hooks';
import { DefaultTasksRunnerOptions } from './default-tasks-runner';
Expand Down Expand Up @@ -90,8 +90,8 @@ export class Cache {
const tdCommit = join(this.cachePath, `${task.hash}.commit`);

// might be left overs from partially-completed cache invocations
await this.remove(tdCommit);
await this.remove(td);
await remove(tdCommit);
await remove(td);

await mkdir(td);
await writeFile(
Expand Down Expand Up @@ -145,7 +145,7 @@ export class Cache {
const cached = join(cachedResult.outputsPath, f);
if (await pathExists(cached)) {
const src = join(this.root, f);
await this.remove(src);
await remove(src);
await this.copy(cached, src);
}
})
Expand Down Expand Up @@ -202,18 +202,6 @@ export class Cache {
});
}

private async remove(path: string): Promise<void> {
const { remove } = require('../native');
return new Promise((res, rej) => {
try {
remove(path);
res();
} catch (e) {
rej(e);
}
});
}

private async getFromLocalDir(task: Task) {
const tdCommit = join(this.cachePath, `${task.hash}.commit`);
const td = join(this.cachePath, task.hash);
Expand Down

0 comments on commit 936f05b

Please sign in to comment.