Skip to content

Commit

Permalink
Modified the 'FileSystem' class and the serialization method to skip …
Browse files Browse the repository at this point in the history
…allow non-serializable file system (skip the serialization of a fs if 'fs.serializer()' returns null/undefined)
  • Loading branch information
AdrienCastex committed Jul 2, 2017
1 parent 218d907 commit 43acf3f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/manager/v2/fileSystem/FileSystem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion lib/manager/v2/fileSystem/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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;
}());
Expand Down
2 changes: 2 additions & 0 deletions lib/manager/v2/fileSystem/Serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
14 changes: 13 additions & 1 deletion src/manager/v2/fileSystem/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -1036,7 +1044,11 @@ export abstract class FileSystem implements ISerializableFileSystem

serialize(callback : ReturnCallback<any>) : void
{
this.serializer().serialize(this, callback);
const serializer = this.serializer();
if(!serializer)
return callback();

serializer.serialize(this, callback);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/manager/v2/fileSystem/Serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down

0 comments on commit 43acf3f

Please sign in to comment.