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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 let subscriptions = this.subscriptions.filter( 698 let subscriptions = this.subscriptions.filter(
699 s => !(s instanceof ExternalSubscription) 699 s => !(s instanceof ExternalSubscription)
700 ); 700 );
701 if (!explicitFile) 701 if (!explicitFile)
702 this._saving = true; 702 this._saving = true;
703 703
704 checkBackupRequired(writeFilters, removeLastBackup); 704 checkBackupRequired(writeFilters, removeLastBackup);
705 }, 705 },
706 706
707 /** 707 /**
708 * Returns the list of existing backup files. 708 * @typedef FileInfo
709 * @return {nsIFile[]} 709 * @type {object}
710 * @property {nsIFile} file
711 * @property {number} lastModified
712 */
713
714 /**
715 * Returns a promise resolving in a list of existing backup files.
716 * @return {Promise.<FileInfo[]>}
710 */ 717 */
711 getBackupFiles() 718 getBackupFiles()
712 { 719 {
713 let result = []; 720 let backups = [];
714 721
715 let [, part1, part2] = /^(.*)(\.\w+)$/.exec( 722 let [, part1, part2] = /^(.*)(\.\w+)$/.exec(
716 FilterStorage.sourceFile.leafName 723 FilterStorage.sourceFile.leafName
717 ) || [null, FilterStorage.sourceFile.leafName, ""]; 724 ) || [null, FilterStorage.sourceFile.leafName, ""];
718 for (let i = 1; ; i++) 725
726 function checkBackupFile(index)
719 { 727 {
720 let file = FilterStorage.sourceFile.clone(); 728 return new Promise((resolve, reject) =>
721 file.leafName = part1 + "-backup" + i + part2; 729 {
722 if (file.exists()) 730 let file = FilterStorage.sourceFile.clone();
723 result.push(file); 731 file.leafName = part1 + "-backup" + index + part2;
724 else 732
725 break; 733 IO.statFile(file, (error, result) =>
734 {
735 if (!error && result.exists)
736 {
737 backups.push({
738 file,
739 lastModified: result.lastModified
740 });
741 resolve(checkBackupFile(index + 1));
kzar 2017/03/29 11:51:33 The recursion here is slightly hairy but I can't t
742 }
743 else
744 resolve(backups);
745 });
746 });
726 } 747 }
727 return result; 748
749 return checkBackupFile(1);
728 } 750 }
729 }; 751 };
730 752
731 /** 753 /**
732 * Joins subscription's filters to the subscription without any notifications. 754 * Joins subscription's filters to the subscription without any notifications.
733 * @param {Subscription} subscription 755 * @param {Subscription} subscription
734 * filter subscription that should be connected to its filters 756 * filter subscription that should be connected to its filters
735 */ 757 */
736 function addSubscriptionFilters(subscription) 758 function addSubscriptionFilters(subscription)
737 { 759 {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 Subscription.knownSubscriptions = origKnownSubscriptions; 887 Subscription.knownSubscriptions = origKnownSubscriptions;
866 } 888 }
867 889
868 // Allow events to be processed every now and then. 890 // Allow events to be processed every now and then.
869 // Note: IO.readFromFile() will deal with the potential reentrance here. 891 // Note: IO.readFromFile() will deal with the potential reentrance here.
870 this.linesProcessed++; 892 this.linesProcessed++;
871 if (this.linesProcessed % 1000 == 0) 893 if (this.linesProcessed % 1000 == 0)
872 return Utils.yield(); 894 return Utils.yield();
873 } 895 }
874 }; 896 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld