MCPcopy
hub / github.com/Swatinem/rust-cache / cleanTargetDir

Function cleanTargetDir

src/cleanup.ts:10–33  ·  view source on GitHub ↗
(targetDir: string, packages: Packages, checkTimestamp = false)

Source from the content-addressed store, hash-verified

8import { Packages } from "./workspace";
9
10export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
11 core.debug(`cleaning target directory "${targetDir}"`);
12
13 // remove all *files* from the profile directory
14 let dir = await fs.promises.opendir(targetDir);
15 for await (const dirent of dir) {
16 if (dirent.isDirectory()) {
17 let dirName = path.join(dir.path, dirent.name);
18 // is it a profile dir, or a nested target dir?
19 let isNestedTarget =
20 (await exists(path.join(dirName, "CACHEDIR.TAG"))) || (await exists(path.join(dirName, ".rustc_info.json")));
21
22 try {
23 if (isNestedTarget) {
24 await cleanTargetDir(dirName, packages, checkTimestamp);
25 } else {
26 await cleanProfileTarget(dirName, packages, checkTimestamp);
27 }
28 } catch {}
29 } else if (dirent.name !== "CACHEDIR.TAG") {
30 await rm(dir.path, dirent);
31 }
32 }
33}
34
35async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
36 core.debug(`cleaning profile directory "${profileDir}"`);

Callers 3

runFunction · 0.90
runFunction · 0.90
cleanProfileTargetFunction · 0.85

Calls 3

existsFunction · 0.90
cleanProfileTargetFunction · 0.85
rmFunction · 0.85

Tested by

no test coverage detected