Skip to content

Commit

Permalink
Fixed the MOVE method + Fixed the PROPFIND method
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 29, 2017
1 parent f14cde3 commit 2c7a84c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
32 changes: 15 additions & 17 deletions lib/manager/v2/fileSystem/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ var FileSystem = (function () {
}, callback);
return;
}
StandardMethods_1.StandardMethods.standardMove(ctx, pathFrom, _this, pathTo, _this, callback);
StandardMethods_1.StandardMethods.standardMove(ctx, pathFrom, _this, pathTo, _this, overwrite, callback);
};
_this.fastExistCheckEx(ctx, pathFrom, callback, function () {
if (!overwrite)
Expand All @@ -291,23 +291,23 @@ var FileSystem = (function () {
_this.isLocked(ctx, pathTo, function (e, isLocked) {
if (e || isLocked)
return callback(e ? e : Errors_1.Errors.Locked);
if (_this._copy) {
var go_1 = function () {
var go = function () {
if (_this._copy) {
_this._copy(pathFrom, pathTo, {
context: ctx,
depth: depth,
overwrite: overwrite
}, callback);
};
_this.fastExistCheckEx(ctx, pathFrom, callback, function () {
if (!overwrite)
_this.fastExistCheckExReverse(ctx, pathTo, callback, go_1);
else
go_1();
});
}
else
return;
}
StandardMethods_1.StandardMethods.standardCopy(ctx, pathFrom, _this, pathTo, _this, overwrite, depth, callback);
};
_this.fastExistCheckEx(ctx, pathFrom, callback, function () {
if (!overwrite)
_this.fastExistCheckExReverse(ctx, pathTo, callback, go);
else
go();
});
});
});
});
Expand Down Expand Up @@ -484,12 +484,12 @@ var FileSystem = (function () {
var buffIsLocked = new BufferedIsLocked(_this, ctx, pPath);
var fs = _this;
callback(null, {
setProperty: function (name, value, callback) {
setProperty: function (name, value, attributes, callback) {
issuePrivilegeCheck(fs, ctx, pPath, 'canWriteProperties', callback, function () {
buffIsLocked.isLocked(function (e, isLocked) {
if (e || isLocked)
return callback(e ? e : Errors_1.Errors.Locked);
pm.setProperty(name, value, callback);
pm.setProperty(name, value, attributes, callback);
});
});
},
Expand Down Expand Up @@ -647,9 +647,7 @@ var FileSystem = (function () {
var tree = _callback ? _tree : _rootPath;
var rootPath = _callback ? new Path_1.Path(_rootPath) : new Path_1.Path('/');
if (tree.constructor === CommonTypes_1.ResourceType) {
issuePrivilegeCheck(this, ctx, rootPath, 'canWrite', callback, function () {
_this.create(ctx, rootPath, tree, callback);
});
this.create(ctx, rootPath, tree, callback);
}
else {
new Workflow_1.Workflow()
Expand Down
13 changes: 11 additions & 2 deletions lib/server/v2/commands/Move.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
var WebDAVRequest_1 = require("../WebDAVRequest");
var StandardMethods_1 = require("../../../manager/v2/fileSystem/StandardMethods");
var Path_1 = require("../../../manager/v2/Path");
var Errors_1 = require("../../../Errors");
function execute(ctx, methodName, privilegeName, callback) {
ctx.noBodyExpected(function () {
ctx.getResource(function (e, r) {
Expand All @@ -20,13 +21,21 @@ function execute(ctx, methodName, privilegeName, callback) {
destination = destination.substring(destination.indexOf('/')); // Remove the hostname + port
}
destination = new Path_1.Path(destination);
if (destination.toString() === ctx.requested.path.toString()) {
var sDest = destination.toString(true);
var sSource = ctx.requested.path.toString(true);
if (sDest === sSource) {
ctx.setCode(WebDAVRequest_1.HTTPCodes.Forbidden);
return callback();
}
if (sDest.indexOf(sSource) === 0) {
ctx.setCode(WebDAVRequest_1.HTTPCodes.BadGateway);
return callback();
}
var cb = function (e, overwritten) {
if (e) {
if (!ctx.setCodeFromError(e))
if (e === Errors_1.Errors.ResourceAlreadyExists)
ctx.setCode(WebDAVRequest_1.HTTPCodes.PreconditionFailed);
else if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
}
else if (overwritten)
Expand Down
10 changes: 7 additions & 3 deletions lib/server/v2/commands/Propfind.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var default_1 = (function () {
});
resource.type(function (e, type) { return process.nextTick(function () {
if (e) {
ctx.setCode(e === Errors_1.Errors.ResourceNotFound ? WebDAVRequest_1.HTTPCodes.NotFound : WebDAVRequest_1.HTTPCodes.InternalServerError);
if (!ctx.setCodeFromError(e))
ctx.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError);
return callback();
}
if (!type.isDirectory || ctx.headers.depth === 0) {
Expand Down Expand Up @@ -307,8 +308,11 @@ var default_1 = (function () {
for (var name_1 in properties) {
if (reqBody.mustDisplay(name_1)) {
var tag = prop.ele(name_1);
if (reqBody.mustDisplayValue(name_1))
tag.add(properties[name_1]);
if (reqBody.mustDisplayValue(name_1)) {
var property = properties[name_1];
tag.attributes = property.attributes;
tag.add(property.value);
}
}
}
nbOut();
Expand Down
37 changes: 18 additions & 19 deletions src/manager/v2/fileSystem/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Workflow } from '../../../helper/Workflow'
import { Errors } from '../../../Errors'
import { Lock } from '../../../resource/lock/Lock'
import { Path } from '../Path'
import { ResourceType, SimpleCallback, Return2Callback, ReturnCallback, SubTree, OpenWriteStreamMode, ResourcePropertyValue } from './CommonTypes'
import { ResourceType, SimpleCallback, Return2Callback, ReturnCallback, SubTree, OpenWriteStreamMode, ResourcePropertyValue, PropertyAttributes } from './CommonTypes'
import { ContextualFileSystem } from './ContextualFileSystem'
import { ILockManager } from './LockManager'
import { IPropertyManager, PropertyBag } from './PropertyManager'
Expand Down Expand Up @@ -359,7 +359,7 @@ export abstract class FileSystem implements ISerializableFileSystem
return;
}

StandardMethods.standardMove(ctx, pathFrom, this, pathTo, this, callback);
StandardMethods.standardMove(ctx, pathFrom, this, pathTo, this, overwrite, callback);
}

this.fastExistCheckEx(ctx, pathFrom, callback, () => {
Expand Down Expand Up @@ -393,26 +393,27 @@ export abstract class FileSystem implements ISerializableFileSystem
if(e || isLocked)
return callback(e ? e : Errors.Locked);

if(this._copy)
const go = () =>
{
const go = () =>
if(this._copy)
{
this._copy(pathFrom, pathTo, {
context: ctx,
depth,
overwrite
}, callback);
return;
}

this.fastExistCheckEx(ctx, pathFrom, callback, () => {
if(!overwrite)
this.fastExistCheckExReverse(ctx, pathTo, callback, go);
else
go();
})
}
else
StandardMethods.standardCopy(ctx, pathFrom, this, pathTo, this, overwrite, depth, callback);
}

this.fastExistCheckEx(ctx, pathFrom, callback, () => {
if(!overwrite)
this.fastExistCheckExReverse(ctx, pathTo, callback, go);
else
go();
})
})
})
})
Expand Down Expand Up @@ -641,18 +642,18 @@ export abstract class FileSystem implements ISerializableFileSystem
const fs = this;

callback(null, {
setProperty(name : string, value : ResourcePropertyValue, callback : SimpleCallback) : void
setProperty(name : string, value : ResourcePropertyValue, attributes : PropertyAttributes, callback : SimpleCallback) : void
{
issuePrivilegeCheck(fs, ctx, pPath, 'canWriteProperties', callback, () => {
buffIsLocked.isLocked((e, isLocked) => {
if(e || isLocked)
return callback(e ? e : Errors.Locked);

pm.setProperty(name, value, callback);
pm.setProperty(name, value, attributes, callback);
})
})
},
getProperty(name : string, callback : ReturnCallback<ResourcePropertyValue>) : void
getProperty(name : string, callback : Return2Callback<ResourcePropertyValue, PropertyAttributes>) : void
{
issuePrivilegeCheck(fs, ctx, pPath, 'canReadProperties', callback, () => {
pm.getProperty(name, callback);
Expand Down Expand Up @@ -848,9 +849,7 @@ export abstract class FileSystem implements ISerializableFileSystem

if(tree.constructor === ResourceType)
{
issuePrivilegeCheck(this, ctx, rootPath, 'canWrite', callback, () => {
this.create(ctx, rootPath, tree as ResourceType, callback);
})
this.create(ctx, rootPath, tree as ResourceType, callback);
}
else
{
Expand All @@ -859,7 +858,7 @@ export abstract class FileSystem implements ISerializableFileSystem
const value = tree[name];
const childPath = rootPath.getChildPath(name);
if(value.constructor === ResourceType)
this.addSubTree(ctx, childPath, value, cb)
this.addSubTree(ctx, childPath, value as ResourceType, cb)
else
this.addSubTree(ctx, childPath, ResourceType.Directory, (e) => {
if(e)
Expand Down
15 changes: 12 additions & 3 deletions src/server/v2/commands/Move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,26 @@ export function execute(ctx : RequestContext, methodName : string, privilegeName
}
destination = new Path(destination);

if(destination.toString() === ctx.requested.path.toString())
const sDest = destination.toString(true);
const sSource = ctx.requested.path.toString(true);
if(sDest === sSource)
{
ctx.setCode(HTTPCodes.Forbidden);
return callback();
}
if(sDest.indexOf(sSource) === 0)
{
ctx.setCode(HTTPCodes.BadGateway);
return callback();
}

const cb = (e ?: Error, overwritten ?: boolean) =>
{
if(e)
{
if(!ctx.setCodeFromError(e))
if(e === Errors.ResourceAlreadyExists)
ctx.setCode(HTTPCodes.PreconditionFailed);
else if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
}
else if(overwritten)
Expand All @@ -49,7 +58,7 @@ export function execute(ctx : RequestContext, methodName : string, privilegeName

ctx.server.getFileSystem(destination, (destFs, destRootPath, destSubPath) => {
if(destFs !== r.fs)
{ // Copy
{ // Standard method
if(methodName === 'move')
StandardMethods.standardMove(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
else
Expand Down
9 changes: 7 additions & 2 deletions src/server/v2/commands/Propfind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export default class implements HTTPMethod
resource.type((e, type) => process.nextTick(() => {
if(e)
{
ctx.setCode(e === Errors.ResourceNotFound ? HTTPCodes.NotFound : HTTPCodes.InternalServerError);
if(!ctx.setCodeFromError(e))
ctx.setCode(HTTPCodes.InternalServerError)
return callback();
}

Expand Down Expand Up @@ -496,7 +497,11 @@ export default class implements HTTPMethod
{
const tag = prop.ele(name);
if(reqBody.mustDisplayValue(name))
tag.add(properties[name]);
{
const property = properties[name];
tag.attributes = property.attributes;
tag.add(property.value);
}
}
}
nbOut();
Expand Down

0 comments on commit 2c7a84c

Please sign in to comment.