Skip to content

Commit

Permalink
Fixed the 'VirtualFileSystem'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 29, 2017
1 parent 2c7a84c commit 9d3b03e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 35 deletions.
3 changes: 1 addition & 2 deletions lib/manager/v2/instances/VirtualFileSystem.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="node" />
import { LocalPropertyManager, LastModifiedDateInfo, FileSystemSerializer, OpenWriteStreamInfo, PropertyManagerInfo, OpenReadStreamInfo, IPropertyManager, LocalLockManager, CreationDateInfo, LockManagerInfo, SimpleCallback, ReturnCallback, ResourceType, ILockManager, ReadDirInfo, CreateInfo, DeleteInfo, FileSystem, SizeInfo, MoveInfo, TypeInfo } from '../fileSystem/export';
import { LocalPropertyManager, LastModifiedDateInfo, FileSystemSerializer, OpenWriteStreamInfo, PropertyManagerInfo, OpenReadStreamInfo, IPropertyManager, LocalLockManager, CreationDateInfo, LockManagerInfo, SimpleCallback, ReturnCallback, ResourceType, ILockManager, ReadDirInfo, CreateInfo, DeleteInfo, FileSystem, SizeInfo, TypeInfo } from '../fileSystem/export';
import { Readable, Writable } from 'stream';
import { RequestContext } from '../../../server/v2/RequestContext';
import { Path } from '../Path';
Expand Down Expand Up @@ -40,7 +40,6 @@ export declare class VirtualFileSystem extends FileSystem {
protected _delete(path: Path, ctx: DeleteInfo, callback: SimpleCallback): void;
protected _openWriteStream(path: Path, ctx: OpenWriteStreamInfo, callback: ReturnCallback<Writable>): void;
protected _openReadStream(path: Path, ctx: OpenReadStreamInfo, callback: ReturnCallback<Readable>): void;
protected _move(pathFrom: Path, pathTo: Path, ctx: MoveInfo, callback: ReturnCallback<boolean>): void;
protected _size(path: Path, ctx: SizeInfo, callback: ReturnCallback<number>): void;
protected _lockManager(path: Path, ctx: LockManagerInfo, callback: ReturnCallback<ILockManager>): void;
protected _propertyManager(path: Path, ctx: PropertyManagerInfo, callback: ReturnCallback<IPropertyManager>): void;
Expand Down
16 changes: 2 additions & 14 deletions lib/manager/v2/instances/VirtualFileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ var VirtualFileSystem = (function (_super) {
callback();
};
VirtualFileSystem.prototype._delete = function (path, ctx, callback) {
var sPath = path.toString();
var sPath = path.toString(true);
for (var path_1 in this.resources)
if (path_1.indexOf(sPath) === 0)
delete this.resources[path_1];
delete this.resources[path.toString()];
callback();
};
VirtualFileSystem.prototype._openWriteStream = function (path, ctx, callback) {
Expand All @@ -137,19 +138,6 @@ var VirtualFileSystem = (function (_super) {
return callback(Errors_1.Errors.ResourceNotFound);
callback(null, new VirtualFileReadable(resource.content));
};
VirtualFileSystem.prototype._move = function (pathFrom, pathTo, ctx, callback) {
var from = pathFrom.toString();
var to = pathTo.toString();
var existed = !!this.resources[to];
var fromExists = !!this.resources[from];
if (!fromExists)
return callback(Errors_1.Errors.ResourceNotFound);
if (existed && !ctx.overwrite)
return callback(Errors_1.Errors.ResourceAlreadyExists);
this.resources[to] = this.resources[from];
delete this.resources[from];
callback(null, existed);
};
VirtualFileSystem.prototype._size = function (path, ctx, callback) {
var resource = this.resources[path.toString()];
if (!resource)
Expand Down
21 changes: 2 additions & 19 deletions src/manager/v2/instances/VirtualFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ export class VirtualFileSystem extends FileSystem

protected _delete(path : Path, ctx : DeleteInfo, callback : SimpleCallback) : void
{
const sPath = path.toString();
const sPath = path.toString(true);
for(const path in this.resources)
if(path.indexOf(sPath) === 0)
delete this.resources[path];
delete this.resources[path.toString()];

callback();
}
Expand Down Expand Up @@ -191,24 +192,6 @@ export class VirtualFileSystem extends FileSystem
callback(null, new VirtualFileReadable(resource.content));
}

protected _move(pathFrom : Path, pathTo : Path, ctx : MoveInfo, callback : ReturnCallback<boolean>) : void
{
const from = pathFrom.toString();
const to = pathTo.toString();
const existed = !!this.resources[to];
const fromExists = !!this.resources[from];

if(!fromExists)
return callback(Errors.ResourceNotFound);
if(existed && !ctx.overwrite)
return callback(Errors.ResourceAlreadyExists);

this.resources[to] = this.resources[from];
delete this.resources[from];

callback(null, existed);
}

protected _size(path : Path, ctx : SizeInfo, callback : ReturnCallback<number>) : void
{
const resource = this.resources[path.toString()];
Expand Down

0 comments on commit 9d3b03e

Please sign in to comment.