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

Side by Side Diff: lib/filesystem/io.js

Issue 5442569823584256: Issue 189 - Implement API changes from #117, #153, #192 in Chrome (Closed)
Patch Set: Fixed #301 fallout as well Created April 15, 2014, 7:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « background.js ('k') | lib/prefs.js » ('j') | 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
(...skipping 30 matching lines...) Expand all
41 }, errorCallback); 41 }, errorCallback);
42 }, 42 },
43 43
44 lineBreak: "\n", 44 lineBreak: "\n",
45 45
46 resolveFilePath: function(path) 46 resolveFilePath: function(path)
47 { 47 {
48 return new FakeFile(path); 48 return new FakeFile(path);
49 }, 49 },
50 50
51 readFromFile: function(file, decode, listener, callback, timeLineID) 51 readFromFile: function(file, listener, callback, timeLineID)
52 { 52 {
53 // Hack to allow importing old data 53 // Hack to allow importing old data
54 if (typeof file == "string") 54 if (typeof file == "string")
55 { 55 {
56 var Utils = require("utils").Utils; 56 var Utils = require("utils").Utils;
57 Utils.runAsync(function() 57 Utils.runAsync(function()
58 { 58 {
59 var lines = file.split(/[\r\n]+/); 59 var lines = file.split(/[\r\n]+/);
60 for (var i = 0; i < lines.length; i++) 60 for (var i = 0; i < lines.length; i++)
61 listener.process(lines[i]); 61 listener.process(lines[i]);
62 listener.process(null); 62 listener.process(null);
63 callback(null); 63 callback(null);
64 }.bind(this)); 64 }.bind(this));
65 return; 65 return;
66 } 66 }
67 67
68 if ("spec" in file && /^defaults\b/.test(file.spec))
69 {
70 // Code attempts to read the default patterns.ini, we don't have that.
71 // Make sure to execute first-run actions instead.
72 var Utils = require("utils").Utils;
73 Utils.runAsync(function()
74 {
75 if (ext.storage.currentVersion)
76 seenDataCorruption = true;
77 delete ext.storage.currentVersion;
78 callback(null);
79 });
80 return;
81 }
82
83 this._getFileEntry(file, false, function(fs, fileEntry) 68 this._getFileEntry(file, false, function(fs, fileEntry)
84 { 69 {
85 fileEntry.file(function(file) 70 fileEntry.file(function(file)
86 { 71 {
87 var reader = new FileReader(); 72 var reader = new FileReader();
88 reader.onloadend = function() 73 reader.onloadend = function()
89 { 74 {
90 if (reader.error) 75 if (reader.error)
91 callback(reader.error); 76 callback(reader.error);
92 else 77 else
93 { 78 {
94 var lines = reader.result.split(/[\r\n]+/); 79 var lines = reader.result.split(/[\r\n]+/);
95 for (var i = 0; i < lines.length; i++) 80 for (var i = 0; i < lines.length; i++)
96 listener.process(lines[i]); 81 listener.process(lines[i]);
97 listener.process(null); 82 listener.process(null);
98 callback(null); 83 callback(null);
99 } 84 }
100 }; 85 };
101 reader.readAsText(file); 86 reader.readAsText(file);
102 }, callback); 87 }, callback);
103 }, callback); 88 }, callback);
104 }, 89 },
105 90
106 writeToFile: function(file, encode, data, callback, timeLineID) 91 writeToFile: function(file, data, callback, timeLineID)
107 { 92 {
108 this._getFileEntry(file, true, function(fs, fileEntry) 93 this._getFileEntry(file, true, function(fs, fileEntry)
109 { 94 {
110 fileEntry.createWriter(function(writer) 95 fileEntry.createWriter(function(writer)
111 { 96 {
112 var executeWriteOperation = function(op, nextOperation) 97 var executeWriteOperation = function(op, nextOperation)
113 { 98 {
114 writer.onwriteend = function() 99 writer.onwriteend = function()
115 { 100 {
116 if (writer.error) 101 if (writer.error)
(...skipping 25 matching lines...) Expand all
142 executeWriteOperation(writer.write.bind(writer, blob), callback.bind(n ull, null)); 127 executeWriteOperation(writer.write.bind(writer, blob), callback.bind(n ull, null));
143 }.bind(this)); 128 }.bind(this));
144 }.bind(this), callback); 129 }.bind(this), callback);
145 }.bind(this), callback); 130 }.bind(this), callback);
146 }, 131 },
147 132
148 copyFile: function(fromFile, toFile, callback) 133 copyFile: function(fromFile, toFile, callback)
149 { 134 {
150 // Simply combine read and write operations 135 // Simply combine read and write operations
151 var data = []; 136 var data = [];
152 this.readFromFile(fromFile, false, { 137 this.readFromFile(fromFile, {
153 process: function(line) 138 process: function(line)
154 { 139 {
155 if (line !== null) 140 if (line !== null)
156 data.push(line); 141 data.push(line);
157 } 142 }
158 }, function(e) 143 }, function(e)
159 { 144 {
160 if (e) 145 if (e)
161 callback(e); 146 callback(e);
162 else 147 else
163 this.writeToFile(toFile, false, data, callback); 148 this.writeToFile(toFile, data, callback);
164 }.bind(this)); 149 }.bind(this));
165 }, 150 },
166 151
167 renameFile: function(fromFile, newName, callback) 152 renameFile: function(fromFile, newName, callback)
168 { 153 {
169 this._getFileEntry(fromFile, false, function(fs, fileEntry) 154 this._getFileEntry(fromFile, false, function(fs, fileEntry)
170 { 155 {
171 fileEntry.moveTo(fs.root, newName, function() 156 fileEntry.moveTo(fs.root, newName, function()
172 { 157 {
173 callback(null); 158 callback(null);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 callback(null, { 193 callback(null, {
209 exists: true, 194 exists: true,
210 isDirectory: fileEntry.isDirectory, 195 isDirectory: fileEntry.isDirectory,
211 isFile: fileEntry.isFile, 196 isFile: fileEntry.isFile,
212 lastModified: metadata.modificationTime.getTime() 197 lastModified: metadata.modificationTime.getTime()
213 }); 198 });
214 }, callback); 199 }, callback);
215 }, callback); 200 }, callback);
216 } 201 }
217 }; 202 };
OLDNEW
« background.js ('K') | « background.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld