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

Unified Diff: lib/adblockplus_compat.js

Issue 8556073: Fixed: writing patterns.ini might leave left-overs from previous content (Closed)
Patch Set: Created Oct. 12, 2012, 7:46 a.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 | « .hgsubstate ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/adblockplus_compat.js
===================================================================
--- a/lib/adblockplus_compat.js
+++ b/lib/adblockplus_compat.js
@@ -174,39 +174,49 @@ require.scopes.io =
{
this._getFileEntry(file, true, function(fs, fileEntry)
{
fileEntry.createWriter(function(writer)
{
writer.onwriteend = function()
{
if (writer.error)
+ {
callback(writer.error);
- else
- callback(null);
- };
+ return;
+ }
- var blob;
- try
- {
- blob = new Blob([data.join("\n") + "\n"], {type: "text/plain"});
- }
- catch (e)
- {
- if (!(e instanceof TypeError))
- throw e;
+ writer.onwriteend = function()
+ {
+ if (writer.error)
+ callback(writer.error);
+ else
+ callback(null);
+ }.bind(this);
- // Blob wasn't a constructor before Chrome 20
- var builder = new (window.BlobBuilder || window.WebKitBlobBuilder);
- builder.append(data.join("\n") + "\n");
- blob = builder.getBlob("text/plain");
- }
- writer.write(blob);
- }, callback);
- }, callback);
+ var blob;
+ try
+ {
+ blob = new Blob([data.join(this.lineBreak) + this.lineBreak], {type: "text/plain"});
+ }
+ catch (e)
+ {
+ if (!(e instanceof TypeError))
+ throw e;
+
+ // Blob wasn't a constructor before Chrome 20
+ var builder = new (window.BlobBuilder || window.WebKitBlobBuilder);
+ builder.append(data.join(this.lineBreak) + this.lineBreak);
+ blob = builder.getBlob("text/plain");
+ }
+ writer.write(blob);
+ }.bind(this);
+ writer.truncate(0);
+ }.bind(this), callback);
+ }.bind(this), callback);
},
copyFile: function(fromFile, toFile, callback)
{
// Simply combine read and write operations
var data = [];
this.readFromFile(fromFile, false, {
process: function(line)
« no previous file with comments | « .hgsubstate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld