mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-07-19 07:11:24 +03:00
Improve errors and cleanup
- Silence errors and do not create error annotations, fixes #144 - Implement cleanup for new sparse registry - Do not clean `-sys` dependencies from `registry/src`, hopefully fixes #150
This commit is contained in:
76
dist/restore/index.js
vendored
76
dist/restore/index.js
vendored
@ -66810,6 +66810,16 @@ var exec = __nccwpck_require__(1514);
|
||||
|
||||
|
||||
|
||||
function reportError(e) {
|
||||
const { commandFailed } = e;
|
||||
if (commandFailed) {
|
||||
lib_core.error(`Command failed: ${commandFailed.command}`);
|
||||
lib_core.error(commandFailed.stderr);
|
||||
}
|
||||
else {
|
||||
lib_core.error(`${e.stack}`);
|
||||
}
|
||||
}
|
||||
async function getCmdOutput(cmd, args = [], options = {}) {
|
||||
let stdout = "";
|
||||
let stderr = "";
|
||||
@ -66828,8 +66838,10 @@ async function getCmdOutput(cmd, args = [], options = {}) {
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
lib_core.error(`Command failed: ${cmd} ${args.join(" ")}`);
|
||||
lib_core.error(stderr);
|
||||
e.commandFailed = {
|
||||
command: `${cmd} ${args.join(" ")}`,
|
||||
stderr,
|
||||
};
|
||||
throw e;
|
||||
}
|
||||
return stdout;
|
||||
@ -66837,10 +66849,10 @@ async function getCmdOutput(cmd, args = [], options = {}) {
|
||||
function getCacheHandler() {
|
||||
const cacheProvider = lib_core.getInput("cache-provider");
|
||||
switch (cacheProvider) {
|
||||
case 'github':
|
||||
case "github":
|
||||
lib_core.info("Using Github Cache.");
|
||||
return lib_cache;
|
||||
case 'buildjet':
|
||||
case "buildjet":
|
||||
lib_core.info("Using Buildjet Cache.");
|
||||
return cache;
|
||||
default:
|
||||
@ -67259,10 +67271,8 @@ async function cleanBin(oldBins) {
|
||||
}
|
||||
}
|
||||
async function cleanRegistry(packages, crates = true) {
|
||||
// `.cargo/registry/src`
|
||||
// we can remove this completely, as cargo will recreate this from `cache`
|
||||
await rmRF(path.join(CARGO_HOME, "registry", "src"));
|
||||
// `.cargo/registry/index`
|
||||
let pkgSet = new Set(packages.map((p) => p.name));
|
||||
const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
|
||||
for await (const dirent of indexDir) {
|
||||
if (dirent.isDirectory()) {
|
||||
@ -67273,15 +67283,35 @@ async function cleanRegistry(packages, crates = true) {
|
||||
if (await exists(path.join(dirPath, ".git"))) {
|
||||
await rmRF(path.join(dirPath, ".cache"));
|
||||
}
|
||||
// TODO: else, clean `.cache` based on the `packages`
|
||||
else {
|
||||
await cleanRegistryIndexCache(dirPath, pkgSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!crates) {
|
||||
core.debug(`skipping crate cleanup`);
|
||||
core.debug("skipping registry cache and src cleanup");
|
||||
return;
|
||||
}
|
||||
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
|
||||
// `.cargo/registry/src`
|
||||
// Cargo usually re-creates these from the `.crate` cache below,
|
||||
// but for some reason that does not work for `-sys` crates that check timestamps
|
||||
// to decide if rebuilds are necessary.
|
||||
pkgSet = new Set(packages.filter((p) => p.name.endsWith("-sys")).map((p) => `${p.name}-${p.version}`));
|
||||
const srcDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "src"));
|
||||
for await (const dirent of srcDir) {
|
||||
if (dirent.isDirectory()) {
|
||||
// eg `.cargo/registry/src/github.com-1ecc6299db9ec823`
|
||||
// or `.cargo/registry/src/index.crates.io-e139d0d48fed7772`
|
||||
const dir = await fs.promises.opendir(path.join(srcDir.path, dirent.name));
|
||||
for await (const dirent of dir) {
|
||||
if (dirent.isDirectory() && !pkgSet.has(dirent.name)) {
|
||||
await rmRF(path.join(dir.path, dirent.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// `.cargo/registry/cache`
|
||||
pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
|
||||
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
|
||||
for await (const dirent of cacheDir) {
|
||||
if (dirent.isDirectory()) {
|
||||
@ -67297,6 +67327,30 @@ async function cleanRegistry(packages, crates = true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Recursively walks and cleans the index `.cache`
|
||||
async function cleanRegistryIndexCache(dirName, keepPkg) {
|
||||
let dirIsEmpty = true;
|
||||
const cacheDir = await fs.promises.opendir(dirName);
|
||||
for await (const dirent of cacheDir) {
|
||||
if (dirent.isDirectory()) {
|
||||
if (await cleanRegistryIndexCache(path.join(dirName, dirent.name), keepPkg)) {
|
||||
await rm(dirName, dirent);
|
||||
}
|
||||
else {
|
||||
dirIsEmpty && (dirIsEmpty = false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (keepPkg.has(dirent.name)) {
|
||||
dirIsEmpty && (dirIsEmpty = false);
|
||||
}
|
||||
else {
|
||||
await rm(dirName, dirent);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dirIsEmpty;
|
||||
}
|
||||
async function cleanGit(packages) {
|
||||
const coPath = path.join(CARGO_HOME, "git", "checkouts");
|
||||
const dbPath = path.join(CARGO_HOME, "git", "db");
|
||||
@ -67466,7 +67520,7 @@ async function run() {
|
||||
}
|
||||
catch (e) {
|
||||
setCacheHitOutput(false);
|
||||
lib_core.error(`${e.stack}`);
|
||||
reportError(e);
|
||||
}
|
||||
}
|
||||
function setCacheHitOutput(cacheHit) {
|
||||
|
Reference in New Issue
Block a user