From 43acf3f4984637dc227a963ca837519354c20473 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sun, 2 Jul 2017 09:30:08 +0200 Subject: [PATCH] Modified the 'FileSystem' class and the serialization method to skip allow non-serializable file system (skip the serialization of a fs if 'fs.serializer()' returns null/undefined) --- lib/manager/v2/fileSystem/FileSystem.d.ts | 2 ++ lib/manager/v2/fileSystem/FileSystem.js | 11 ++++++++++- lib/manager/v2/fileSystem/Serialization.js | 2 ++ src/manager/v2/fileSystem/FileSystem.ts | 14 +++++++++++++- src/manager/v2/fileSystem/Serialization.ts | 3 +++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/manager/v2/fileSystem/FileSystem.d.ts b/lib/manager/v2/fileSystem/FileSystem.d.ts index 2186c2bc..e224a857 100644 --- a/lib/manager/v2/fileSystem/FileSystem.d.ts +++ b/lib/manager/v2/fileSystem/FileSystem.d.ts @@ -16,6 +16,8 @@ export declare abstract class FileSystem implements ISerializableFileSystem { private __serializer; constructor(serializer: FileSystemSerializer); serializer(): FileSystemSerializer; + setSerializer(serializer: FileSystemSerializer): void; + doNotSerialize(): void; contextualize(ctx: RequestContext): ContextualFileSystem; resource(ctx: RequestContext, path: Path): Resource; fastExistCheckEx(ctx: RequestContext, _path: Path | string, errorCallback: SimpleCallback, callback: () => void): void; diff --git a/lib/manager/v2/fileSystem/FileSystem.js b/lib/manager/v2/fileSystem/FileSystem.js index 1117145a..e294c0b0 100644 --- a/lib/manager/v2/fileSystem/FileSystem.js +++ b/lib/manager/v2/fileSystem/FileSystem.js @@ -38,6 +38,12 @@ var FileSystem = (function () { FileSystem.prototype.serializer = function () { return this.__serializer; }; + FileSystem.prototype.setSerializer = function (serializer) { + this.__serializer = serializer; + }; + FileSystem.prototype.doNotSerialize = function () { + this.__serializer = null; + }; FileSystem.prototype.contextualize = function (ctx) { return new ContextualFileSystem_1.ContextualFileSystem(this, ctx); }; @@ -780,7 +786,10 @@ var FileSystem = (function () { }); }; FileSystem.prototype.serialize = function (callback) { - this.serializer().serialize(this, callback); + var serializer = this.serializer(); + if (!serializer) + return callback(); + serializer.serialize(this, callback); }; return FileSystem; }()); diff --git a/lib/manager/v2/fileSystem/Serialization.js b/lib/manager/v2/fileSystem/Serialization.js index ce2a3913..66404434 100644 --- a/lib/manager/v2/fileSystem/Serialization.js +++ b/lib/manager/v2/fileSystem/Serialization.js @@ -8,6 +8,8 @@ function serialize(fileSystems, callback) { .each(Object.keys(fileSystems), function (path, cb) { var fs = fileSystems[path]; var serializer = fs.serializer(); + if (!serializer) + return cb(); // Skip serialization serializer.serialize(fs, function (e, data) { if (!e) result[path] = { diff --git a/src/manager/v2/fileSystem/FileSystem.ts b/src/manager/v2/fileSystem/FileSystem.ts index 8be06c60..98f36ac1 100644 --- a/src/manager/v2/fileSystem/FileSystem.ts +++ b/src/manager/v2/fileSystem/FileSystem.ts @@ -57,6 +57,14 @@ export abstract class FileSystem implements ISerializableFileSystem { return this.__serializer; } + setSerializer(serializer : FileSystemSerializer) + { + this.__serializer = serializer; + } + doNotSerialize() + { + this.__serializer = null; + } contextualize(ctx : RequestContext) : ContextualFileSystem { @@ -1036,7 +1044,11 @@ export abstract class FileSystem implements ISerializableFileSystem serialize(callback : ReturnCallback) : void { - this.serializer().serialize(this, callback); + const serializer = this.serializer(); + if(!serializer) + return callback(); + + serializer.serialize(this, callback); } } diff --git a/src/manager/v2/fileSystem/Serialization.ts b/src/manager/v2/fileSystem/Serialization.ts index ba2ce087..a19d85a9 100644 --- a/src/manager/v2/fileSystem/Serialization.ts +++ b/src/manager/v2/fileSystem/Serialization.ts @@ -44,6 +44,9 @@ export function serialize(fileSystems : UnserializedData, callback : ReturnCallb .each(Object.keys(fileSystems), (path, cb) => { const fs = fileSystems[path]; const serializer = fs.serializer(); + if(!serializer) + return cb(); // Skip serialization + serializer.serialize(fs, (e, data) => { if(!e) result[path] = {