emscripten Humble Cloud interface
Edward Rudd
2014-10-17 066a44df518df552d5a1f7fa70c1921fb34b0385

add two utility methods to CLOUDFS

  • listFilesByScope to list by scope (allow easier access to list files)
  • clearFilesByScope to allow clearing out files in a certain scope.
1 files modified
50 ■■■■■ changed files
client/library/library_cloudfs.js 50 ●●●●● patch | view | raw | blame | history
client/library/library_cloudfs.js
@@ -271,6 +271,56 @@
            callback(this.error);
          };
        },
        listFilesByScope: function(scope, listCB) {
            CLOUDFS.getDB(function(err, db) {
                if (err) listCB(err);
                var transaction = db.transaction([CLOUDFS.DB_STORE_NAME], 'readonly');
                transaction.onerror = function() { listCB(this.error); };
                var store = transaction.objectStore(CLOUDFS.DB_STORE_NAME);
                var index = store.index('scope');
                var entries = [];
                index.openCursor(IDBKeyRange.only(scope)).onsuccess = function(event) {
                    var cursor = event.target.result;
                    if (!cursor) {
                          return listCB(null, entries);
                    }
                    if (FS.isFile(cursor.value.mode)) {
                        entries.push(cursor.value.path);
                    }
                    cursor.continue();
                };
            });
        },
        clearFilesByScope: function(scope, oncomplete) {
            CLOUDFS.getDB(function(err, db) {
                if (err) oncomplete(err);
                var transaction = db.transaction([CLOUDFS.DB_STORE_NAME], 'readwrite');
                transaction.onerror = function() { oncomplete(this.error); };
                var store = transaction.objectStore(CLOUDFS.DB_STORE_NAME);
                var index = store.index('scope');
                var entries = [];
                index.openKeyCursor(IDBKeyRange.only(scope)).onsuccess = function(event) {
                    var cursor = event.target.result;
                    if (cursor) {
                        store.delete(cursor.primaryKey);
                        cursor.continue();
                    } else {
                        oncomplete(null);
                    }
                };
            });
        },
        // Getting list of entities
        getLocalSet: function(mount, callback) {
            function isRealDir(p) {