mirror of
https://github.com/Swatinem/rust-cache
synced 2025-11-08 00:15:06 +00:00
Add a selftest and support for .cargo/bin
This commit is contained in:
parent
83aad8d470
commit
b495963495
12 changed files with 1897 additions and 69 deletions
32
src/save.ts
32
src/save.ts
|
|
@ -5,7 +5,17 @@ import * as glob from "@actions/glob";
|
|||
import * as io from "@actions/io";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { cleanTarget, getCacheConfig, getPackages, Packages, paths, rm, stateKey } from "./common";
|
||||
import {
|
||||
cleanTarget,
|
||||
getCacheConfig,
|
||||
getCargoBins,
|
||||
getPackages,
|
||||
Packages,
|
||||
paths,
|
||||
rm,
|
||||
stateBins,
|
||||
stateKey,
|
||||
} from "./common";
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
|
|
@ -26,6 +36,10 @@ async function run() {
|
|||
await cleanRegistry(registryName, packages);
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
await cleanBin();
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
await cleanGit(packages);
|
||||
} catch {}
|
||||
|
|
@ -56,6 +70,22 @@ async function getRegistryName(): Promise<string> {
|
|||
return path.basename(path.dirname(first));
|
||||
}
|
||||
|
||||
async function cleanBin() {
|
||||
const bins = await getCargoBins();
|
||||
const oldBins = JSON.parse(core.getState(stateBins));
|
||||
|
||||
for (const bin of oldBins) {
|
||||
bins.delete(bin);
|
||||
}
|
||||
|
||||
const dir = await fs.promises.opendir(path.join(paths.cargoHome, "bin"));
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isFile() && !bins.has(dirent.name)) {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanRegistry(registryName: string, packages: Packages) {
|
||||
await io.rmRF(path.join(paths.index, registryName, ".cache"));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue