| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 { | 56 { |
| 57 return formatVersion; | 57 return formatVersion; |
| 58 }, | 58 }, |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * File containing the filter list | 61 * File containing the filter list |
| 62 * @type {string} | 62 * @type {string} |
| 63 */ | 63 */ |
| 64 get sourceFile() | 64 get sourceFile() |
| 65 { | 65 { |
| 66 return "patterns.ini"; | 66 return "patterns.ini"; |
|
Wladimir Palant
2017/04/10 14:59:15
We are removing configurability here, there is no
| |
| 67 }, | 67 }, |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * Will be set to true if no patterns.ini file exists. | 70 * Will be set to true if no patterns.ini file exists. |
| 71 * @type {boolean} | 71 * @type {boolean} |
| 72 */ | 72 */ |
| 73 firstRun: false, | 73 firstRun: false, |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Map of properties listed in the filter storage file before the sections | 76 * Map of properties listed in the filter storage file before the sections |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 parser(null); | 451 parser(null); |
| 452 if (this.subscriptions.length == 0) | 452 if (this.subscriptions.length == 0) |
| 453 { | 453 { |
| 454 // No filter subscriptions in the file, this isn't right. | 454 // No filter subscriptions in the file, this isn't right. |
| 455 throw new Error("No data in the file"); | 455 throw new Error("No data in the file"); |
| 456 } | 456 } |
| 457 }); | 457 }); |
| 458 }).catch(error => | 458 }).catch(error => |
| 459 { | 459 { |
| 460 Cu.reportError(error); | 460 Cu.reportError(error); |
| 461 return tryBackup(1); | 461 return tryBackup(1); |
|
kzar
2017/04/20 06:49:25
So we return a promise here, which might recursive
Wladimir Palant
2017/04/20 07:17:06
Yes, this is the intended behavior - we already re
| |
| 462 }).then(() => | 462 }).then(() => |
| 463 { | 463 { |
| 464 this.initialized = true; | 464 this.initialized = true; |
| 465 FilterNotifier.triggerListeners("load"); | 465 FilterNotifier.triggerListeners("load"); |
|
Wladimir Palant
2017/04/10 14:59:15
There is a change here: load notification is fired
| |
| 466 }); | 466 }); |
| 467 }, | 467 }, |
| 468 | 468 |
| 469 /** | 469 /** |
| 470 * Constructs the file name for a patterns.ini backup. | 470 * Constructs the file name for a patterns.ini backup. |
| 471 * @param {number} backupIndex | 471 * @param {number} backupIndex |
| 472 * number of the backup file (1 being the most recent) | 472 * number of the backup file (1 being the most recent) |
| 473 * @return {string} backup file name | 473 * @return {string} backup file name |
| 474 */ | 474 */ |
| 475 getBackupName(backupIndex) | 475 getBackupName(backupIndex) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 { | 609 { |
| 610 if (index > 0) | 610 if (index > 0) |
| 611 { | 611 { |
| 612 return IO.renameFile(this.getBackupName(index), | 612 return IO.renameFile(this.getBackupName(index), |
| 613 this.getBackupName(index + 1)) | 613 this.getBackupName(index + 1)) |
| 614 .catch(ignoreErrors) | 614 .catch(ignoreErrors) |
| 615 .then(() => renameBackup(index - 1)); | 615 .then(() => renameBackup(index - 1)); |
| 616 } | 616 } |
| 617 | 617 |
| 618 return IO.renameFile(this.sourceFile, this.getBackupName(1)) | 618 return IO.renameFile(this.sourceFile, this.getBackupName(1)) |
| 619 .catch(ignoreErrors); | 619 .catch(ignoreErrors); |
|
Wladimir Palant
2017/04/10 14:59:15
The logic is slightly simplified by not removing t
| |
| 620 }; | 620 }; |
| 621 | 621 |
| 622 // Rename existing files | 622 // Rename existing files |
| 623 return renameBackup(Prefs.patternsbackups - 1); | 623 return renameBackup(Prefs.patternsbackups - 1); |
| 624 }).catch(error => | 624 }).catch(error => |
| 625 { | 625 { |
| 626 // Errors during backup creation shouldn't prevent writing filters. | 626 // Errors during backup creation shouldn't prevent writing filters. |
| 627 Cu.reportError(error); | 627 Cu.reportError(error); |
| 628 }).then(() => | 628 }).then(() => |
| 629 { | 629 { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 655 */ | 655 */ |
| 656 | 656 |
| 657 /** | 657 /** |
| 658 * Returns a promise resolving in a list of existing backup files. | 658 * Returns a promise resolving in a list of existing backup files. |
| 659 * @return {Promise.<FileInfo[]>} | 659 * @return {Promise.<FileInfo[]>} |
| 660 */ | 660 */ |
| 661 getBackupFiles() | 661 getBackupFiles() |
| 662 { | 662 { |
| 663 let backups = []; | 663 let backups = []; |
| 664 | 664 |
| 665 function checkBackupFile(index) | 665 let checkBackupFile = index => |
| 666 { | 666 { |
| 667 return IO.statFile(this.getBackupName(index)).then(statData => | 667 return IO.statFile(this.getBackupName(index)).then(statData => |
| 668 { | 668 { |
| 669 if (!statData.exists) | 669 if (!statData.exists) |
| 670 return backups; | 670 return backups; |
| 671 | 671 |
| 672 backups.push({ | 672 backups.push({ |
| 673 index, | 673 index, |
| 674 lastModified: statData.lastModified | 674 lastModified: statData.lastModified |
| 675 }); | 675 }); |
| 676 return checkBackupFile(index + 1); | 676 return checkBackupFile(index + 1); |
| 677 }).catch(error => | 677 }).catch(error => |
| 678 { | 678 { |
| 679 // Something went wrong, return whatever data we got so far. | 679 // Something went wrong, return whatever data we got so far. |
| 680 Cu.reportError(error); | 680 Cu.reportError(error); |
| 681 return backups; | 681 return backups; |
| 682 }); | 682 }); |
| 683 } | 683 }; |
| 684 | 684 |
| 685 return checkBackupFile(1); | 685 return checkBackupFile(1); |
| 686 } | 686 } |
| 687 }; | 687 }; |
| 688 | 688 |
| 689 /** | 689 /** |
| 690 * Joins subscription's filters to the subscription without any notifications. | 690 * Joins subscription's filters to the subscription without any notifications. |
| 691 * @param {Subscription} subscription | 691 * @param {Subscription} subscription |
| 692 * filter subscription that should be connected to its filters | 692 * filter subscription that should be connected to its filters |
| 693 */ | 693 */ |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 else if (this.wantObj === false && val) | 817 else if (this.wantObj === false && val) |
| 818 this.curObj.push(val.replace(/\\\[/g, "[")); | 818 this.curObj.push(val.replace(/\\\[/g, "[")); |
| 819 } | 819 } |
| 820 finally | 820 finally |
| 821 { | 821 { |
| 822 Filter.knownFilters = origKnownFilters; | 822 Filter.knownFilters = origKnownFilters; |
| 823 Subscription.knownSubscriptions = origKnownSubscriptions; | 823 Subscription.knownSubscriptions = origKnownSubscriptions; |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 }; | 826 }; |
| LEFT | RIGHT |