diff --git a/lib/manager/v2/instances/VirtualFileSystem.js b/lib/manager/v2/instances/VirtualFileSystem.js index 4bc83456..0e32186c 100644 --- a/lib/manager/v2/instances/VirtualFileSystem.js +++ b/lib/manager/v2/instances/VirtualFileSystem.js @@ -16,25 +16,22 @@ var Errors_1 = require("../../../Errors"); var Path_1 = require("../Path"); var _VirtualFileSystemResource = (function () { function _VirtualFileSystemResource(data) { + var rs; if (data.constructor === export_1.ResourceType) { - this.lastModifiedDate = Date.now(); - this.creationDate = Date.now(); - this.content = []; - this.props = new export_1.LocalPropertyManager(); - this.locks = new export_1.LocalLockManager(); - this.type = data; - this.size = 0; + rs = { + type: data + }; } else { - var rs = data; - this.lastModifiedDate = rs.lastModifiedDate; - this.creationDate = rs.creationDate; - this.content = rs.content; - this.props = rs.props; - this.locks = rs.locks; - this.size = rs.size; - this.type = rs.type; + rs = data; } + this.lastModifiedDate = rs.lastModifiedDate ? rs.lastModifiedDate : Date.now(); + this.creationDate = rs.creationDate ? rs.creationDate : Date.now(); + this.content = rs.content ? rs.content.map(function (o) { return new Buffer(o); }) : []; + this.props = rs.props ? Object.defineProperties(new export_1.LocalPropertyManager(), rs.props) : new export_1.LocalPropertyManager(); + this.locks = rs.locks ? Object.defineProperties(new export_1.LocalLockManager(), rs.locks) : new export_1.LocalLockManager(); + this.size = rs.size ? rs.size : 0; + this.type = rs.type ? rs.type : export_1.ResourceType.File; } _VirtualFileSystemResource.updateLastModified = function (r) { r.lastModifiedDate = Date.now(); @@ -89,7 +86,8 @@ var VirtualSerializer = (function () { }; VirtualSerializer.prototype.unserialize = function (serializedData, callback) { var fs = new VirtualFileSystem(); - fs.resources = serializedData; + for (var path in serializedData) + fs.resources[path] = new _VirtualFileSystemResource(serializedData[path]); callback(null, fs); }; return VirtualSerializer; diff --git a/src/manager/v2/instances/VirtualFileSystem.ts b/src/manager/v2/instances/VirtualFileSystem.ts index 9b58c378..232ecd63 100644 --- a/src/manager/v2/instances/VirtualFileSystem.ts +++ b/src/manager/v2/instances/VirtualFileSystem.ts @@ -38,27 +38,25 @@ export class _VirtualFileSystemResource constructor(data : _VirtualFileSystemResource | ResourceType) { + let rs : _VirtualFileSystemResource; if(data.constructor === ResourceType) { - this.lastModifiedDate = Date.now(); - this.creationDate = Date.now(); - this.content = []; - this.props = new LocalPropertyManager(); - this.locks = new LocalLockManager(); - this.type = data as ResourceType; - this.size = 0; + rs = { + type: data as ResourceType + } as _VirtualFileSystemResource; } else { - const rs = data as _VirtualFileSystemResource; - this.lastModifiedDate = rs.lastModifiedDate; - this.creationDate = rs.creationDate; - this.content = rs.content; - this.props = rs.props; - this.locks = rs.locks; - this.size = rs.size; - this.type = rs.type; + rs = data as _VirtualFileSystemResource; } + + this.lastModifiedDate = rs.lastModifiedDate ? rs.lastModifiedDate : Date.now(); + this.creationDate = rs.creationDate ? rs.creationDate : Date.now(); + this.content = rs.content ? rs.content.map((o) => new Buffer(o)) : []; + this.props = rs.props ? Object.defineProperties(new LocalPropertyManager(), rs.props as any) : new LocalPropertyManager(); + this.locks = rs.locks ? Object.defineProperties(new LocalLockManager(), rs.locks as any) : new LocalLockManager(); + this.size = rs.size ? rs.size : 0; + this.type = rs.type ? rs.type : ResourceType.File; } static updateLastModified(r : _VirtualFileSystemResource) @@ -125,7 +123,8 @@ export class VirtualSerializer implements FileSystemSerializer unserialize(serializedData : any, callback : ReturnCallback) : void { const fs = new VirtualFileSystem(); - fs.resources = serializedData; + for(const path in serializedData) + fs.resources[path] = new _VirtualFileSystemResource(serializedData[path]); callback(null, fs); } }