From 46958f1f16b1d83ae58cf081d9af162df3874877 Mon Sep 17 00:00:00 2001 From: abose Date: Thu, 20 Feb 2025 19:27:58 +0530 Subject: [PATCH 1/2] chore: add support to read text files larger than 16MB --- src/extensibility/ExtensionManager.js | 2 +- src/file/FileUtils.js | 30 ++++++++++++------- src/filesystem/File.js | 11 +++++-- .../impls/appshell/AppshellFileSystem.js | 4 +-- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/extensibility/ExtensionManager.js b/src/extensibility/ExtensionManager.js index 43a1016819..19e1b99655 100644 --- a/src/extensibility/ExtensionManager.js +++ b/src/extensibility/ExtensionManager.js @@ -70,7 +70,7 @@ define(function (require, exports, module) { // never rejects return new Promise((resolve) => { const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH); - FileUtils.readAsText(registryFile) + FileUtils.readAsText(registryFile, true, {ignoreFileSizeLimits: true}) .done(resolve) .fail(function (err) { console.error(`Registry cache not found ${REGISTRY_CACHE_PATH}`, err); diff --git a/src/file/FileUtils.js b/src/file/FileUtils.js index 29220ebd36..80be0c49b0 100644 --- a/src/file/FileUtils.js +++ b/src/file/FileUtils.js @@ -70,22 +70,32 @@ define(function (require, exports, module) { * Asynchronously reads a file as UTF-8 encoded text. * @param {!File} file File to read * @param {boolean?} bypassCache - an optional argument, if specified will read from disc instead of using cache. + * @param {object} [options] + * @param {boolean} [options.ignoreFileSizeLimits]. Will read larger files than 16MB limit. will bypassCache + + * won't cache if enabled. + * @param {boolean} [options.doNotCache] will not cache if enabled. Auto-enabled if ignoreFileSizeLimits = true * @return {$.Promise} a jQuery promise that will be resolved with the * file's text content plus its timestamp, or rejected with a FileSystemError string * constant if the file can not be read. */ - function readAsText(file, bypassCache) { + function readAsText(file, bypassCache, options = {}) { const result = new $.Deferred(); + let doNotCache = options.doNotCache; + if(options.ignoreFileSizeLimits) { + bypassCache = true; + doNotCache = true; + } - file.read({bypassCache: bypassCache}, function (err, data, _encoding, stat) { - if(!err && typeof data !== "string"){ - result.reject(FileSystemError.UNSUPPORTED_ENCODING); - } else if (!err) { - result.resolve(data, stat.mtime); - } else { - result.reject(err); - } - }); + file.read({ bypassCache: bypassCache, ignoreFileSizeLimits: options.ignoreFileSizeLimits, doNotCache}, + function (err, data, _encoding, stat) { + if(!err && typeof data !== "string"){ + result.reject(FileSystemError.UNSUPPORTED_ENCODING); + } else if (!err) { + result.resolve(data, stat.mtime); + } else { + result.reject(err); + } + }); return result.promise(); } diff --git a/src/filesystem/File.js b/src/filesystem/File.js index 74020600f6..d4d7f882e8 100644 --- a/src/filesystem/File.js +++ b/src/filesystem/File.js @@ -94,8 +94,12 @@ define(function (require, exports, module) { /** * Read a file. * - * @param {Object=} options properties \{encoding: 'one of format supported here: - * https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding'} + * @param {Object} options + * @param {string} [options.encoding] 'one of format supported here: + * https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/encoding' + * @param {boolean} [options.ignoreFileSizeLimits] by default max file size that can be read is 16MB. + * @param {boolean} [options.doNotCache] will not cache if enabled. Auto-enabled if ignoreFileSizeLimits = true + * * @param {function (?string, string=, FileSystemStats=)} callback Callback that is passed the * FileSystemError string or the file's contents and its stats. */ @@ -106,6 +110,9 @@ define(function (require, exports, module) { options.encoding = this._encoding; } options.encoding = options.encoding || this._encoding || "utf8"; + if(options.ignoreFileSizeLimits) { + options.doNotCache = true; + } // We don't need to check isWatched() here because contents are only saved // for watched files. Note that we need to explicitly test this._contents diff --git a/src/filesystem/impls/appshell/AppshellFileSystem.js b/src/filesystem/impls/appshell/AppshellFileSystem.js index 00732d10fb..f86f656cfe 100644 --- a/src/filesystem/impls/appshell/AppshellFileSystem.js +++ b/src/filesystem/impls/appshell/AppshellFileSystem.js @@ -551,7 +551,7 @@ define(function (require, exports, module) { * If both calls fail, the error from the read call is passed back. * * @param {string} path - * @param {{encoding: string=, stat: FileSystemStats=}} options + * @param {{encoding: string=, stat: FileSystemStats=, ignoreFileSizeLimits: boolean=}} options * @param {function(?string, string=, FileSystemStats=)} callback */ function readFile(path, options, callback) { @@ -562,7 +562,7 @@ define(function (require, exports, module) { // callback to be executed when the call to stat completes // or immediately if a stat object was passed as an argument function doReadFile(stat) { - if (stat.size > (FileUtils.MAX_FILE_SIZE)) { + if (!options.ignoreFileSizeLimits && stat.size > (FileUtils.MAX_FILE_SIZE)) { callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE); } else { appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) { From 74ec12286114ce4b01f8e0ff9248bc49435778a2 Mon Sep 17 00:00:00 2001 From: abose Date: Thu, 20 Feb 2025 20:00:57 +0530 Subject: [PATCH 2/2] fix: extension registry not getting updatedgit add .! --- src/extensibility/ExtensionManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensibility/ExtensionManager.js b/src/extensibility/ExtensionManager.js index 19e1b99655..70953fa292 100644 --- a/src/extensibility/ExtensionManager.js +++ b/src/extensibility/ExtensionManager.js @@ -70,7 +70,7 @@ define(function (require, exports, module) { // never rejects return new Promise((resolve) => { const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH); - FileUtils.readAsText(registryFile, true, {ignoreFileSizeLimits: true}) + FileUtils.readAsText(registryFile, true) .done(resolve) .fail(function (err) { console.error(`Registry cache not found ${REGISTRY_CACHE_PATH}`, err); @@ -83,7 +83,7 @@ define(function (require, exports, module) { // never rejects return new Promise((resolve) => { const registryFile = FileSystem.getFileForPath(REGISTRY_CACHE_PATH); - FileUtils.writeText(registryFile, registryFileText) + FileUtils.writeText(registryFile, registryFileText, true) .done(resolve) .fail(function (err) { logger.reportError(err, `Registry cache write error ${REGISTRY_CACHE_PATH}`);