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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 exports.IO = | 53 exports.IO = |
54 { | 54 { |
55 resolveFilePath: function(path) | 55 resolveFilePath: function(path) |
56 { | 56 { |
57 return new FakeFile(path); | 57 return new FakeFile(path); |
58 }, | 58 }, |
59 | 59 |
60 readFromFile: function(file, listener, callback) | 60 readFromFile: function(file, listener, callback) |
61 { | 61 { |
62 loadFile(file).catch(() => null) | 62 function onLoaded(entry) |
Sebastian Noack
2016/04/01 10:49:44
The logic here is wrong. In the case of readFromFi
| |
63 .then(entry => | |
64 { | 63 { |
65 if (!entry) | |
66 return; | |
67 if ("content" in entry) | 64 if ("content" in entry) |
68 { | 65 { |
69 for (let line of entry.content) | 66 for (let line of entry.content) |
70 listener.process(line); | 67 listener.process(line); |
71 | 68 |
72 listener.process(null); | 69 listener.process(null); |
73 callback(null); | 70 callback(null); |
74 } | 71 } |
75 else | 72 else |
76 { | 73 { |
77 let keys = []; | 74 let keys = []; |
78 for (let i = 0; i < entry.chunks; i++) | 75 for (let i = 0; i < entry.chunks; i++) |
79 keys.push(fileToKey(file, i)); | 76 keys.push(fileToKey(file, i)); |
80 | 77 |
81 ext.storage.get(keys, items => | 78 ext.storage.get(keys, items => |
82 { | 79 { |
83 for (let key of keys) | 80 for (let key of keys) |
84 for (let line of items[key]) | 81 for (let line of items[key]) |
85 listener.process(line); | 82 listener.process(line); |
86 | 83 |
87 listener.process(null); | 84 listener.process(null); |
88 callback(null); | 85 callback(null); |
89 }); | 86 }); |
90 } | 87 } |
91 }); | 88 } |
89 | |
90 loadFile(file).then(onLoaded, callback); | |
92 }, | 91 }, |
93 | 92 |
Sebastian Noack
2016/04/01 10:49:44
Nit: You added trailing whitespaces to this line.
| |
94 writeToFile: function(file, data, callback) | 93 writeToFile: function(file, data, callback) |
95 { | 94 { |
96 let items = {}; | 95 let items = {}; |
97 let entry = items[fileToKey(file)] = {lastModified: Date.now()}; | 96 let entry = items[fileToKey(file)] = {lastModified: Date.now()}; |
98 | 97 |
99 if (typeof browser != "object") | 98 if (typeof browser == "object") |
100 { | 99 { |
101 loadFile(file).catch(() => null) | 100 loadFile(file).catch(() => null) |
102 .then(oldEntry => | 101 .then(oldEntry => |
103 { | 102 { |
104 let quota = 1024 * 1024 / 2 - 1000; | 103 let quota = 1024 * 1024 / 2 - 1000; |
105 let chunks = []; | 104 let chunks = []; |
106 let chunk = []; | 105 let chunk = []; |
107 let chunkSize = 0; | 106 let chunkSize = 0; |
108 | 107 |
109 for (let line of data) | 108 for (let line of data) |
(...skipping 16 matching lines...) Expand all Loading... | |
126 ext.storage.set(items, callback); | 125 ext.storage.set(items, callback); |
127 | 126 |
128 if (oldEntry && "chunks" in oldEntry) | 127 if (oldEntry && "chunks" in oldEntry) |
129 for (let i = entry.chunks; i < oldEntry.chunks; i++) | 128 for (let i = entry.chunks; i < oldEntry.chunks; i++) |
130 ext.storage.remove(fileToKey(file, i)); | 129 ext.storage.remove(fileToKey(file, i)); |
131 }); | 130 }); |
132 } | 131 } |
133 else | 132 else |
134 { | 133 { |
135 entry.content = data; | 134 entry.content = data; |
136 ext.storage.set(items, callback); | 135 ext.storage.set(items, callback); |
Sebastian Noack
2016/04/01 10:49:44
Nit: You added trailing whitespaces to this line.
| |
137 } | 136 } |
138 }, | 137 }, |
139 | 138 |
140 statFile: function(file, callback) | 139 statFile: function(file, callback) |
141 { | 140 { |
142 loadFile(file).catch((val) => null) | 141 function onLoaded(entry) |
143 .then(entry => | |
144 { | 142 { |
145 if (entry) | 143 callback(null, { |
146 callback(null, { | 144 exists: true, |
147 exists: true, | 145 lastModified: entry.lastModified |
148 lastModified: entry.lastModified | 146 }); |
149 }); | 147 } |
150 }); | 148 |
151 }, | 149 loadFile(file).then(onLoaded, callback); |
150 } | |
152 }; | 151 }; |
LEFT | RIGHT |