| 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 |
| */ |