TagSpaces is an offline, open source, document manager with tagging support
moving createDirectoryIndex to utils.js
uggrock82e0db6f0919
diff --git a/data/chromium/chrome.api.js b/data/chromium/chrome.api.jsindex bb3af5382..3c141fa52 100644--- a/data/chromium/chrome.api.js+++ b/data/chromium/chrome.api.js@@ -83,24 +83,6 @@ define(function(require, exports, module) {}- function createDirectoryIndex(dirPath) {- TSCORE.showWaitingDialog($.i18n.t("ns.common:waitDialogDiectoryIndexing"));-- var directoryIndex = [];- TSCORE.Utils.walkDirectory(dirPath, {recursive: true}, function(fileEntry) {- directoryIndex.push(fileEntry);- }).then(- function(entries) {- TSPOSTIO.createDirectoryIndex(directoryIndex);- },- function(err) {- console.warn("Error creating index: " + err);- }- ).catch(function() {- TSCORE.hideWaitingDialog();- });- }-function createDirectoryTree(dirPath) {TSCORE.showAlertDialog("Creating directory not supported.");//var directoyTree = generateDirectoryTree(dirPath);@@ -292,7 +274,6 @@ define(function(require, exports, module) {exports.focusWindow = focusWindow;exports.checkNewVersion = checkNewVersion;- exports.createDirectoryIndex = createDirectoryIndex;exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;diff --git a/data/ext/perspectiveGrid/perspectiveUI.js b/data/ext/perspectiveGrid/perspectiveUI.jsindex 90d15e863..400465a1a 100644--- a/data/ext/perspectiveGrid/perspectiveUI.js+++ b/data/ext/perspectiveGrid/perspectiveUI.js@@ -198,7 +198,7 @@ define(function(require, exports, module) {});$("#" + this.extensionID + "IncludeSubDirsButton").on("click", function() {- TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);+ TSCORE.Utils.createDirectoryIndex(TSCORE.currentPath);});$("#" + this.extensionID + "TagButton").on("click", function() {diff --git a/data/ext/perspectiveHealth/extension.js b/data/ext/perspectiveHealth/extension.jsindex e066285b2..99fa2a288 100644--- a/data/ext/perspectiveHealth/extension.js+++ b/data/ext/perspectiveHealth/extension.js@@ -165,7 +165,7 @@ define(function(require, exports, module) {.click(function() {vizMode = "quantYours";TSCORE.showLoadingAnimation();- TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);+ TSCORE.Utils.createDirectoryIndex(TSCORE.currentPath);}).prepend( "<i class='fa fa-tasks' />"))diff --git a/data/ext/perspectiveList/perspectiveUI.js b/data/ext/perspectiveList/perspectiveUI.jsindex 1e2b58675..11f9e605d 100644--- a/data/ext/perspectiveList/perspectiveUI.js+++ b/data/ext/perspectiveList/perspectiveUI.js@@ -45,6 +45,7 @@ define(function(require, exports, module) {});$("#" + this.extensionID + "IncludeSubDirsButton").on("click", function() {+ // TODO remove from all places e.g. config/*if (TSCORE.Config.getShowWarningRecursiveScan()) {TSCORE.showConfirmDialog($.i18n.t("ns.perspectiveList:includeSubdirsTitleConfirm"),@@ -62,7 +63,7 @@ define(function(require, exports, module) {$("#" + self.extensionID + "IncludeSubDirsButton").prop('disabled', true);TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);}*/- TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);+ TSCORE.Utils.createDirectoryIndex(TSCORE.currentPath);});$("#" + this.extensionID + "DeleteSelectedFilesButton").on("click", function() {diff --git a/data/mozilla/mozilla.api.js b/data/mozilla/mozilla.api.jsindex 25ad1145f..1e31c3ea0 100644--- a/data/mozilla/mozilla.api.js+++ b/data/mozilla/mozilla.api.js@@ -39,13 +39,6 @@ define(function(require, exports, module) {console.log("Saving setting as native mozilla preference failed!");}break;- case "indexDirectory":- if (message.success) {- TSPOSTIO.createDirectoryIndex(message.content);- } else {- console.error("Indexing directory failed");- }- break;case "createDirectoryTree":if (message.success) {console.log("Directory tree: " + JSON.stringify(message.content));@@ -185,18 +178,6 @@ define(function(require, exports, module) {});}- function createDirectoryIndex(dirPath) {- console.log("Creating directory index for: " + dirPath);- var event = document.createEvent('CustomEvent');- event.initCustomEvent("addon-message", true, true, {- "detail": {- "command": "createDirectoryIndex",- "path": dirPath- }- });- document.documentElement.dispatchEvent(event);- }-function createDirectoryTree(dirPath) {console.log("Creating directory tree for: " + dirPath);var event = document.createEvent('CustomEvent');@@ -493,7 +474,6 @@ define(function(require, exports, module) {exports.focusWindow = focusWindow;exports.checkNewVersion = checkNewVersion;- exports.createDirectoryIndex = createDirectoryIndex;exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.jsindex 7beff1003..b9891dcce 100644--- a/data/node-webkit/node-webkit.api.js+++ b/data/node-webkit/node-webkit.api.js@@ -257,45 +257,62 @@ define(function(require, exports, module) {TSPOSTIO.createDirectoryTree(directoyTree);}- function createDirectoryIndex(dirPath) {- TSCORE.showWaitingDialog($.i18n.t("ns.common:waitDialogDiectoryIndexing"));+ function listDirectoryPromiseAsync(path) {+ console.time("listDirectoryPromise");+ return new Promise(function(resolve, reject) {+ var statEntriesPromises = [];+ fs.readdir(path, function(error, entries) {+ if (error) {+ console.log("Error listing directory " + path);+ resolve([]); // returning results even if any promise fails+ }- var directoryIndex = [];- TSCORE.Utils.walkDirectory(dirPath, {recursive: true}, function(fileEntry) {- directoryIndex.push(fileEntry);- }).then(- function(entries) {- TSPOSTIO.createDirectoryIndex(directoryIndex);- },- function(err) {- console.warn("Error creating index: " + err);- }- ).catch(function() {- TSCORE.hideWaitingDialog();+ if (entries) {+ entries.forEach(function(entry) {+ statEntriesPromises.push(getPropertiesPromise(path + TSCORE.dirSeparator + entry));+ });+ Promise.all(statEntriesPromises).then(function(enhancedEntries) {+ console.timeEnd("listDirectoryPromise");+ resolve(enhancedEntries);+ }, function(err) {+ resolve([]); // returning results even if any promise fails+ });+ }+ });});-}-function listDirectoryPromise(path) {+ console.time("listDirectoryPromise");return new Promise(function(resolve, reject) {- var statEntriesPromises = [];+ var enhancedEntries = [];+ var entryPath;+ var stats;+ var eentry;fs.readdir(path, function(error, entries) {if (error) {console.log("Error listing directory " + path);- resolve(statEntriesPromises);- } else {- if (entries) {- entries.forEach(function(entry) {- statEntriesPromises.push(getPropertiesPromise(path + TSCORE.dirSeparator + entry));- });- }- Promise.all(statEntriesPromises).then(function(enhancedEntries) {- resolve(enhancedEntries);- }, function(err) {- resolve(statEntriesPromises);- //reject("At least one get file properties failed.");+ resolve(enhancedEntries); // returning results even if any promise fails+ }++ if (entries) {+ entries.forEach(function(entry) {+ entryPath = path + TSCORE.dirSeparator + entry;+ try {+ stats = fs.statSync(entryPath);+ eentry = {};+ eentry.name = entry;+ eentry.isFile = stats.isFile();+ eentry.size = stats.size;+ eentry.lmdt = stats.mtime;+ eentry.path = entryPath;+ enhancedEntries.push(eentry);+ } catch(e) {+ console.warn("Error getting stats for " + entryPath);+ }});+ console.timeEnd("listDirectoryPromise");+ resolve(enhancedEntries);}});});@@ -327,6 +344,7 @@ define(function(require, exports, module) {if (err) {resolve(false);}+if (stats) {var entry = {};entry.name = path.substring(path.lastIndexOf(TSCORE.dirSeparator) + 1, path.length);@@ -335,8 +353,6 @@ define(function(require, exports, module) {entry.lmdt = stats.mtime;entry.path = path;resolve(entry);- } else {- resolve(false);}});});@@ -638,7 +654,6 @@ define(function(require, exports, module) {exports.focusWindow = focusWindow;exports.checkNewVersion = checkNewVersion;- exports.createDirectoryIndex = createDirectoryIndex;exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;diff --git a/data/web/web.api.js b/data/web/web.api.jsindex 0d9176e1f..bafa4d023 100644--- a/data/web/web.api.js+++ b/data/web/web.api.js@@ -91,24 +91,6 @@ define(function(require, exports, module) {}- function createDirectoryIndex(dirPath) {- TSCORE.showWaitingDialog($.i18n.t("ns.common:waitDialogDiectoryIndexing"));-- var directoryIndex = [];- TSCORE.Utils.walkDirectory(dirPath, {recursive: true}, function(fileEntry) {- directoryIndex.push(fileEntry);- }).then(- function(entries) {- TSPOSTIO.createDirectoryIndex(directoryIndex);- },- function(err) {- console.warn("Error creating index: " + err);- }- ).catch(function() {- TSCORE.hideWaitingDialog();- });- }-function createDirectoryTree(dirPath) {console.log("Creating directory index for: " + dirPath);TSCORE.showLoadingAnimation();@@ -394,7 +376,6 @@ define(function(require, exports, module) {exports.focusWindow = focusWindow;exports.checkNewVersion = checkNewVersion;- exports.createDirectoryIndex = createDirectoryIndex;exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;