3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-12-15 17:38:59 +00:00

Remove a few synchronous FS interactions

This commit is contained in:
Tamir Duberstein 2025-12-09 10:32:50 -05:00
parent 42c55942cf
commit 230365fb7a
No known key found for this signature in database
3 changed files with 41 additions and 19 deletions

18
dist/restore/index.js vendored
View file

@ -149504,6 +149504,8 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto
// EXTERNAL MODULE: external "fs/promises"
var promises_ = __nccwpck_require__(91943);
var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_);
;// CONCATENATED MODULE: external "stream/promises"
const external_stream_promises_namespaceObject = require("stream/promises");
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(70857);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
@ -150783,6 +150785,7 @@ class Workspace {
const HOME = external_os_default().homedir();
const config_CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG";
@ -150980,9 +150983,7 @@ class CacheConfig {
}
keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) {
hasher.update(chunk);
}
await (0,external_stream_promises_namespaceObject.pipeline)((0,external_fs_.createReadStream)(file), hasher);
}
keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles);
@ -151099,10 +151100,17 @@ async function globFiles(pattern) {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
// fs.statSync resolve the symbolic link and returns stat for the
// fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved
// file is actually a regular file.
return (await globber.glob()).filter((file) => external_fs_default().statSync(file).isFile());
const files = [];
for (const file of await globber.glob()) {
const stats = await promises_default().stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
}
function sort_and_uniq(a) {
return a

18
dist/save/index.js vendored
View file

@ -149506,6 +149506,8 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto
// EXTERNAL MODULE: external "fs/promises"
var promises_ = __nccwpck_require__(91943);
var promises_default = /*#__PURE__*/__nccwpck_require__.n(promises_);
;// CONCATENATED MODULE: external "stream/promises"
const external_stream_promises_namespaceObject = require("stream/promises");
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(70857);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
@ -150783,6 +150785,7 @@ class Workspace {
const HOME = external_os_default().homedir();
const CARGO_HOME = process.env.CARGO_HOME || external_path_default().join(HOME, ".cargo");
const STATE_CONFIG = "RUST_CACHE_CONFIG";
@ -150980,9 +150983,7 @@ class CacheConfig {
}
keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) {
for await (const chunk of external_fs_default().createReadStream(file)) {
hasher.update(chunk);
}
await (0,external_stream_promises_namespaceObject.pipeline)((0,external_fs_.createReadStream)(file), hasher);
}
keyFiles.push(...parsedKeyFiles);
self.keyFiles = sort_and_uniq(keyFiles);
@ -151099,10 +151100,17 @@ async function globFiles(pattern) {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
// fs.statSync resolve the symbolic link and returns stat for the
// fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved
// file is actually a regular file.
return (await globber.glob()).filter((file) => external_fs_default().statSync(file).isFile());
const files = [];
for (const file of await globber.glob()) {
const stats = await promises_default().stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
}
function sort_and_uniq(a) {
return a

View file

@ -1,8 +1,9 @@
import * as core from "@actions/core";
import * as glob from "@actions/glob";
import crypto from "crypto";
import fs from "fs";
import fs_promises from "fs/promises";
import fs from "fs/promises";
import { createReadStream } from "fs";
import { pipeline } from "stream/promises";
import os from "os";
import path from "path";
import * as toml from "smol-toml";
@ -178,7 +179,7 @@ export class CacheConfig {
for (const cargo_manifest of cargo_manifests) {
try {
const content = await fs_promises.readFile(cargo_manifest, { encoding: "utf8" });
const content = await fs.readFile(cargo_manifest, { encoding: "utf8" });
// Use any since TomlPrimitive is not exposed
const parsed = toml.parse(content) as { [key: string]: any };
@ -225,7 +226,7 @@ export class CacheConfig {
const cargo_lock = path.join(workspace.root, "Cargo.lock");
if (await exists(cargo_lock)) {
try {
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" });
const content = await fs.readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content);
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
@ -253,9 +254,7 @@ export class CacheConfig {
keyFiles = sort_and_uniq(keyFiles);
for (const file of keyFiles) {
for await (const chunk of fs.createReadStream(file)) {
hasher.update(chunk);
}
await pipeline(createReadStream(file), hasher);
}
keyFiles.push(...parsedKeyFiles);
@ -394,10 +393,17 @@ async function globFiles(pattern: string): Promise<string[]> {
const globber = await glob.create(pattern, {
followSymbolicLinks: false,
});
// fs.statSync resolve the symbolic link and returns stat for the
// fs.stat resolve the symbolic link and returns stat for the
// file it pointed to, so isFile would make sure the resolved
// file is actually a regular file.
return (await globber.glob()).filter((file) => fs.statSync(file).isFile());
const files = [];
for (const file of await globber.glob()) {
const stats = await fs.stat(file);
if (stats.isFile()) {
files.push(file);
}
}
return files;
}
function sort_and_uniq(a: string[]) {