Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/filterStorage.js

Issue 29397586: Issue 4919 - Make getBackupFiles in lib/filterStorage.js asynchronous (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created March 29, 2017, 10:39 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterStorage.js
===================================================================
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -700,36 +700,58 @@ let FilterStorage = exports.FilterStorag
);
if (!explicitFile)
this._saving = true;
checkBackupRequired(writeFilters, removeLastBackup);
},
/**
- * Returns the list of existing backup files.
- * @return {nsIFile[]}
+ * @typedef FileInfo
+ * @type {object}
+ * @property {nsIFile} file
+ * @property {number} lastModified
+ */
+
+ /**
+ * Returns a promise resolving in a list of existing backup files.
+ * @return {Promise.<FileInfo[]>}
*/
getBackupFiles()
{
- let result = [];
+ let backups = [];
let [, part1, part2] = /^(.*)(\.\w+)$/.exec(
FilterStorage.sourceFile.leafName
) || [null, FilterStorage.sourceFile.leafName, ""];
- for (let i = 1; ; i++)
+
+ function checkBackupFile(index)
{
- let file = FilterStorage.sourceFile.clone();
- file.leafName = part1 + "-backup" + i + part2;
- if (file.exists())
- result.push(file);
- else
- break;
+ return new Promise((resolve, reject) =>
+ {
+ let file = FilterStorage.sourceFile.clone();
+ file.leafName = part1 + "-backup" + index + part2;
+
+ IO.statFile(file, (error, result) =>
+ {
+ if (!error && result.exists)
+ {
+ backups.push({
+ file,
+ lastModified: result.lastModified
+ });
+ resolve(checkBackupFile(index + 1));
kzar 2017/03/29 11:51:33 The recursion here is slightly hairy but I can't t
+ }
+ else
+ resolve(backups);
+ });
+ });
}
- return result;
+
+ return checkBackupFile(1);
}
};
/**
* Joins subscription's filters to the subscription without any notifications.
* @param {Subscription} subscription
* filter subscription that should be connected to its filters
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld