Updated Branches: refs/heads/2.9.x 05ca69646 -> c01c1730e
[CB-4017] Fixed behavior of DirectoryReader. DirectoryReader.readEntries now returns all entries on the first call and an empty list on all subsequent calls. (Technically, it returns batches of entries until they're all returned, then returning an empty list; this implementation just passes them all in one batch.) Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/c01c1730 Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/c01c1730 Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/c01c1730 Branch: refs/heads/2.9.x Commit: c01c1730e95cad2b97b98e5ef8e1089ad462fe24 Parents: 05ca696 Author: Max Woghiren <[email protected]> Authored: Mon Jul 8 14:05:43 2013 -0400 Committer: Max Woghiren <[email protected]> Committed: Mon Jul 8 14:12:08 2013 -0400 ---------------------------------------------------------------------- lib/common/plugin/DirectoryReader.js | 8 ++++++++ 1 file changed, 8 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/c01c1730/lib/common/plugin/DirectoryReader.js ---------------------------------------------------------------------- diff --git a/lib/common/plugin/DirectoryReader.js b/lib/common/plugin/DirectoryReader.js index 2883b56..c01df86 100644 --- a/lib/common/plugin/DirectoryReader.js +++ b/lib/common/plugin/DirectoryReader.js @@ -27,6 +27,7 @@ var exec = require('cordova/exec'), */ function DirectoryReader(path) { this.path = path || null; + this.hasReadEntries = false; } /** @@ -36,6 +37,12 @@ function DirectoryReader(path) { * @param {Function} errorCallback is called with a FileError */ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) { + // If we've already read and passed on this directory's entries, return an empty list. + if (this.hasReadEntries) { + successCallback([]); + return; + } + var reader = this; var win = typeof successCallback !== 'function' ? null : function(result) { var retVal = []; for (var i=0; i<result.length; i++) { @@ -52,6 +59,7 @@ DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) entry.fullPath = result[i].fullPath; retVal.push(entry); } + reader.hasReadEntries = true; successCallback(retVal); }; var fail = typeof errorCallback !== 'function' ? null : function(code) {
