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.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
65
gaia/shared/js/device_storage/enumerate_all.js
Executable file
65
gaia/shared/js/device_storage/enumerate_all.js
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
'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;
|
||||
}
|
||||
33
gaia/shared/js/device_storage/get_storage_if_available.js
Executable file
33
gaia/shared/js/device_storage/get_storage_if_available.js
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
/* exported getStorageIfAvailable */
|
||||
|
||||
// Get a DeviceStorage object for the specified kind of storage and, if it
|
||||
// is available, and if the specified number of bytes of storage space are
|
||||
// free then asynchronously pass the DeviceStorage object to the success
|
||||
// callback. Otherwise, invoke the error callback, if one is specified. If
|
||||
// the error callback is called because device storage is not available, the
|
||||
// argument will be a DeviceStorage status string like 'unavailable' or
|
||||
// 'shared'. If the error callback is called because there is not enough
|
||||
// storage space, the argument will be the number of bytes that are available.
|
||||
function getStorageIfAvailable(kind, size, success, error) {
|
||||
var storage = navigator.getDeviceStorage(kind);
|
||||
storage.available().onsuccess = function(e) {
|
||||
if (e.target.result !== 'available') {
|
||||
if (error) {
|
||||
error(e.target.result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
storage.freeSpace().onsuccess = function(e) {
|
||||
if (e.target.result < size) {
|
||||
if (error) {
|
||||
error(e.target.result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
success(storage);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
37
gaia/shared/js/device_storage/get_unused_filename.js
Executable file
37
gaia/shared/js/device_storage/get_unused_filename.js
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
/* exported getUnusedFilename */
|
||||
|
||||
// This utility function helps avoid overwriting existing files.
|
||||
// If no file with the specified name exists in the specified storage, pass
|
||||
// the name to the callback. Otherwise, add a version number to the name
|
||||
// and try again. Once a name is found that does not already exist, pass it
|
||||
// to the callback. If the initial name 'base.ext' does not exist, then new
|
||||
// names of the form 'base_n.ext', where n is a number are tried.
|
||||
function getUnusedFilename(storage, name, callback) {
|
||||
var getreq = storage.get(name);
|
||||
getreq.onerror = function() {
|
||||
// We get this error if the file does not already exist, and that
|
||||
// is what we want
|
||||
callback(name);
|
||||
};
|
||||
getreq.onsuccess = function() {
|
||||
var version = 0;
|
||||
var p = name.lastIndexOf('/');
|
||||
var dir = name.substring(0, p + 1);
|
||||
var file = name.substring(p + 1);
|
||||
p = file.lastIndexOf('.');
|
||||
if (p === -1) {
|
||||
p = file.length;
|
||||
}
|
||||
var ext = file.substring(p);
|
||||
var base = file.substring(0, p);
|
||||
var parts = base.match(/^(.*)_(\d{1,2})$/);
|
||||
if (parts) {
|
||||
base = parts[1];
|
||||
version = parseInt(parts[2]);
|
||||
}
|
||||
|
||||
var newname = dir + base + '_' + (version + 1) + ext;
|
||||
getUnusedFilename(storage, newname, callback);
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue