VulpesOS/gaia/shared/js/device_storage/enumerate_all.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

65 lines
1.6 KiB
JavaScript
Executable file

'use strict';
/* exported enumerateAll */
// With the removal of composite storage, this function emulates
// the composite storage enumeration (i.e. return files from
// all of the storage areas).
function enumerateAll(storages, dir, options) {
var storageIndex = 0;
var ds_cursor = null;
var cursor = {
continue: function cursor_continue() {
ds_cursor.continue();
}
};
function onsuccess(e) {
cursor.result = e.target.result;
if (!cursor.result) {
storageIndex++;
if (storageIndex < storages.length) {
enumerateNextStorage();
return;
}
// If we've run out of storages, then we fall through and call
// onsuccess with the null result.
}
if (cursor.onsuccess) {
try {
cursor.onsuccess(e);
} catch (err) {
console.warn('enumerateAll onsuccess threw', err);
}
}
}
function onerror(e) {
cursor.error = e.target.error;
if (cursor.error.name === 'NotFoundError' &&
storageIndex !== storages.length - 1) {
storageIndex++;
enumerateNextStorage();
return;
}
if (cursor.onerror) {
try {
cursor.onerror(e);
} catch (err) {
console.warn('enumerateAll onerror threw', err);
}
}
}
function enumerateNextStorage() {
// The || {} on the next line is required to make enumerate work properly
// on v1-train.
ds_cursor = storages[storageIndex].enumerate(dir, options || {});
ds_cursor.onsuccess = onsuccess;
ds_cursor.onerror = onerror;
}
enumerateNextStorage();
return cursor;
}