From 5def14e3bbbf17ccbe375aa8d2bfca6f1909e2a1 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 23 Apr 2024 11:01:20 +0530 Subject: [PATCH] Skip indexing non-existent folders on Desktop app --- src/interface/desktop/main.js | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/interface/desktop/main.js b/src/interface/desktop/main.js index eb3ceb37..2e9f7989 100644 --- a/src/interface/desktop/main.js +++ b/src/interface/desktop/main.js @@ -121,24 +121,36 @@ function isSupportedFileType(filePath) { } function processDirectory(filesToPush, folder) { - const files = fs.readdirSync(folder.path, { withFileTypes: true }); + try { + const files = fs.readdirSync(folder.path, { withFileTypes: true }); - for (const file of files) { - const filePath = path.join(file.path, file.name || ''); - // Skip hidden files and folders - if (file.name.startsWith('.')) { - continue; + for (const file of files) { + const filePath = path.join(file.path, file.name || ''); + // Skip hidden files and folders + if (file.name.startsWith('.')) { + continue; + } + // Add supported files to index + if (file.isFile() && isSupportedFileType(filePath)) { + console.log(`Add ${file.name} in ${file.path} for indexing`); + filesToPush.push(filePath); + } + // Recursively process subdirectories + if (file.isDirectory()) { + processDirectory(filesToPush, {'path': filePath}); + } } - // Add supported files to index - if (file.isFile() && isSupportedFileType(filePath)) { - console.log(`Add ${file.name} in ${file.path} for indexing`); - filesToPush.push(filePath); - } - // Recursively process subdirectories - if (file.isDirectory()) { - processDirectory(filesToPush, {'path': filePath}); + } catch (err) { + if (err.code === 'EACCES') { + console.error(`Access denied to ${folder.path}`); + } else if (err.code === 'ENOENT') { + console.error(`${folder.path} does not exist`); + } else { + console.error(`An error occurred while reading directory: ${error.message}`); } + return; } + } function pushDataToKhoj (regenerate = false) {