diff options
Diffstat (limited to 'devtools/server/actors')
-rw-r--r-- | devtools/server/actors/storage.js | 109 |
1 files changed, 52 insertions, 57 deletions
diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index f4fbbd8c3..497051e57 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -2,8 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* globals StopIteration */ - "use strict"; const {Cc, Ci, Cu, CC} = require("chrome"); @@ -1733,7 +1731,9 @@ StorageActors.createActor({ if (!DebuggerServer.isInChildProcess) { this.backToChild = (func, rv) => rv; this.clearDBStore = indexedDBHelpers.clearDBStore; - this.gatherFilesOrFolders = indexedDBHelpers.gatherFilesOrFolders; + this.findIDBPathsForHost = indexedDBHelpers.findIDBPathsForHost; + this.findSqlitePathsForHost = indexedDBHelpers.findSqlitePathsForHost; + this.findStorageTypePaths = indexedDBHelpers.findStorageTypePaths; this.getDBMetaData = indexedDBHelpers.getDBMetaData; this.getDBNamesForHost = indexedDBHelpers.getDBNamesForHost; this.getNameFromDatabaseFile = indexedDBHelpers.getNameFromDatabaseFile; @@ -2011,35 +2011,23 @@ var indexedDBHelpers = { // idb/1556056096MeysDaabta.sqlite // - PathToProfileDir/storage/temporary/http+++www.example.com/ // idb/1556056096MeysDaabta.sqlite - // // The subdirectory inside the storage folder is determined by the storage // type: // - default: { storage: "default" } or not specified. // - permanent: { storage: "persistent" }. // - temporary: { storage: "temporary" }. - let sqliteFiles = yield this.gatherFilesOrFolders(storagePath, path => { - if (path.endsWith(".sqlite")) { - let { components } = OS.Path.split(path); - let isIDB = components[components.length - 2] === "idb"; - - return isIDB; - } - return false; - }); + let sqliteFiles = yield this.findSqlitePathsForHost(storagePath, sanitizedHost); for (let file of sqliteFiles) { let splitPath = OS.Path.split(file).components; let idbIndex = splitPath.indexOf("idb"); - let name = splitPath[idbIndex - 1]; let storage = splitPath[idbIndex - 2]; let relative = file.substr(profileDir.length + 1); - if (name.startsWith(sanitizedHost)) { - files.push({ - file: relative, - storage: storage === "permanent" ? "persistent" : storage - }); - } + files.push({ + file: relative, + storage: storage === "permanent" ? "persistent" : storage + }); } if (files.length > 0) { @@ -2057,48 +2045,55 @@ var indexedDBHelpers = { }), /** - * Gather together all of the files in path and pass each path through a - * validation function. - * - * @param {String} - * Path in which to begin searching. - * @param {Function} - * Validation function, which checks each file path. If this function - * Returns true the file path is kept. - * - * @returns {Array} - * An array of file paths. + * Find all SQLite files that hold IndexedDB data for a host, such as: + * storage/temporary/http+++www.example.com/idb/1556056096MeysDaabta.sqlite */ - gatherFilesOrFolders: Task.async(function* (path, validationFunc) { - let files = []; - let iterator; - let paths = [path]; - - while (paths.length > 0) { - try { - iterator = new OS.File.DirectoryIterator(paths.pop()); - - for (let child in iterator) { - child = yield child; - - path = child.path; - - if (child.isDir) { - paths.push(path); - } else if (validationFunc(path)) { - files.push(path); - } - } - } catch (ex) { - // Ignore StopIteration to prevent exiting the loop. - if (ex != StopIteration) { - throw ex; + findSqlitePathsForHost: Task.async(function* (storagePath, sanitizedHost) { + let sqlitePaths = []; + let idbPaths = yield this.findIDBPathsForHost(storagePath, sanitizedHost); + for (let idbPath of idbPaths) { + let iterator = new OS.File.DirectoryIterator(idbPath); + yield iterator.forEach(entry => { + if (!entry.isDir && entry.path.endsWith(".sqlite")) { + sqlitePaths.push(entry.path); } + }); + iterator.close(); + } + return sqlitePaths; + }), + + /** + * Find all paths that hold IndexedDB data for a host, such as: + * storage/temporary/http+++www.example.com/idb + */ + findIDBPathsForHost: Task.async(function* (storagePath, sanitizedHost) { + let idbPaths = []; + let typePaths = yield this.findStorageTypePaths(storagePath); + for (let typePath of typePaths) { + let idbPath = OS.Path.join(typePath, sanitizedHost, "idb"); + if (yield OS.File.exists(idbPath)) { + idbPaths.push(idbPath); } } - iterator.close(); + return idbPaths; + }), - return files; + /** + * Find all the storage types, such as "default", "permanent", or "temporary". + * These names have changed over time, so it seems simpler to look through all types + * that currently exist in the profile. + */ + findStorageTypePaths: Task.async(function* (storagePath) { + let iterator = new OS.File.DirectoryIterator(storagePath); + let typePaths = []; + yield iterator.forEach(entry => { + if (entry.isDir) { + typePaths.push(entry.path); + } + }); + iterator.close(); + return typePaths; }), /** |