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

Side by Side Diff: lib/filterStorage.js

Issue 8736021: Topic 10992 - Fallback if patterns.ini doesn`t exist doesn`t work (Closed)
Patch Set: Created Oct. 31, 2012, 3:19 p.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 Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 /** 7 /**
8 * @fileOverview FilterStorage class responsible for managing user's subscriptio ns and filters. 8 * @fileOverview FilterStorage class responsible for managing user's subscriptio ns and filters.
9 */ 9 */
10 10
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 { 369 {
370 let [, part1, part2] = /^(.*)(\.\w+)$/.exec(sourceFile.leafName) || [null, sourceFile.leafName, ""]; 370 let [, part1, part2] = /^(.*)(\.\w+)$/.exec(sourceFile.leafName) || [null, sourceFile.leafName, ""];
371 371
372 sourceFile = sourceFile.clone(); 372 sourceFile = sourceFile.clone();
373 sourceFile.leafName = part1 + "-backup" + (++backupIndex) + part2; 373 sourceFile.leafName = part1 + "-backup" + (++backupIndex) + part2;
374 374
375 IO.statFile(sourceFile, function(e, statData) 375 IO.statFile(sourceFile, function(e, statData)
376 { 376 {
377 if (!e && statData.exists) 377 if (!e && statData.exists)
378 readFile(sourceFile, backupIndex); 378 readFile(sourceFile, backupIndex);
379 else
380 doneReading(parser);
379 }); 381 });
380 TimeLine.leave("FilterStorage.loadFromDisk() read callback done"); 382 TimeLine.leave("FilterStorage.loadFromDisk() read callback done");
381 return; 383 return;
382 } 384 }
383 } 385 }
384 386 doneReading(parser);
385 // Old special groups might have been converted, remove them if they are empty
386 let specialMap = {"~il~": true, "~wl~": true, "~fl~": true, "~eh~": true };
387 let knownSubscriptions = {__proto__: null};
388 for (let i = 0; i < parser.subscriptions.length; i++)
389 {
390 let subscription = parser.subscriptions[i];
391 if (subscription instanceof SpecialSubscription && subscription.filter s.length == 0 && subscription.url in specialMap)
392 parser.subscriptions.splice(i--, 1);
393 else
394 knownSubscriptions[subscription.url] = subscription;
395 }
396
397 this.fileProperties = parser.fileProperties;
398 this.subscriptions = parser.subscriptions;
399 this.knownSubscriptions = knownSubscriptions;
400 Filter.knownFilters = parser.knownFilters;
401 Subscription.knownSubscriptions = parser.knownSubscriptions;
402
403 if (parser.userFilters)
404 {
405 for (let i = 0; i < parser.userFilters.length; i++)
406 {
407 let filter = Filter.fromText(parser.userFilters[i]);
408 this.addFilter(filter, null, undefined, true);
409 }
410 }
411 TimeLine.log("Initializing data done, triggering observers")
412
413 this._loading = false;
414 FilterNotifier.triggerListeners("load");
415
416 if (sourceFile != this.sourceFile)
417 this.saveToDisk();
418
419 TimeLine.leave("FilterStorage.loadFromDisk() read callback done");
420 }.bind(this), "FilterStorageRead"); 387 }.bind(this), "FilterStorageRead");
421 388
422 TimeLine.leave("FilterStorage.loadFromDisk() <- readFile()", "FilterStorag eRead"); 389 TimeLine.leave("FilterStorage.loadFromDisk() <- readFile()", "FilterStorag eRead");
423 }.bind(this); 390 }.bind(this);
424 391
392 var doneReading = function(parser)
393 {
394 // Old special groups might have been converted, remove them if they are e mpty
395 let specialMap = {"~il~": true, "~wl~": true, "~fl~": true, "~eh~": true};
396 let knownSubscriptions = {__proto__: null};
397 for (let i = 0; i < parser.subscriptions.length; i++)
398 {
399 let subscription = parser.subscriptions[i];
400 if (subscription instanceof SpecialSubscription && subscription.filters. length == 0 && subscription.url in specialMap)
401 parser.subscriptions.splice(i--, 1);
402 else
403 knownSubscriptions[subscription.url] = subscription;
404 }
405
406 this.fileProperties = parser.fileProperties;
407 this.subscriptions = parser.subscriptions;
408 this.knownSubscriptions = knownSubscriptions;
409 Filter.knownFilters = parser.knownFilters;
410 Subscription.knownSubscriptions = parser.knownSubscriptions;
411
412 if (parser.userFilters)
413 {
414 for (let i = 0; i < parser.userFilters.length; i++)
415 {
416 let filter = Filter.fromText(parser.userFilters[i]);
417 this.addFilter(filter, null, undefined, true);
418 }
419 }
420 TimeLine.log("Initializing data done, triggering observers")
421
422 this._loading = false;
423 FilterNotifier.triggerListeners("load");
424
425 if (sourceFile != this.sourceFile)
426 this.saveToDisk();
427
428 TimeLine.leave("FilterStorage.loadFromDisk() read callback done");
429 }.bind(this);
430
425 let startRead = function(file) 431 let startRead = function(file)
426 { 432 {
427 this._loading = true; 433 this._loading = true;
428 readFile(file, 0); 434 readFile(file, 0);
429 }.bind(this); 435 }.bind(this);
430 436
431 let explicitFile; 437 let explicitFile;
432 if (sourceFile) 438 if (sourceFile)
433 { 439 {
434 explicitFile = true; 440 explicitFile = true;
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 else if (this.wantObj === false && val) 836 else if (this.wantObj === false && val)
831 this.curObj.push(val.replace(/\\\[/g, "[")); 837 this.curObj.push(val.replace(/\\\[/g, "["));
832 } 838 }
833 finally 839 finally
834 { 840 {
835 Filter.knownFilters = origKnownFilters; 841 Filter.knownFilters = origKnownFilters;
836 Subscription.knownSubscriptions = origKnownSubscriptions; 842 Subscription.knownSubscriptions = origKnownSubscriptions;
837 } 843 }
838 } 844 }
839 }; 845 };
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