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, 8:11 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 | « no previous file | 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
@@ -171,42 +171,50 @@ require.scopes.io =
},
writeToFile: function(file, encode, data, callback, timeLineID)
{
this._getFileEntry(file, true, function(fs, fileEntry)
{
fileEntry.createWriter(function(writer)
{
- writer.onwriteend = function()
+ var executeWriteOperation = function(op, nextOperation)
{
- if (writer.error)
- callback(writer.error);
- else
- callback(null);
- };
+ writer.onwriteend = function()
+ {
+ if (writer.error)
+ callback(writer.error);
+ else
+ nextOperation();
+ }.bind(this);
Felix Dahlke 2012/10/12 08:16:21 Why bind this? Doesn't seem to be used.
- var blob;
- try
+ op();
+ }.bind(this);
Felix Dahlke 2012/10/12 08:16:21 Again, why bind this?
+
+ executeWriteOperation(writer.truncate.bind(writer, 0), function()
{
- blob = new Blob([data.join("\n") + "\n"], {type: "text/plain"});
- }
- catch (e)
- {
- if (!(e instanceof TypeError))
- throw e;
+ 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("\n") + "\n");
- blob = builder.getBlob("text/plain");
- }
- writer.write(blob);
- }, callback);
- }, callback);
+ // 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");
+ }
+ executeWriteOperation(writer.write.bind(writer, blob), callback.bind(null, null));
+ }.bind(this));
+ }.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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld