Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Copy children recursively and asynchronously #87

Open
wants to merge 11 commits into from

2 participants

@francescomari

The method copyNode() in jsDAV_Tree invokes the getChildren() method in a synchronous fashion. This method is defined asynchronous by the API. I propose a fix by properly calling the getChildren() method asynchronously.

@francescomari

I also spotted another point where an async function was called asynchronously. For the sake of completeness, I found the two bugs while trying to move a folder from one path in the tree to another.

@francescomari

Another fix, the createFile() method was calling with three parameters instead of four. I think that iCollection.js should be updated to reflect the new method signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2013
  1. @francescomari
  2. @francescomari
Commits on Nov 16, 2013
  1. @francescomari
Commits on Mar 18, 2014
  1. @tripodsan
  2. @francescomari

    Merge pull request #1 from tripodsan/master

    francescomari authored
    JSDAV-94 Xml.toClarkNotation() must not lowercase names
Commits on Mar 19, 2014
  1. @tripodsan
  2. @tripodsan
Commits on Mar 20, 2014
  1. @tripodsan
  2. @francescomari

    Merge pull request #2 from tripodsan/master

    francescomari authored
    Fixes for 404 property handling
Commits on Mar 26, 2014
  1. @francescomari
Commits on Mar 28, 2014
  1. @francescomari

    Revert "Avoid usage of instanceof to check for WebDAV exceptions"

    francescomari authored
    This reverts commit c69edafc0503c76db704a5916981263c2f336e11.
This page is out of date. Refresh to see the latest.
View
8 lib/DAV/handler.js
@@ -1774,7 +1774,10 @@ jsDAV_Handler.STATUS_MAP = {
// If we were unable to find the property, we will list it as 404.
if (!allProperties && !newProps["200"][rprop])
newProps["404"][rprop] = null;
+ cbnext();
+ }
+ function afterGetProperties(rpath, newProps, cbnext) {
var node = nodes[rpath];
rpath = Util.trim(rpath, "/");
self.dispatchEvent("afterGetProperties", rpath, newProps, node, function() {
@@ -1925,7 +1928,10 @@ jsDAV_Handler.STATUS_MAP = {
}
})
.end(function(err) {
- cbnextpfp(err);
+ if (err) {
+ return cbnextpfp(err);
+ }
+ afterGetProperties(myPath, newProperties, cbnextpfp)
});
}
});
View
4 lib/DAV/plugins/locks.js
@@ -25,7 +25,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
* @var String
*/
name: "locks",
-
+
initialize: function(handler) {
this.handler = handler;
//this.locksBackend = locksBackend;
@@ -98,7 +98,7 @@ var jsDAV_Locks_Plugin = module.exports = jsDAV_ServerPlugin.extend({
});
break;
default:
- afterGetNode();
+ next();
break;
}
View
16 lib/DAV/property/response.js
@@ -74,9 +74,12 @@ var jsDAV_Property_Response = module.exports = jsDAV_Property.extend({
aXml.push("<d:propstat><d:prop>");
for (resPropertyName in resPropertyGroup) {
- if (typeof resPropertyName != "string"
- || !(resPropertyValue = resPropertyGroup[resPropertyName]))
- continue;
+ if (typeof resPropertyName != "string")
+ continue;
+ resPropertyValue = resPropertyGroup[resPropertyName];
+ if (!resPropertyValue && resHttpStatus == "200") {
+ continue;
+ }
resCurrentProperty = "";
resPropName = resPropertyName.match(/^\{([^\}]*)\}(.*)$/);
@@ -103,7 +106,10 @@ var jsDAV_Property_Response = module.exports = jsDAV_Property.extend({
}
}
- if (typeof resPropertyValue != "object") {
+ if (!resPropertyValue) {
+ resCurrentProperty += "/>";
+ }
+ else if (typeof resPropertyValue != "object") {
resCurrentProperty += ">" + Xml.escapeXml(resPropertyValue) + "</" + resNodeName + ">";
}
else if (resPropertyValue.hasFeature(jsDAV_Property)) {
@@ -111,7 +117,7 @@ var jsDAV_Property_Response = module.exports = jsDAV_Property.extend({
resCurrentProperty = resPropertyValue.serialize(handler, resCurrentProperty)
+ "</" + resNodeName + ">";
}
- else if (resPropertyValue) {
+ else {
throw new Exc.jsDAV_Exception("Unknown property value type: "
+ resPropertyValue + " for property: " + resPropertyName);
}
View
40 lib/DAV/tree.js
@@ -16,6 +16,7 @@ var jsDAV_iProperties = require("./interfaces/iProperties");
var Exc = require("./../shared/exceptions");
var Util = require("./../shared/util");
var Path = require("path");
+var Async = require("asyncjs");
/**
* Abstract tree object
@@ -146,7 +147,12 @@ var jsDAV_Tree = module.exports = Base.extend({
this.copy(sourcePath, destinationPath, function(err) {
if (err)
return cbmovetree(err);
- self.getNodeForPath(sourcePath)["delete"](onDone);
+ self.getNodeForPath(sourcePath, function (err, node) {
+ if (err) {
+ return cbmovetree(err);
+ }
+ node['delete'](onDone);
+ });
});
}
@@ -210,7 +216,7 @@ var jsDAV_Tree = module.exports = Base.extend({
source.get(function(err, data) {
if (err)
return cbcopytreenode(err);
- destinationParent.createFile(destinationName, data, function(err) {
+ destinationParent.createFile(destinationName, data, null, function(err) {
if (err)
return cbcopytreenode(err);
destinationParent.getChild(destinationName, function(err, destination) {
@@ -228,25 +234,21 @@ var jsDAV_Tree = module.exports = Base.extend({
destinationParent.getChild(destinationName, function(err, destination) {
if (err)
return cbcopytreenode(err);
- var child;
- var c = source.getChildren();
- var i = 0;
- var l = c.length;
- var error = null;
- var onError = function(err) {
- if (err)
- error = err;
- };
- for (; i < l && !error; ++i) {
- child = c[i];
- self.copyNode(child, destination, onError);
- }
- if (error)
- return cbcopytreenode(error);
- afterCopy(destination);
+ source.getChildren(function (err, children) {
+ if (err) {
+ return cbcopytreenode(err);
+ }
+ Async.list(children).each(function (child, cbnext) {
+ self.copyNode(child, destination, child.getName(), cbnext);
+ }).end(function (err) {
+ if (err) {
+ return cbcopytreenode(err);
+ }
+ afterCopy(destination);
+ });
+ });
});
});
-
}
function afterCopy(destination) {
View
4 lib/shared/xml.js
@@ -55,7 +55,9 @@ exports.toClarkNotation = function(dom) {
// Mapping back to the real namespace, in case it was dav
var ns = dom.namespaceURI == "urn:DAV" ? "DAV:" : dom.namespaceURI;
// Mapping to clark notation
- return "{" + ns + "}" + dom.localName.toLowerCase();
+
+ // https://github.com/mikedeboer/jsDAV/issues/94
+ return "{" + ns + "}" + dom.localName;
};
/**
Something went wrong with that request. Please try again.