Skip to content

Commit

Permalink
Fixed the 'VirtualFileSystem' unserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 30, 2017
1 parent 7bc8928 commit d43f5c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
30 changes: 14 additions & 16 deletions lib/manager/v2/instances/VirtualFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 15 additions & 16 deletions src/manager/v2/instances/VirtualFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -125,7 +123,8 @@ export class VirtualSerializer implements FileSystemSerializer
unserialize(serializedData : any, callback : ReturnCallback<FileSystem>) : void
{
const fs = new VirtualFileSystem();
fs.resources = serializedData;
for(const path in serializedData)
fs.resources[path] = new _VirtualFileSystemResource(serializedData[path]);
callback(null, fs);
}
}
Expand Down

0 comments on commit d43f5c9

Please sign in to comment.