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

Side by Side Diff: lib/io.js

Issue 4951638452207616: Issue 530 - patterns.ini isn`t being written on Firefox 20 (Permission denied) (Closed)
Patch Set: Created May 21, 2014, 2:49 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 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Module containing file I/O helpers. 19 * @fileOverview Module containing file I/O helpers.
20 */ 20 */
21 21
22 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); 22 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
23 let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null); 23 let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null);
24 let {OS} = Cu.import("resource://gre/modules/osfile.jsm", null); 24 let {OS} = Cu.import("resource://gre/modules/osfile.jsm", null);
25 let {Task} = Cu.import("resource://gre/modules/Task.jsm", null); 25 let {Task} = Cu.import("resource://gre/modules/Task.jsm", null);
26 26
27 let {TimeLine} = require("timeline"); 27 let {TimeLine} = require("timeline");
28 let {Prefs} = require("prefs");
28 let {Utils} = require("utils"); 29 let {Utils} = require("utils");
29 30
31 let firstRead = true;
30 const BUFFER_SIZE = 0x8000; // 32kB 32 const BUFFER_SIZE = 0x8000; // 32kB
31 33
32 let IO = exports.IO = 34 let IO = exports.IO =
33 { 35 {
34 /** 36 /**
35 * Retrieves the platform-dependent line break string. 37 * Retrieves the platform-dependent line break string.
36 */ 38 */
37 get lineBreak() 39 get lineBreak()
38 { 40 {
39 let lineBreak = (Services.appinfo.OS == "WINNT" ? "\r\n" : "\n"); 41 let lineBreak = (Services.appinfo.OS == "WINNT" ? "\r\n" : "\n");
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (timeLineID) 174 if (timeLineID)
173 { 175 {
174 TimeLine.asyncDone(timeLineID); 176 TimeLine.asyncDone(timeLineID);
175 } 177 }
176 }; 178 };
177 179
178 let decoder = new TextDecoder(); 180 let decoder = new TextDecoder();
179 let array = new Uint8Array(BUFFER_SIZE); 181 let array = new Uint8Array(BUFFER_SIZE);
180 Task.spawn(function() 182 Task.spawn(function()
181 { 183 {
184 if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <= 0)
185 {
186 // See https://issues.adblockplus.org/ticket/530 - the first file
187 // opened cannot be closed due to Gecko bug 858723. Make sure that
188 // our patterns.ini file doesn't stay locked by opening a dummy file
189 // first.
190 try
191 {
192 let dummyPath = IO.resolveFilePath(Prefs.data_directory + "/dummy"). path;
193 let dummy = yield OS.File.open(dummyPath, {write: true, truncate: tr ue});
194 yield dummy.close();
195 }
196 catch (e)
197 {
198 // Dummy might be locked already, we don't care
199 }
200 }
201 firstRead = false;
202
182 let f = yield OS.File.open(file.path, {read: true}); 203 let f = yield OS.File.open(file.path, {read: true});
183 let numBytes; 204 let numBytes;
184 do 205 do
185 { 206 {
186 numBytes = yield f.readTo(array); 207 numBytes = yield f.readTo(array);
187 if (numBytes) 208 if (numBytes)
188 { 209 {
189 let data = decoder.decode(numBytes == BUFFER_SIZE ? 210 let data = decoder.decode(numBytes == BUFFER_SIZE ?
190 array : 211 array :
191 array.subarray(0, numBytes), {stream: true }); 212 array.subarray(0, numBytes), {stream: true });
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 else 356 else
336 callback(e); 357 callback(e);
337 }); 358 });
338 } 359 }
339 catch(e) 360 catch(e)
340 { 361 {
341 callback(e); 362 callback(e);
342 } 363 }
343 } 364 }
344 } 365 }
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