Skip to content

Commit 592d2bc

Browse files
committed
Fixed the MOVE method
1 parent a03cc96 commit 592d2bc

File tree

2 files changed

+54
-58
lines changed

2 files changed

+54
-58
lines changed

lib/server/v2/commands/Move.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function execute(ctx, methodName, privilegeName, callback) {
88
ctx.noBodyExpected(function () {
99
ctx.getResource(function (e, r) {
1010
ctx.checkIfHeader(r, function () {
11-
//ctx.requirePrivilege([ privilegeName ], r, () => {
1211
var overwrite = ctx.headers.find('overwrite') === 'T';
1312
var destination = ctx.headers.find('destination');
1413
if (!destination) {
@@ -52,10 +51,9 @@ function execute(ctx, methodName, privilegeName, callback) {
5251
StandardMethods_1.StandardMethods.standardCopy(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
5352
}
5453
else {
55-
r[methodName](destination, overwrite, cb);
54+
r[methodName](destSubPath, overwrite, cb);
5655
}
5756
});
58-
//})
5957
});
6058
});
6159
});

src/server/v2/commands/Move.ts

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,65 @@ export function execute(ctx : HTTPRequestContext, methodName : string, privilege
99
ctx.noBodyExpected(() => {
1010
ctx.getResource((e, r) => {
1111
ctx.checkIfHeader(r, () => {
12-
//ctx.requirePrivilege([ privilegeName ], r, () => {
13-
const overwrite = ctx.headers.find('overwrite') === 'T';
12+
const overwrite = ctx.headers.find('overwrite') === 'T';
1413

15-
let destination : any = ctx.headers.find('destination');
16-
if(!destination)
17-
{
18-
ctx.setCode(HTTPCodes.BadRequest);
19-
return callback();
20-
}
21-
22-
const startIndex = destination.indexOf('://');
23-
if(startIndex !== -1)
24-
{
25-
destination = destination.substring(startIndex + '://'.length)
26-
destination = destination.substring(destination.indexOf('/')) // Remove the hostname + port
27-
}
28-
destination = new Path(destination);
14+
let destination : any = ctx.headers.find('destination');
15+
if(!destination)
16+
{
17+
ctx.setCode(HTTPCodes.BadRequest);
18+
return callback();
19+
}
20+
21+
const startIndex = destination.indexOf('://');
22+
if(startIndex !== -1)
23+
{
24+
destination = destination.substring(startIndex + '://'.length)
25+
destination = destination.substring(destination.indexOf('/')) // Remove the hostname + port
26+
}
27+
destination = new Path(destination);
2928

30-
const sDest = destination.toString(true);
31-
const sSource = ctx.requested.path.toString(true);
32-
if(sDest === sSource)
33-
{
34-
ctx.setCode(HTTPCodes.Forbidden);
35-
return callback();
36-
}
37-
if(sDest.indexOf(sSource) === 0)
38-
{
39-
ctx.setCode(HTTPCodes.BadGateway);
40-
return callback();
41-
}
29+
const sDest = destination.toString(true);
30+
const sSource = ctx.requested.path.toString(true);
31+
if(sDest === sSource)
32+
{
33+
ctx.setCode(HTTPCodes.Forbidden);
34+
return callback();
35+
}
36+
if(sDest.indexOf(sSource) === 0)
37+
{
38+
ctx.setCode(HTTPCodes.BadGateway);
39+
return callback();
40+
}
4241

43-
const cb = (e ?: Error, overwritten ?: boolean) =>
42+
const cb = (e ?: Error, overwritten ?: boolean) =>
43+
{
44+
if(e)
4445
{
45-
if(e)
46-
{
47-
if(e === Errors.ResourceAlreadyExists)
48-
ctx.setCode(HTTPCodes.PreconditionFailed);
49-
else if(!ctx.setCodeFromError(e))
50-
ctx.setCode(HTTPCodes.InternalServerError)
51-
}
52-
else if(overwritten)
53-
ctx.setCode(HTTPCodes.NoContent);
54-
else
55-
ctx.setCode(HTTPCodes.Created);
56-
callback();
57-
};
46+
if(e === Errors.ResourceAlreadyExists)
47+
ctx.setCode(HTTPCodes.PreconditionFailed);
48+
else if(!ctx.setCodeFromError(e))
49+
ctx.setCode(HTTPCodes.InternalServerError)
50+
}
51+
else if(overwritten)
52+
ctx.setCode(HTTPCodes.NoContent);
53+
else
54+
ctx.setCode(HTTPCodes.Created);
55+
callback();
56+
};
5857

59-
ctx.server.getFileSystem(destination, (destFs, destRootPath, destSubPath) => {
60-
if(destFs !== r.fs)
61-
{ // Standard method
62-
if(methodName === 'move')
63-
StandardMethods.standardMove(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
64-
else
65-
StandardMethods.standardCopy(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
66-
}
58+
ctx.server.getFileSystem(destination, (destFs, destRootPath, destSubPath) => {
59+
if(destFs !== r.fs)
60+
{ // Standard method
61+
if(methodName === 'move')
62+
StandardMethods.standardMove(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
6763
else
68-
{ // Delegate the operation to the file system
69-
r[methodName](destination, overwrite, cb);
70-
}
71-
})
72-
//})
64+
StandardMethods.standardCopy(ctx, r.path, r.fs, destSubPath, destFs, overwrite, cb);
65+
}
66+
else
67+
{ // Delegate the operation to the file system
68+
r[methodName](destSubPath, overwrite, cb);
69+
}
70+
})
7371
})
7472
})
7573
})

0 commit comments

Comments
 (0)