mirror of
https://github.com/Swatinem/rust-cache.git
synced 2024-11-22 13:57:10 +08:00
clean nested and arbitrary profile and target directories
This commit is contained in:
parent
827b33fbd0
commit
86bae2494f
33
dist/restore/index.js
vendored
33
dist/restore/index.js
vendored
@ -61868,6 +61868,28 @@ async function getRustVersion() {
|
||||
|
||||
|
||||
async function cleanTargetDir(targetDir, packages) {
|
||||
let dir;
|
||||
// remove all *files* from the profile directory
|
||||
dir = await external_fs_default().promises.opendir(targetDir);
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory()) {
|
||||
let dirName = external_path_default().join(dir.path, dirent.name);
|
||||
// is it a profile dir, or a nested target dir?
|
||||
let isNestedTarget = await exists(external_path_default().join(dirName, "CACHEDIR.TAG"));
|
||||
try {
|
||||
if (isNestedTarget) {
|
||||
await cleanTargetDir(dirName, packages);
|
||||
}
|
||||
else {
|
||||
await cleanProfileTarget(dirName, packages);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (dirent.name !== "CACHEDIR.TAG") {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json"));
|
||||
// TODO: remove all unknown files, clean all directories like profiles
|
||||
try {
|
||||
@ -62002,6 +62024,15 @@ async function rm(parent, dirent) {
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
async function exists(path) {
|
||||
try {
|
||||
await external_fs_default().promises.access(path);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/restore.ts
|
||||
|
||||
@ -62040,8 +62071,8 @@ async function run() {
|
||||
if (restoreKey !== key) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
for (const workspace of config.workspaces) {
|
||||
const packages = await workspace.getPackages();
|
||||
try {
|
||||
const packages = await workspace.getPackages();
|
||||
await cleanTargetDir(workspace.target, packages);
|
||||
}
|
||||
catch { }
|
||||
|
31
dist/save/index.js
vendored
31
dist/save/index.js
vendored
@ -61868,6 +61868,28 @@ async function getRustVersion() {
|
||||
|
||||
|
||||
async function cleanTargetDir(targetDir, packages) {
|
||||
let dir;
|
||||
// remove all *files* from the profile directory
|
||||
dir = await external_fs_default().promises.opendir(targetDir);
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory()) {
|
||||
let dirName = external_path_default().join(dir.path, dirent.name);
|
||||
// is it a profile dir, or a nested target dir?
|
||||
let isNestedTarget = await exists(external_path_default().join(dirName, "CACHEDIR.TAG"));
|
||||
try {
|
||||
if (isNestedTarget) {
|
||||
await cleanTargetDir(dirName, packages);
|
||||
}
|
||||
else {
|
||||
await cleanProfileTarget(dirName, packages);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else if (dirent.name !== "CACHEDIR.TAG") {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json"));
|
||||
// TODO: remove all unknown files, clean all directories like profiles
|
||||
try {
|
||||
@ -62002,6 +62024,15 @@ async function rm(parent, dirent) {
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
async function exists(path) {
|
||||
try {
|
||||
await external_fs_default().promises.access(path);
|
||||
return true;
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/save.ts
|
||||
|
||||
|
@ -7,6 +7,27 @@ import { CacheConfig, STATE_BINS } from "./config";
|
||||
import { Packages } from "./workspace";
|
||||
|
||||
export async function cleanTargetDir(targetDir: string, packages: Packages) {
|
||||
let dir: fs.Dir;
|
||||
// remove all *files* from the profile directory
|
||||
dir = await fs.promises.opendir(targetDir);
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory()) {
|
||||
let dirName = path.join(dir.path, dirent.name);
|
||||
// is it a profile dir, or a nested target dir?
|
||||
let isNestedTarget = await exists(path.join(dirName, "CACHEDIR.TAG"));
|
||||
|
||||
try {
|
||||
if (isNestedTarget) {
|
||||
await cleanTargetDir(dirName, packages);
|
||||
} else {
|
||||
await cleanProfileTarget(dirName, packages);
|
||||
}
|
||||
} catch {}
|
||||
} else if (dirent.name !== "CACHEDIR.TAG") {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
|
||||
await fs.promises.unlink(path.join(targetDir, "./.rustc_info.json"));
|
||||
|
||||
// TODO: remove all unknown files, clean all directories like profiles
|
||||
@ -156,3 +177,12 @@ export async function rm(parent: string, dirent: fs.Dirent) {
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function exists(path: string) {
|
||||
try {
|
||||
await fs.promises.access(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ async function run() {
|
||||
if (restoreKey !== key) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
for (const workspace of config.workspaces) {
|
||||
const packages = await workspace.getPackages();
|
||||
|
||||
try {
|
||||
const packages = await workspace.getPackages();
|
||||
|
||||
await cleanTargetDir(workspace.target, packages);
|
||||
} catch {}
|
||||
}
|
||||
|
911
tests/Cargo.lock
generated
911
tests/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user