OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 26 matching lines...) Expand all Loading... |
37 ext.storage[path + "/lastModified"] = lastModified || 0; | 37 ext.storage[path + "/lastModified"] = lastModified || 0; |
38 }, | 38 }, |
39 | 39 |
40 lineBreak: "\n", | 40 lineBreak: "\n", |
41 | 41 |
42 resolveFilePath: function(path) | 42 resolveFilePath: function(path) |
43 { | 43 { |
44 return new FakeFile(path); | 44 return new FakeFile(path); |
45 }, | 45 }, |
46 | 46 |
47 readFromFile: function(file, decode, listener, callback, timeLineID) | 47 readFromFile: function(file, listener, callback, timeLineID) |
48 { | 48 { |
49 var Utils = require("utils").Utils; | 49 var Utils = require("utils").Utils; |
50 Utils.runAsync(function() | 50 Utils.runAsync(function() |
51 { | 51 { |
52 if ("spec" in file && /^defaults\b/.test(file.spec)) | |
53 { | |
54 // Code attempts to read the default patterns.ini, we don't have that. | |
55 // Make sure to execute first-run actions instead. | |
56 if (ext.storage.currentVersion) | |
57 seenDataCorruption = true; | |
58 delete ext.storage.currentVersion; | |
59 callback(null); | |
60 return; | |
61 } | |
62 | |
63 var path = this._getFilePath(file); | 52 var path = this._getFilePath(file); |
64 if (!(path in ext.storage)) | 53 if (!(path in ext.storage)) |
65 { | 54 { |
66 callback(new Error("File doesn't exist")) | 55 callback(new Error("File doesn't exist")) |
67 return; | 56 return; |
68 } | 57 } |
69 | 58 |
70 var lines = ext.storage[path].split(/[\r\n]+/); | 59 var lines = ext.storage[path].split(/[\r\n]+/); |
71 for (var i = 0; i < lines.length; i++) | 60 for (var i = 0; i < lines.length; i++) |
72 listener.process(lines[i]); | 61 listener.process(lines[i]); |
73 listener.process(null); | 62 listener.process(null); |
74 callback(null); | 63 callback(null); |
75 }.bind(this)); | 64 }.bind(this)); |
76 }, | 65 }, |
77 | 66 |
78 writeToFile: function(file, encode, data, callback, timeLineID) | 67 writeToFile: function(file, data, callback, timeLineID) |
79 { | 68 { |
80 var path = this._getFilePath(file); | 69 var path = this._getFilePath(file); |
81 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Date
.now()); | 70 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Date
.now()); |
82 | 71 |
83 var Utils = require("utils").Utils; | 72 var Utils = require("utils").Utils; |
84 Utils.runAsync(callback, null, null); | 73 Utils.runAsync(callback, null, null); |
85 }, | 74 }, |
86 | 75 |
87 copyFile: function(fromFile, toFile, callback) | 76 copyFile: function(fromFile, toFile, callback) |
88 { | 77 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 { | 117 { |
129 var path = this._getFilePath(file); | 118 var path = this._getFilePath(file); |
130 callback(null, { | 119 callback(null, { |
131 exists: path in ext.storage, | 120 exists: path in ext.storage, |
132 isDirectory: false, | 121 isDirectory: false, |
133 isFile: true, | 122 isFile: true, |
134 lastModified: parseInt(ext.storage[path + "/lastModified"], 10) || 0 | 123 lastModified: parseInt(ext.storage[path + "/lastModified"], 10) || 0 |
135 }); | 124 }); |
136 } | 125 } |
137 }; | 126 }; |
OLD | NEW |