mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Don't attempt to sync files larger than 16MiB
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
ae96ae7d50
commit
2808565161
@ -26,7 +26,7 @@ import { FSWatcher, watch } from "chokidar";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import type stream from "stream";
|
||||
import { Disposer, ExtendedObservableMap, iter, Singleton, storedKubeConfigFolder } from "../../common/utils";
|
||||
import { bytesToUnits, Disposer, ExtendedObservableMap, iter, noop, Singleton, storedKubeConfigFolder } from "../../common/utils";
|
||||
import logger from "../logger";
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { loadConfigFromString, splitConfig } from "../../common/kube-helpers";
|
||||
@ -228,9 +228,18 @@ export function computeDiff(contents: string, source: RootSource, filePath: stri
|
||||
});
|
||||
}
|
||||
|
||||
function diffChangedConfig(filePath: string, source: RootSource): Disposer {
|
||||
const maxAllowedFileReadSize = 16 * 1024 * 1024; // 16 MiB
|
||||
|
||||
function diffChangedConfig(filePath: string, source: RootSource, stats: fs.Stats): Disposer {
|
||||
logger.debug(`${logPrefix} file changed`, { filePath });
|
||||
|
||||
if (stats.size >= maxAllowedFileReadSize) {
|
||||
logger.warn(`${logPrefix} skipping ${filePath}: size=${bytesToUnits(stats.size)} is larger than maxSize=${bytesToUnits(maxAllowedFileReadSize)}`);
|
||||
source.clear();
|
||||
|
||||
return noop;
|
||||
}
|
||||
|
||||
// TODO: replace with an AbortController with fs.readFile when we upgrade to Node 16 (after it comes out)
|
||||
const fileReader = fs.createReadStream(filePath, {
|
||||
mode: fs.constants.O_RDONLY,
|
||||
@ -294,7 +303,7 @@ function watchFileChanges(filePath: string): [IComputedValue<CatalogEntity[]>, D
|
||||
});
|
||||
|
||||
watcher
|
||||
.on("change", (childFilePath) => {
|
||||
.on("change", (childFilePath, stats) => {
|
||||
const cleanup = cleanupFns.get(childFilePath);
|
||||
|
||||
if (!cleanup) {
|
||||
@ -303,9 +312,9 @@ function watchFileChanges(filePath: string): [IComputedValue<CatalogEntity[]>, D
|
||||
}
|
||||
|
||||
cleanup();
|
||||
cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map)));
|
||||
cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map), stats));
|
||||
})
|
||||
.on("add", (childFilePath) => {
|
||||
.on("add", (childFilePath, stats) => {
|
||||
if (isFolderSync) {
|
||||
const fileName = path.basename(childFilePath);
|
||||
|
||||
@ -316,7 +325,7 @@ function watchFileChanges(filePath: string): [IComputedValue<CatalogEntity[]>, D
|
||||
}
|
||||
}
|
||||
|
||||
cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map)));
|
||||
cleanupFns.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrInsert(childFilePath, observable.map), stats));
|
||||
})
|
||||
.on("unlink", (childFilePath) => {
|
||||
cleanupFns.get(childFilePath)?.();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user