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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ?
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld