jsDAV
jsDAV copied to clipboard
incorrect MOVE results in deletion
MOVEing a resource to itself results in the corresponding file being deleted:
$ echo lipsum > foo
$ curl -v -X MOVE -H "Destination: http://127.0.0.1:8000/foo" "http://127.0.0.1:8000/foo"
< HTTP/1.1 500 Internal Server Error
...
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:a="http://ajax.org/2005/aml">
<a:exception>Error: ENOENT, rename '.../foo'</a:exception>
<a:message>ENOENT, rename '.../foo'</a:message>
<a:file></a:file>
<a:line></a:line>
<a:jsdav-version>0.3.2</a:jsdav-version>
</d:error>
$ ls foo
ls: foo: No such file or directory
Similarly, MOVEing a nonexistent resource to an existing resource deletes the latter:
$ echo lipsum > foo
$ curl -v -X MOVE -H "Destination: http://127.0.0.1:8000/foo" "http://127.0.0.1:8000/bar"
< HTTP/1.1 500 Internal Server Error
...
<?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:a="http://ajax.org/2005/aml">
<a:exception>Error: ENOENT, rename '.../bar'</a:exception>
<a:message>ENOENT, rename '.../bar'</a:message>
<a:file></a:file>
<a:line></a:line>
<a:jsdav-version>0.3.2</a:jsdav-version>
</d:error>
$ ls foo
ls: foo: No such file or directory
That seems undesirable as it leads to unexpected data loss.
This is how I start my jsDAV server:
var jsDAV = require("jsDAV/lib/jsdav");
var locks = require("jsDAV/lib/DAV/plugins/locks/fs");
var path = require("path");
var root = __dirname
jsDAV.debugMode = true;
jsDAV.createServer({ node: root }, 8000);
It seems validations missing caught special cases You can refer on lib/DAV/handler.js, then find "this.getCopyAndMoveInfo = function(cbcopymove) {" to add more validation