From 066a44df518df552d5a1f7fa70c1921fb34b0385 Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Fri, 17 Oct 2014 18:43:45 +0000
Subject: [PATCH] add two utility methods to CLOUDFS

---
 client/library/library_cloudfs.js |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/client/library/library_cloudfs.js b/client/library/library_cloudfs.js
index 4df6392..bd5c0f8 100644
--- a/client/library/library_cloudfs.js
+++ b/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) {

--
Gitblit v1.9.3