Left: | ||
Right: |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 * endings) | 75 * endings) |
76 * @return {Promise} | 76 * @return {Promise} |
77 * Promise to be resolved or rejected once the operation is completed | 77 * Promise to be resolved or rejected once the operation is completed |
78 */ | 78 */ |
79 writeToFile(fileName, data) | 79 writeToFile(fileName, data) |
80 { | 80 { |
81 return saveFile(fileName, data); | 81 return saveFile(fileName, data); |
82 }, | 82 }, |
83 | 83 |
84 /** | 84 /** |
85 * Copies a file. | |
86 * @param {string} fromFile | |
87 * Name of the file to be copied | |
88 * @param {string} toFile | |
89 * Name of the file to be written, will be overwritten if exists | |
90 * @return {Promise} | |
91 * Promise to be resolved or rejected once the operation is completed | |
92 */ | |
93 copyFile(fromFile, toFile) | |
94 { | |
95 return loadFile(fromFile).then(entry => saveFile(toFile, entry.content)); | |
96 }, | |
97 | |
98 /** | |
99 * Renames a file. | 85 * Renames a file. |
100 * @param {string} fromFile | 86 * @param {string} fromFile |
101 * Name of the file to be renamed | 87 * Name of the file to be renamed |
102 * @param {string} newName | 88 * @param {string} newName |
103 * New file name, will be overwritten if exists | 89 * New file name, will be overwritten if exists |
104 * @return {Promise} | 90 * @return {Promise} |
105 * Promise to be resolved or rejected once the operation is completed | 91 * Promise to be resolved or rejected once the operation is completed |
106 */ | 92 */ |
107 renameFile(fromFile, newName) | 93 renameFile(fromFile, newName) |
108 { | 94 { |
109 return loadFile(fromFile) | 95 return loadFile(fromFile) |
110 .then(entry => browser.storage.local.set({[fileToKey(newName)]: entry})) | 96 .then(entry => browser.storage.local.set({[fileToKey(newName)]: entry})) |
111 .then(() => this.removeFile(fromFile)); | 97 .then(() => this.removeFile(fromFile)); |
112 }, | 98 }, |
113 | 99 |
114 /** | 100 /** |
115 * Removes a file. | |
116 * @param {string} fileName | |
117 * Name of the file to be removed | |
118 * @return {Promise} | |
119 * Promise to be resolved or rejected once the operation is completed | |
120 */ | |
121 removeFile(fileName) | |
122 { | |
123 return browser.storage.local.remove(fileToKey(fileName)); | |
124 }, | |
Sebastian Noack
2018/06/01 19:15:46
Well spotted! I confirmed that copyFile() and remo
piscoi.georgiana
2018/06/05 07:15:56
Done.
| |
125 | |
126 /** | |
127 * Retrieves file metadata. | 101 * Retrieves file metadata. |
128 * @param {string} fileName | 102 * @param {string} fileName |
129 * Name of the file to be looked up | 103 * Name of the file to be looked up |
130 * @return {Promise.<StatData>} | 104 * @return {Promise.<StatData>} |
131 * Promise to be resolved with file metadata once the operation is | 105 * Promise to be resolved with file metadata once the operation is |
132 * completed | 106 * completed |
133 */ | 107 */ |
134 statFile(fileName) | 108 statFile(fileName) |
135 { | 109 { |
136 return loadFile(fileName).then(entry => | 110 return loadFile(fileName).then(entry => |
137 { | 111 { |
138 return { | 112 return { |
139 exists: true, | 113 exists: true, |
140 lastModified: entry.lastModified | 114 lastModified: entry.lastModified |
141 }; | 115 }; |
142 }).catch(error => | 116 }).catch(error => |
143 { | 117 { |
144 if (error.type == "NoSuchFile") | 118 if (error.type == "NoSuchFile") |
145 return {exists: false}; | 119 return {exists: false}; |
146 throw error; | 120 throw error; |
147 }); | 121 }); |
148 } | 122 } |
149 }; | 123 }; |
OLD | NEW |