diff --git a/lib/manager/v2/fileSystem/FileSystem.js b/lib/manager/v2/fileSystem/FileSystem.js index 66f9c2e7..86113c6c 100644 --- a/lib/manager/v2/fileSystem/FileSystem.js +++ b/lib/manager/v2/fileSystem/FileSystem.js @@ -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) @@ -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(); + }); }); }); }); @@ -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); }); }); }, @@ -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() diff --git a/lib/server/v2/commands/Move.js b/lib/server/v2/commands/Move.js index 9106ef8d..7e8424d8 100644 --- a/lib/server/v2/commands/Move.js +++ b/lib/server/v2/commands/Move.js @@ -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) { @@ -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) diff --git a/lib/server/v2/commands/Propfind.js b/lib/server/v2/commands/Propfind.js index 1a023702..984bf3a0 100644 --- a/lib/server/v2/commands/Propfind.js +++ b/lib/server/v2/commands/Propfind.js @@ -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) { @@ -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(); diff --git a/src/manager/v2/fileSystem/FileSystem.ts b/src/manager/v2/fileSystem/FileSystem.ts index 1de44062..4c26c418 100644 --- a/src/manager/v2/fileSystem/FileSystem.ts +++ b/src/manager/v2/fileSystem/FileSystem.ts @@ -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' @@ -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, () => { @@ -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(); + }) }) }) }) @@ -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) : void + getProperty(name : string, callback : Return2Callback) : void { issuePrivilegeCheck(fs, ctx, pPath, 'canReadProperties', callback, () => { pm.getProperty(name, callback); @@ -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 { @@ -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) diff --git a/src/server/v2/commands/Move.ts b/src/server/v2/commands/Move.ts index e96bdc78..a088b5fc 100644 --- a/src/server/v2/commands/Move.ts +++ b/src/server/v2/commands/Move.ts @@ -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) @@ -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 diff --git a/src/server/v2/commands/Propfind.ts b/src/server/v2/commands/Propfind.ts index 0c7adc79..778f253a 100644 --- a/src/server/v2/commands/Propfind.ts +++ b/src/server/v2/commands/Propfind.ts @@ -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(); } @@ -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();