Updated Branches: refs/heads/master c1c1f3727 -> 34e49e0c1
[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-plugin-file/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/34e49e0c Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/34e49e0c Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/34e49e0c Branch: refs/heads/master Commit: 34e49e0c1b3c38088a13a2b53f454cf930dd8484 Parents: c1c1f37 Author: Max Woghiren <[email protected]> Authored: Mon Jul 8 14:13:56 2013 -0400 Committer: Max Woghiren <[email protected]> Committed: Mon Jul 8 14:14:28 2013 -0400 ---------------------------------------------------------------------- www/DirectoryReader.js | 8 ++++++++ 1 file changed, 8 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/34e49e0c/www/DirectoryReader.js ---------------------------------------------------------------------- diff --git a/www/DirectoryReader.js b/www/DirectoryReader.js index 849e26e..5f0cb38 100644 --- a/www/DirectoryReader.js +++ b/www/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) {
