@@ -61667,6 +61667,8 @@ class Workspace {
6166761667
6166861668
6166961669
61670+ const HOME = external_os_default().homedir();
61671+ const config_CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
6167061672const STATE_LOCKFILE_HASH = "RUST_CACHE_LOCKFILE_HASH";
6167161673const STATE_LOCKFILES = "RUST_CACHE_LOCKFILES";
6167261674const config_STATE_BINS = "RUST_CACHE_BINS";
@@ -61679,14 +61681,6 @@ class CacheConfig {
6167961681 this.cacheKey = "";
6168061682 /** The secondary (restore) key that only contains the prefix and environment */
6168161683 this.restoreKey = "";
61682- /** The `~/.cargo` directory */
61683- this.cargoHome = "";
61684- /** The cargo registry index directory */
61685- this.cargoIndex = "";
61686- /** The cargo registry cache directory */
61687- this.cargoCache = "";
61688- /** The cargo git checkouts directory */
61689- this.cargoGit = "";
6169061684 /** The workspace configurations */
6169161685 this.workspaces = [];
6169261686 /** The prefix portion of the cache key */
@@ -61782,14 +61776,8 @@ class CacheConfig {
6178261776 self.keyFiles = keyFiles;
6178361777 key += `-${lockHash}`;
6178461778 self.cacheKey = key;
61785- // Constructs some generic paths, workspace config and paths to restore:
61779+ // Constructs the workspace config and paths to restore:
6178661780 // The workspaces are given using a `$workspace -> $target` syntax.
61787- const home = external_os_default().homedir();
61788- const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo");
61789- self.cargoHome = cargoHome;
61790- self.cargoIndex = external_path_default().join(cargoHome, "registry/index");
61791- self.cargoCache = external_path_default().join(cargoHome, "registry/cache");
61792- self.cargoGit = external_path_default().join(cargoHome, "git");
6179361781 const workspaces = [];
6179461782 const workspacesInput = lib_core.getInput("workspaces") || ".";
6179561783 for (const workspace of workspacesInput.trim().split("\n")) {
@@ -61799,15 +61787,7 @@ class CacheConfig {
6179961787 workspaces.push(new Workspace(root, target));
6180061788 }
6180161789 self.workspaces = workspaces;
61802- self.cachePaths = [
61803- external_path_default().join(cargoHome, "bin"),
61804- external_path_default().join(cargoHome, ".crates2.json"),
61805- external_path_default().join(cargoHome, ".crates.toml"),
61806- self.cargoIndex,
61807- self.cargoCache,
61808- self.cargoGit,
61809- ...workspaces.map((ws) => ws.target),
61810- ];
61790+ self.cachePaths = [config_CARGO_HOME, ...workspaces.map((ws) => ws.target)];
6181161791 return self;
6181261792 }
6181361793 printInfo() {
@@ -61837,19 +61817,6 @@ class CacheConfig {
6183761817 }
6183861818 lib_core.endGroup();
6183961819 }
61840- async getCargoBins() {
61841- const bins = new Set();
61842- try {
61843- const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(this.cargoHome, ".crates2.json"), "utf8"));
61844- for (const pkg of Object.values(installs)) {
61845- for (const bin of pkg.bins) {
61846- bins.add(bin);
61847- }
61848- }
61849- }
61850- catch { }
61851- return bins;
61852- }
6185361820}
6185461821async function getRustVersion() {
6185561822 const stdout = await getCmdOutput("rustc", ["-vV"]);
@@ -61890,7 +61857,6 @@ async function cleanTargetDir(targetDir, packages) {
6189061857 await rm(dir.path, dirent);
6189161858 }
6189261859 }
61893- await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json"));
6189461860}
6189561861async function cleanProfileTarget(profileDir, packages) {
6189661862 await lib_io.rmRF(external_path_default().join(profileDir, "examples"));
@@ -61916,32 +61882,67 @@ async function cleanProfileTarget(profileDir, packages) {
6191661882 }));
6191761883 await rmExcept(external_path_default().join(profileDir, "deps"), keepDeps);
6191861884}
61919- async function cleanBin(config) {
61920- const bins = await config.getCargoBins();
61885+ async function getCargoBins() {
61886+ const bins = new Set();
61887+ try {
61888+ const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(config_CARGO_HOME, ".crates2.json"), "utf8"));
61889+ for (const pkg of Object.values(installs)) {
61890+ for (const bin of pkg.bins) {
61891+ bins.add(bin);
61892+ }
61893+ }
61894+ }
61895+ catch { }
61896+ return bins;
61897+ }
61898+ async function cleanBin() {
61899+ const bins = await getCargoBins();
6192161900 const oldBins = JSON.parse(core.getState(STATE_BINS));
6192261901 for (const bin of oldBins) {
6192361902 bins.delete(bin);
6192461903 }
61925- const dir = await fs.promises.opendir(path.join(config.cargoHome , "bin"));
61904+ const dir = await fs.promises.opendir(path.join(CARGO_HOME , "bin"));
6192661905 for await (const dirent of dir) {
6192761906 if (dirent.isFile() && !bins.has(dirent.name)) {
6192861907 await rm(dir.path, dirent);
6192961908 }
6193061909 }
6193161910}
61932- async function cleanRegistry(config, registryName, packages) {
61933- await io.rmRF(path.join(config.cargoIndex, registryName, ".cache"));
61911+ async function cleanRegistry(packages) {
61912+ // `.cargo/registry/src`
61913+ const srcDir = path.join(CARGO_HOME, "registry", "src");
61914+ await io.rmRF(srcDir);
61915+ // `.cargo/registry/index`
61916+ const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
61917+ for await (const dirent of indexDir) {
61918+ if (dirent.isDirectory()) {
61919+ // eg `.cargo/registry/index/github.zerozr99.workers.dev-1ecc6299db9ec823`
61920+ // or `.cargo/registry/index/index.crates.io-e139d0d48fed7772`
61921+ const dir = await fs.promises.opendir(path.join(indexDir.path, dirent.name));
61922+ // TODO: check for `.git` etc, for now we just always remove the `.cache`
61923+ // and leave other stuff untouched.
61924+ await io.rmRF(path.join(dir.path, ".cache"));
61925+ }
61926+ }
6193461927 const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
61935- const dir = await fs.promises.opendir(path.join(config.cargoCache, registryName));
61936- for await (const dirent of dir) {
61937- if (dirent.isFile() && !pkgSet.has(dirent.name)) {
61938- await rm(dir.path, dirent);
61928+ // `.cargo/registry/cache`
61929+ const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
61930+ for await (const dirent of cacheDir) {
61931+ if (dirent.isDirectory()) {
61932+ // eg `.cargo/registry/cache/github.zerozr99.workers.dev-1ecc6299db9ec823`
61933+ // or `.cargo/registry/cache/index.crates.io-e139d0d48fed7772`
61934+ const dir = await fs.promises.opendir(path.join(cacheDir.path, dirent.name));
61935+ for await (const dirent of dir) {
61936+ if (dirent.isFile() && !pkgSet.has(dirent.name)) {
61937+ await rm(dir.path, dirent);
61938+ }
61939+ }
6193961940 }
6194061941 }
6194161942}
61942- async function cleanGit(config, packages) {
61943- const coPath = path.join(config.cargoGit , "checkouts");
61944- const dbPath = path.join(config.cargoGit , "db");
61943+ async function cleanGit(packages) {
61944+ const coPath = path.join(CARGO_HOME, "git" , "checkouts");
61945+ const dbPath = path.join(CARGO_HOME, "git" , "db");
6194561946 const repos = new Map();
6194661947 for (const p of packages) {
6194761948 if (!p.path.startsWith(coPath)) {
@@ -62051,7 +62052,7 @@ async function run() {
6205162052 const config = await CacheConfig["new"]();
6205262053 config.printInfo();
6205362054 lib_core.info("");
62054- const bins = await config. getCargoBins();
62055+ const bins = await getCargoBins();
6205562056 lib_core.saveState(config_STATE_BINS, JSON.stringify([...bins]));
6205662057 lib_core.info(`... Restoring cache ...`);
6205762058 const key = config.cacheKey;
0 commit comments