| OLD | NEW |
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } catch (e) {} | 62 } catch (e) {} |
| 63 | 63 |
| 64 return null; | 64 return null; |
| 65 }, | 65 }, |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * Reads strings from a file asynchronously, calls listener.process() with | 68 * Reads strings from a file asynchronously, calls listener.process() with |
| 69 * each line read and with a null parameter once the read operation is done. | 69 * each line read and with a null parameter once the read operation is done. |
| 70 * The callback will be called when the operation is done. | 70 * The callback will be called when the operation is done. |
| 71 */ | 71 */ |
| 72 readFromFile: function*(/**nsIFile*/ file, /**Object*/ listener, /**Function*/
callback) | 72 readFromFile: function(/**nsIFile*/ file, /**Object*/ listener, /**Function*/
callback) |
| 73 { | 73 { |
| 74 try | 74 try |
| 75 { | 75 { |
| 76 let processing = false; | 76 let processing = false; |
| 77 let buffer = ""; | 77 let buffer = ""; |
| 78 let loaded = false; | 78 let loaded = false; |
| 79 let error = null; | 79 let error = null; |
| 80 | 80 |
| 81 let onProgress = function(data) | 81 let onProgress = function(data) |
| 82 { | 82 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 { | 143 { |
| 144 // Still processing data, delay processing this event. | 144 // Still processing data, delay processing this event. |
| 145 error = e; | 145 error = e; |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 callback(e); | 149 callback(e); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 let decoder = new TextDecoder(); | 152 let decoder = new TextDecoder(); |
| 153 Task.spawn(function() | 153 Task.spawn(function*() |
| 154 { | 154 { |
| 155 if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <=
0) | 155 if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <=
0) |
| 156 { | 156 { |
| 157 // See https://issues.adblockplus.org/ticket/530 - the first file | 157 // See https://issues.adblockplus.org/ticket/530 - the first file |
| 158 // opened cannot be closed due to Gecko bug 858723. Make sure that | 158 // opened cannot be closed due to Gecko bug 858723. Make sure that |
| 159 // our patterns.ini file doesn't stay locked by opening a dummy file | 159 // our patterns.ini file doesn't stay locked by opening a dummy file |
| 160 // first. | 160 // first. |
| 161 try | 161 try |
| 162 { | 162 { |
| 163 let dummyPath = IO.resolveFilePath(Prefs.data_directory + "/dummy").
path; | 163 let dummyPath = IO.resolveFilePath(Prefs.data_directory + "/dummy").
path; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 187 catch (e) | 187 catch (e) |
| 188 { | 188 { |
| 189 callback(e); | 189 callback(e); |
| 190 } | 190 } |
| 191 }, | 191 }, |
| 192 | 192 |
| 193 /** | 193 /** |
| 194 * Writes string data to a file in UTF-8 format asynchronously. The callback | 194 * Writes string data to a file in UTF-8 format asynchronously. The callback |
| 195 * will be called when the write operation is done. | 195 * will be called when the write operation is done. |
| 196 */ | 196 */ |
| 197 writeToFile: function*(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ ca
llback) | 197 writeToFile: function(/**nsIFile*/ file, /**Iterator*/ data, /**Function*/ cal
lback) |
| 198 { | 198 { |
| 199 try | 199 try |
| 200 { | 200 { |
| 201 let encoder = new TextEncoder(); | 201 let encoder = new TextEncoder(); |
| 202 | 202 |
| 203 Task.spawn(function() | 203 Task.spawn(function*() |
| 204 { | 204 { |
| 205 // This mimics OS.File.writeAtomic() but writes in chunks. | 205 // This mimics OS.File.writeAtomic() but writes in chunks. |
| 206 let tmpPath = file.path + ".tmp"; | 206 let tmpPath = file.path + ".tmp"; |
| 207 let f = yield OS.File.open(tmpPath, {write: true, truncate: true}); | 207 let f = yield OS.File.open(tmpPath, {write: true, truncate: true}); |
| 208 | 208 |
| 209 let buf = []; | 209 let buf = []; |
| 210 let bufLen = 0; | 210 let bufLen = 0; |
| 211 let lineBreak = this.lineBreak; | 211 let lineBreak = this.lineBreak; |
| 212 | 212 |
| 213 function writeChunk() | 213 function writeChunk() |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 else | 323 else |
| 324 callback(e); | 324 callback(e); |
| 325 }); | 325 }); |
| 326 } | 326 } |
| 327 catch(e) | 327 catch(e) |
| 328 { | 328 { |
| 329 callback(e); | 329 callback(e); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 } | 332 } |
| OLD | NEW |