3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-04-16 00:58:43 +00:00

workspace can only have one Cargo.lock

This commit is contained in:
Max Heller 2023-11-25 10:22:02 -05:00
parent 542fe36d5b
commit 1b681b21ae
No known key found for this signature in database
GPG key ID: 4C0F60F44836C137
5 changed files with 41 additions and 43 deletions

28
dist/restore/index.js vendored
View file

@ -86960,6 +86960,7 @@ var cache_lib_cache = __nccwpck_require__(7799);
function reportError(e) { function reportError(e) {
const { commandFailed } = e; const { commandFailed } = e;
if (commandFailed) { if (commandFailed) {
@ -87007,6 +87008,15 @@ function getCacheProvider() {
cache: cache, cache: cache,
}; };
} }
async function utils_exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/workspace.ts ;// CONCATENATED MODULE: ./src/workspace.ts
@ -87199,10 +87209,8 @@ class CacheConfig {
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
} }
const cargo_locks = sort_and_uniq(workspaceMembers const cargo_lock = external_path_default().join(workspace.root, "Cargo.lock");
.map(member => external_path_default().join(member.path, "Cargo.lock")) if (await utils_exists(cargo_lock)) {
.filter((external_fs_default()).existsSync));
for (const cargo_lock of cargo_locks) {
try { try {
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
const parsed = parse(content); const parsed = parse(content);
@ -87365,6 +87373,7 @@ function sort_and_uniq(a) {
async function cleanTargetDir(targetDir, packages, checkTimestamp = false) { async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
lib_core.debug(`cleaning target directory "${targetDir}"`); lib_core.debug(`cleaning target directory "${targetDir}"`);
// remove all *files* from the profile directory // remove all *files* from the profile directory
@ -87373,7 +87382,7 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
if (dirent.isDirectory()) { if (dirent.isDirectory()) {
let dirName = external_path_default().join(dir.path, dirent.name); let dirName = external_path_default().join(dir.path, dirent.name);
// is it a profile dir, or a nested target dir? // is it a profile dir, or a nested target dir?
let isNestedTarget = (await exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await exists(external_path_default().join(dirName, ".rustc_info.json"))); let isNestedTarget = (await utils_exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await utils_exists(external_path_default().join(dirName, ".rustc_info.json")));
try { try {
if (isNestedTarget) { if (isNestedTarget) {
await cleanTargetDir(dirName, packages, checkTimestamp); await cleanTargetDir(dirName, packages, checkTimestamp);
@ -87646,15 +87655,6 @@ async function rmRF(dirName) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/restore.ts ;// CONCATENATED MODULE: ./src/restore.ts

26
dist/save/index.js vendored
View file

@ -86960,6 +86960,7 @@ var cache_lib_cache = __nccwpck_require__(7799);
function reportError(e) { function reportError(e) {
const { commandFailed } = e; const { commandFailed } = e;
if (commandFailed) { if (commandFailed) {
@ -87007,6 +87008,15 @@ function getCacheProvider() {
cache: cache, cache: cache,
}; };
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/workspace.ts ;// CONCATENATED MODULE: ./src/workspace.ts
@ -87199,10 +87209,8 @@ class CacheConfig {
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
} }
const cargo_locks = sort_and_uniq(workspaceMembers const cargo_lock = external_path_default().join(workspace.root, "Cargo.lock");
.map(member => external_path_default().join(member.path, "Cargo.lock")) if (await exists(cargo_lock)) {
.filter((external_fs_default()).existsSync));
for (const cargo_lock of cargo_locks) {
try { try {
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
const parsed = parse(content); const parsed = parse(content);
@ -87365,6 +87373,7 @@ function sort_and_uniq(a) {
async function cleanTargetDir(targetDir, packages, checkTimestamp = false) { async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
core.debug(`cleaning target directory "${targetDir}"`); core.debug(`cleaning target directory "${targetDir}"`);
// remove all *files* from the profile directory // remove all *files* from the profile directory
@ -87646,15 +87655,6 @@ async function rmRF(dirName) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/save.ts ;// CONCATENATED MODULE: ./src/save.ts

View file

@ -4,6 +4,7 @@ import fs from "fs";
import path from "path"; import path from "path";
import { CARGO_HOME } from "./config"; import { CARGO_HOME } from "./config";
import { exists } from "./utils";
import { Packages } from "./workspace"; import { Packages } from "./workspace";
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) { export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
@ -308,12 +309,3 @@ async function rmRF(dirName: string) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}

View file

@ -8,7 +8,7 @@ import path from "path";
import * as toml from "smol-toml"; import * as toml from "smol-toml";
import { getCargoBins } from "./cleanup"; import { getCargoBins } from "./cleanup";
import { CacheProvider, getCmdOutput } from "./utils"; import { CacheProvider, exists, getCmdOutput } from "./utils";
import { Workspace } from "./workspace"; import { Workspace } from "./workspace";
const HOME = os.homedir(); const HOME = os.homedir();
@ -191,12 +191,8 @@ export class CacheConfig {
} }
} }
const cargo_locks = sort_and_uniq(workspaceMembers const cargo_lock = path.join(workspace.root, "Cargo.lock");
.map(member => path.join(member.path, "Cargo.lock")) if (await exists(cargo_lock)) {
.filter(fs.existsSync)
);
for (const cargo_lock of cargo_locks) {
try { try {
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" }); const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content); const parsed = toml.parse(content);

View file

@ -2,6 +2,7 @@ import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as buildjetCache from "@actions/buildjet-cache"; import * as buildjetCache from "@actions/buildjet-cache";
import * as ghCache from "@actions/cache"; import * as ghCache from "@actions/cache";
import fs from "fs";
export function reportError(e: any) { export function reportError(e: any) {
const { commandFailed } = e; const { commandFailed } = e;
@ -61,3 +62,12 @@ export function getCacheProvider(): CacheProvider {
cache: cache, cache: cache,
}; };
} }
export async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}