Index: lib/io.js |
=================================================================== |
--- a/lib/io.js |
+++ b/lib/io.js |
@@ -20,18 +20,20 @@ |
*/ |
let {Services} = Cu.import("resource://gre/modules/Services.jsm", null); |
let {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm", null); |
let {OS} = Cu.import("resource://gre/modules/osfile.jsm", null); |
let {Task} = Cu.import("resource://gre/modules/Task.jsm", null); |
let {TimeLine} = require("timeline"); |
+let {Prefs} = require("prefs"); |
let {Utils} = require("utils"); |
+let firstRead = true; |
const BUFFER_SIZE = 0x8000; // 32kB |
let IO = exports.IO = |
{ |
/** |
* Retrieves the platform-dependent line break string. |
*/ |
get lineBreak() |
@@ -174,16 +176,35 @@ let IO = exports.IO = |
TimeLine.asyncDone(timeLineID); |
} |
}; |
let decoder = new TextDecoder(); |
let array = new Uint8Array(BUFFER_SIZE); |
Task.spawn(function() |
{ |
+ if (firstRead && Services.vc.compare(Utils.platformVersion, "23.0a1") <= 0) |
+ { |
+ // See https://issues.adblockplus.org/ticket/530 - the first file |
+ // opened cannot be closed due to Gecko bug 858723. Make sure that |
+ // our patterns.ini file doesn't stay locked by opening a dummy file |
+ // first. |
+ try |
+ { |
+ let dummyPath = IO.resolveFilePath(Prefs.data_directory + "/dummy").path; |
+ let dummy = yield OS.File.open(dummyPath, {write: true, truncate: true}); |
+ yield dummy.close(); |
+ } |
+ catch (e) |
+ { |
+ // Dummy might be locked already, we don't care |
+ } |
+ } |
+ firstRead = false; |
+ |
let f = yield OS.File.open(file.path, {read: true}); |
let numBytes; |
do |
{ |
numBytes = yield f.readTo(array); |
if (numBytes) |
{ |
let data = decoder.decode(numBytes == BUFFER_SIZE ? |