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

Side by Side Diff: lib/storage/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') | « lib/prefs.js ('k') | lib/utils.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 26 matching lines...) Expand all
37 ext.storage[path + "/lastModified"] = lastModified || 0; 37 ext.storage[path + "/lastModified"] = lastModified || 0;
38 }, 38 },
39 39
40 lineBreak: "\n", 40 lineBreak: "\n",
41 41
42 resolveFilePath: function(path) 42 resolveFilePath: function(path)
43 { 43 {
44 return new FakeFile(path); 44 return new FakeFile(path);
45 }, 45 },
46 46
47 readFromFile: function(file, decode, listener, callback, timeLineID) 47 readFromFile: function(file, listener, callback, timeLineID)
48 { 48 {
49 var Utils = require("utils").Utils; 49 var Utils = require("utils").Utils;
50 Utils.runAsync(function() 50 Utils.runAsync(function()
51 { 51 {
52 if ("spec" in file && /^defaults\b/.test(file.spec))
53 {
54 // Code attempts to read the default patterns.ini, we don't have that.
55 // Make sure to execute first-run actions instead.
56 if (ext.storage.currentVersion)
57 seenDataCorruption = true;
58 delete ext.storage.currentVersion;
59 callback(null);
60 return;
61 }
62
63 var path = this._getFilePath(file); 52 var path = this._getFilePath(file);
64 if (!(path in ext.storage)) 53 if (!(path in ext.storage))
65 { 54 {
66 callback(new Error("File doesn't exist")) 55 callback(new Error("File doesn't exist"))
67 return; 56 return;
68 } 57 }
69 58
70 var lines = ext.storage[path].split(/[\r\n]+/); 59 var lines = ext.storage[path].split(/[\r\n]+/);
71 for (var i = 0; i < lines.length; i++) 60 for (var i = 0; i < lines.length; i++)
72 listener.process(lines[i]); 61 listener.process(lines[i]);
73 listener.process(null); 62 listener.process(null);
74 callback(null); 63 callback(null);
75 }.bind(this)); 64 }.bind(this));
76 }, 65 },
77 66
78 writeToFile: function(file, encode, data, callback, timeLineID) 67 writeToFile: function(file, data, callback, timeLineID)
79 { 68 {
80 var path = this._getFilePath(file); 69 var path = this._getFilePath(file);
81 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Date .now()); 70 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Date .now());
82 71
83 var Utils = require("utils").Utils; 72 var Utils = require("utils").Utils;
84 Utils.runAsync(callback, null, null); 73 Utils.runAsync(callback, null, null);
85 }, 74 },
86 75
87 copyFile: function(fromFile, toFile, callback) 76 copyFile: function(fromFile, toFile, callback)
88 { 77 {
89 // Simply combine read and write operations 78 // Simply combine read and write operations
90 var data = []; 79 var data = [];
91 this.readFromFile(fromFile, false, { 80 this.readFromFile(fromFile, {
92 process: function(line) 81 process: function(line)
93 { 82 {
94 if (line !== null) 83 if (line !== null)
95 data.push(line); 84 data.push(line);
96 } 85 }
97 }, function(e) 86 }, function(e)
98 { 87 {
99 if (e) 88 if (e)
100 callback(e); 89 callback(e);
101 else 90 else
102 this.writeToFile(toFile, false, data, callback); 91 this.writeToFile(toFile, data, callback);
103 }.bind(this)); 92 }.bind(this));
104 }, 93 },
105 94
106 renameFile: function(fromFile, newName, callback) 95 renameFile: function(fromFile, newName, callback)
107 { 96 {
108 var path = this._getFilePath(fromFile); 97 var path = this._getFilePath(fromFile);
109 if (!(path in ext.storage)) 98 if (!(path in ext.storage))
110 { 99 {
111 callback(new Error("File doesn't exist")) 100 callback(new Error("File doesn't exist"))
112 return; 101 return;
(...skipping 15 matching lines...) Expand all
128 { 117 {
129 var path = this._getFilePath(file); 118 var path = this._getFilePath(file);
130 callback(null, { 119 callback(null, {
131 exists: path in ext.storage, 120 exists: path in ext.storage,
132 isDirectory: false, 121 isDirectory: false,
133 isFile: true, 122 isFile: true,
134 lastModified: parseInt(ext.storage[path + "/lastModified"], 10) || 0 123 lastModified: parseInt(ext.storage[path + "/lastModified"], 10) || 0
135 }); 124 });
136 } 125 }
137 }; 126 };
OLDNEW
« background.js ('K') | « lib/prefs.js ('k') | lib/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld