3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-08-18 02:42:18 +00:00

wip: add incremental mtime restore

This commit is contained in:
Jonathan Kelley 2025-01-28 18:13:52 -08:00
parent f0deed1e0e
commit 3faf29c29b
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
6 changed files with 116 additions and 21 deletions

48
src/incremental.ts Normal file
View file

@ -0,0 +1,48 @@
import * as core from "@actions/core";
import * as io from "@actions/io";
import fs from "fs";
import path from "path";
import { CARGO_HOME } from "./config";
import { exists } from "./utils";
import { Packages } from "./workspace";
export async function restoreIncremental(targetDir: string) {
core.debug(`restoring incremental directory "${targetDir}"`);
let 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"))) || (await exists(path.join(dirName, ".rustc_info.json")));
try {
if (isNestedTarget) {
await restoreIncremental(dirName);
} else {
await restoreIncrementalProfile(dirName);
} restoreIncrementalProfile
} catch { }
}
}
}
async function restoreIncrementalProfile(dirName: string) {
core.debug(`restoring incremental profile directory "${dirName}"`);
const incrementalJson = path.join(dirName, "incremental-restore.json");
if (await exists(incrementalJson)) {
const contents = await fs.promises.readFile(incrementalJson, "utf8");
const { modifiedTimes } = JSON.parse(contents);
// Write the mtimes to all the files in the profile directory
for (const fileName of Object.keys(modifiedTimes)) {
const mtime = modifiedTimes[fileName];
const filePath = path.join(dirName, fileName);
await fs.promises.utimes(filePath, new Date(mtime), new Date(mtime));
}
}
}