Skip to content

Commit

Permalink
Implemented the 'Gateway' in the 'StandardResource' + Fixed the 'move…
Browse files Browse the repository at this point in the history
…To(...)' which was calling the the 'rename(...)' method even when the oldName and newName were equal
  • Loading branch information
AdrienCastex committed Jun 19, 2017
1 parent 083a5c0 commit 05fd08c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/resource/std/StandardResource.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference types="node" />
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType, ResourcePropertyValue } from '../IResource';
import { Readable, Writable } from 'stream';
import { FSManager } from '../../manager/FSManager';
import { FSManager, FSPath } from '../../manager/FSManager';
import { MethodCallArgs } from '../../server/MethodCallArgs';
import { LockKind } from '../lock/LockKind';
import { LockBag } from '../lock/LockBag';
import { Lock } from '../lock/Lock';
Expand Down Expand Up @@ -38,6 +39,7 @@ export declare abstract class StandardResource implements IResource {
abstract addChild(resource: IResource, callback: SimpleCallback): any;
abstract removeChild(resource: IResource, callback: SimpleCallback): any;
abstract getChildren(callback: ReturnCallback<IResource[]>): any;
gateway?(arg: MethodCallArgs, path: FSPath, callback: (error: Error, resource?: IResource) => void): any;
protected updateLastModified(): void;
protected removeFromParent(callback: SimpleCallback): void;
static standardRemoveFromParent(resource: IResource, callback: SimpleCallback): void;
Expand Down
11 changes: 9 additions & 2 deletions lib/resource/std/StandardResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ var StandardResource = (function () {
StandardResource.standardRemoveFromParent(resource, function (e) {
if (e) {
callback(e);
return;
}
else {
resource.webName(function (e, name) {
if (e || name === newName) {
parent.addChild(resource, function (e) {
callback(e);
});
return;
}
resource.rename(newName, function (e, oldName, newName) {
if (e)
callback(e);
Expand All @@ -138,7 +145,7 @@ var StandardResource = (function () {
callback(e);
});
});
}
});
});
});
});
Expand Down
19 changes: 16 additions & 3 deletions src/resource/std/StandardResource.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IResource, ReturnCallback, SimpleCallback, Return2Callback, ResourceType, ResourcePropertyValue } from '../IResource'
import { Readable, Writable } from 'stream'
import { FSManager, FSPath } from '../../manager/FSManager'
import { MethodCallArgs } from '../../server/MethodCallArgs'
import { LockScope } from '../lock/LockScope'
import { Workflow } from '../../helper/Workflow'
import { LockType } from '../lock/LockType'
Expand Down Expand Up @@ -131,6 +132,9 @@ export abstract class StandardResource implements IResource
abstract addChild(resource : IResource, callback : SimpleCallback)
abstract removeChild(resource : IResource, callback : SimpleCallback)
abstract getChildren(callback : ReturnCallback<IResource[]>)

// ****************************** Gateway ****************************** //
gateway?(arg : MethodCallArgs, path : FSPath, callback : (error : Error, resource ?: IResource) => void);

protected updateLastModified()
{
Expand Down Expand Up @@ -193,9 +197,18 @@ export abstract class StandardResource implements IResource
if(e)
{
callback(e);
return;
}
else
{

resource.webName((e, name) => {
if(e || name === newName)
{
parent.addChild(resource, (e) => {
callback(e);
})
return;
}

resource.rename(newName, (e, oldName, newName) => {
if(e)
callback(e);
Expand All @@ -204,7 +217,7 @@ export abstract class StandardResource implements IResource
callback(e);
})
})
}
})
})
})
})
Expand Down

0 comments on commit 05fd08c

Please sign in to comment.