MCPcopy
hub / github.com/jvilk/BrowserFS / empty

Method empty

src/backend/HTML5FS.ts:260–295  ·  view source on GitHub ↗

* Deletes everything in the FS. Used for testing. * Karma clears the storage after you quit it but not between runs of the test * suite, and the tests expect an empty FS every time.

(mainCb: BFSOneArgCallback)

Source from the content-addressed store, hash-verified

258 * suite, and the tests expect an empty FS every time.
259 */
260 public empty(mainCb: BFSOneArgCallback): void {
261 // Get a list of all entries in the root directory to delete them
262 this._readdir('/', (err: ApiError, entries?: Entry[]): void => {
263 if (err) {
264 console.error('Failed to empty FS');
265 mainCb(err);
266 } else {
267 // Called when every entry has been operated on
268 const finished = (er: any): void => {
269 if (err) {
270 console.error("Failed to empty FS");
271 mainCb(err);
272 } else {
273 mainCb();
274 }
275 };
276 // Removes files and recursively removes directories
277 const deleteEntry = (entry: Entry, cb: (e?: any) => void): void => {
278 const succ = () => {
279 cb();
280 };
281 const error = (err: DOMException) => {
282 cb(convertError(err, entry.fullPath, !entry.isDirectory));
283 };
284 if (isDirectoryEntry(entry)) {
285 entry.removeRecursively(succ, error);
286 } else {
287 entry.remove(succ, error);
288 }
289 };
290 // Loop through the entries and remove them, then call the callback
291 // when they're all finished.
292 asyncEach(entries!, deleteEntry, finished);
293 }
294 });
295 }
296
297 public rename(oldPath: string, newPath: string, cb: BFSOneArgCallback): void {
298 let semaphore: number = 2;

Callers 4

authFunction · 0.45
HTML5FSFactoryFunction · 0.45
IDBFSFactoryFunction · 0.45
LSFSFactoryFunction · 0.45

Calls 2

_readdirMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected