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

Delta Between Two Patch Sets: lib/io.js

Issue 29450608: Issue 5279 - Fix broken I/O in non-Firefox applications (Closed) Base URL: https://hg.adblockplus.org/adblockplus
Left Patch Set: Created May 29, 2017, 11:54 a.m.
Right Patch Set: Addressed comments Created May 29, 2017, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 let {application} = require("info"); 239 let {application} = require("info");
240 if (application != "firefox" && application != "fennec2") 240 if (application != "firefox" && application != "fennec2")
241 { 241 {
242 // Currently, only Firefox has a working WebExtensions implementation, other 242 // Currently, only Firefox has a working WebExtensions implementation, other
243 // applications should just use the fallback. 243 // applications should just use the fallback.
244 exports.IO = fallback; 244 exports.IO = fallback;
245 } 245 }
246 else 246 else
247 { 247 {
248 for (let name of [ 248 // Add fallbacks to IO methods - fall back to legacy I/O if file wasn't found.
249 "readFromFile", "copyFile", "renameFile", "removeFile", "statFile" 249 for (let name of Object.getOwnPropertyNames(exports.IO))
Felix Dahlke 2017/05/29 12:22:30 We could avoid duplication here by iterating over
Wladimir Palant 2017/05/29 12:41:23 Done.
250 ]) 250 {
251 { 251 // No fallback for writeToFile method, new data should always be stored to
252 // For missing files, fall back to legacy I/O for all methods except 252 // new storage only.
Felix Dahlke 2017/05/29 12:22:30 Nit: I think that comment should move in front of
Wladimir Palant 2017/05/29 12:41:23 Done.
253 // writeToFile() 253 if (name == "writeToFile")
254 continue;
255
254 let method = exports.IO[name]; 256 let method = exports.IO[name];
255 let fallbackMethod = fallback[name]; 257 let fallbackMethod = fallback[name];
256 exports.IO[name] = (...args) => 258 exports.IO[name] = (...args) =>
257 { 259 {
258 return method(...args).catch(error => 260 return method(...args).catch(error =>
259 { 261 {
260 if (error == "NoSuchFile") 262 if (error == "NoSuchFile")
261 return fallbackMethod(...args); 263 return fallbackMethod(...args);
262 throw error; 264 throw error;
263 }); 265 });
264 }; 266 };
265 } 267 }
266 } 268 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld