OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 }); | 69 }); |
70 } | 70 } |
71 | 71 |
72 function legacyFile(fileName) | 72 function legacyFile(fileName) |
73 { | 73 { |
74 let file = LegacyIO.resolveFilePath("adblockplus"); | 74 let file = LegacyIO.resolveFilePath("adblockplus"); |
75 file.append(fileName); | 75 file.append(fileName); |
76 return file; | 76 return file; |
77 } | 77 } |
78 | 78 |
| 79 function ensureDirExists(file) |
| 80 { |
| 81 if (!file.exists()) |
| 82 { |
| 83 ensureDirExists(file.parent); |
| 84 file.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); |
| 85 } |
| 86 } |
| 87 |
79 let fallback = { | 88 let fallback = { |
80 readFromFile(fileName, listener) | 89 readFromFile(fileName, listener) |
81 { | 90 { |
82 let wrapper = { | 91 let wrapper = { |
83 process(line) | 92 process(line) |
84 { | 93 { |
85 if (line !== null) | 94 if (line !== null) |
86 listener(line); | 95 listener(line); |
87 } | 96 } |
88 }; | 97 }; |
89 return callLegacy("readFromFile", legacyFile(fileName), wrapper); | 98 return callLegacy("readFromFile", legacyFile(fileName), wrapper); |
90 }, | 99 }, |
91 | 100 |
92 writeToFile(fileName, data) | 101 writeToFile(fileName, data) |
93 { | 102 { |
94 return callLegacy("writeToFile", legacyFile(fileName), data); | 103 let file = legacyFile(fileName); |
| 104 ensureDirExists(file.parent); |
| 105 return callLegacy("writeToFile", file, data); |
95 }, | 106 }, |
96 | 107 |
97 copyFile(fromFile, toFile) | 108 copyFile(fromFile, toFile) |
98 { | 109 { |
99 return callLegacy("copyFile", legacyFile(fromFile), legacyFile(toFile)); | 110 return callLegacy("copyFile", legacyFile(fromFile), legacyFile(toFile)); |
100 }, | 111 }, |
101 | 112 |
102 renameFile(fromFile, newName) | 113 renameFile(fromFile, newName) |
103 { | 114 { |
104 return callLegacy("renameFile", legacyFile(fromFile), newName); | 115 return callLegacy("renameFile", legacyFile(fromFile), newName); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 { | 270 { |
260 return method(...args).catch(error => | 271 return method(...args).catch(error => |
261 { | 272 { |
262 if (error == "NoSuchFile") | 273 if (error == "NoSuchFile") |
263 return fallbackMethod(...args); | 274 return fallbackMethod(...args); |
264 throw error; | 275 throw error; |
265 }); | 276 }); |
266 }; | 277 }; |
267 } | 278 } |
268 } | 279 } |
OLD | NEW |