From 719a2e01d8f7aba9895604fa9ca244c33990bf49 Mon Sep 17 00:00:00 2001 From: Tim Morley Date: Wed, 4 Dec 2019 21:40:57 +0000 Subject: [PATCH] Ability to exclude directories, and config to choose them. --- backend/model/threading/DiskMangerWorker.ts | 47 +++++++++++++++++++ common/config/private/IPrivateConfig.ts | 2 + common/config/private/PrivateConfigClass.ts | 4 +- .../indexing/indexing.settings.component.html | 30 ++++++++++++ .../indexing/indexing.settings.component.ts | 16 +++++++ frontend/app/ui/settings/settings.service.ts | 4 +- 6 files changed, 101 insertions(+), 2 deletions(-) diff --git a/backend/model/threading/DiskMangerWorker.ts b/backend/model/threading/DiskMangerWorker.ts index ba59c8b4..9ee661bb 100644 --- a/backend/model/threading/DiskMangerWorker.ts +++ b/backend/model/threading/DiskMangerWorker.ts @@ -57,6 +57,50 @@ export class DiskMangerWorker { return path.basename(name); } + public static excludeDir(name: string,relativeDirectoryName: string, absoluteDirectoryName: string) { + const absoluteName=path.normalize(path.join(absoluteDirectoryName,name)); + const relativeName=path.normalize(path.join(relativeDirectoryName,name)); + + + console.log("----- Starting exlude dir -----"); + console.log("name %s",name); + console.log("absoluteDirectoryName %s",absoluteDirectoryName); + console.log("absoluteName %s",absoluteName); + console.log("relativeDirectoryName %s",relativeDirectoryName); + console.log("relativeName %s",relativeName); + console.log("Config.Server.indexing.excludeFolderList %s",Config.Server.indexing.excludeFolderList); + + for (let j = 0; j < Config.Server.indexing.excludeFolderList.length; j++) { + const exclude=Config.Server.indexing.excludeFolderList[j]; + console.log("trying dir %s",exclude); + + if (exclude.startsWith('/')) { + if (exclude==absoluteName) { + return true; + } + } else if (exclude.includes('/')) { + if (path.normalize(exclude)==relativeName) { + return true; + } + } else { + if (exclude==name) { + return true; + } + } + } + + for (let j = 0; j < Config.Server.indexing.excludeFileList.length; j++) { + const exclude=Config.Server.indexing.excludeFileList[j]; + console.log("trying file %s",exclude); + + if (fs.existsSync(path.join(absoluteName,exclude))) { + return true; + } + } + + return false; + } + public static scanDirectory(relativeDirectoryName: string, maxPhotos: number = null, photosOnly: boolean = false): Promise { return new Promise((resolve, reject) => { relativeDirectoryName = this.normalizeDirPath(relativeDirectoryName); @@ -90,6 +134,9 @@ export class DiskMangerWorker { if (photosOnly === true) { continue; } + if (DiskMangerWorker.excludeDir(file,relativeDirectoryName,absoluteDirectoryName)) { + continue; + } const d = await DiskMangerWorker.scanDirectory(path.join(relativeDirectoryName, file), Config.Server.indexing.folderPreviewSize, true ); diff --git a/common/config/private/IPrivateConfig.ts b/common/config/private/IPrivateConfig.ts index f96a5446..6b8ff96d 100644 --- a/common/config/private/IPrivateConfig.ts +++ b/common/config/private/IPrivateConfig.ts @@ -54,6 +54,8 @@ export interface IndexingConfig { folderPreviewSize: number; cachedFolderTimeout: number; // Do not rescans the folder if seems ok reIndexingSensitivity: ReIndexingSensitivity; + excludeFolderList: string[] + excludeFileList: string[] } export interface ThreadingConfig { diff --git a/common/config/private/PrivateConfigClass.ts b/common/config/private/PrivateConfigClass.ts index c025d447..4e56005d 100644 --- a/common/config/private/PrivateConfigClass.ts +++ b/common/config/private/PrivateConfigClass.ts @@ -57,7 +57,9 @@ export class PrivateConfigClass extends PublicConfigClass implements IPrivateCon indexing: { folderPreviewSize: 2, cachedFolderTimeout: 1000 * 60 * 60, - reIndexingSensitivity: ReIndexingSensitivity.low + reIndexingSensitivity: ReIndexingSensitivity.low, + excludeFolderList: [], + excludeFileList: [] }, duplicates: { listingLimit: 1000 diff --git a/frontend/app/ui/settings/indexing/indexing.settings.component.html b/frontend/app/ui/settings/indexing/indexing.settings.component.html index 2adbb212..99181d2b 100644 --- a/frontend/app/ui/settings/indexing/indexing.settings.component.html +++ b/frontend/app/ui/settings/indexing/indexing.settings.component.html @@ -49,6 +49,36 @@ +
+ +
+ + + Folders to exclude from indexing
+ ';' separated strings. If an entry starts with '/' it is treated as an absolute path. If it doesn't start with '/' but contains a '/', the path is relative to the image directory. If it doesn't contain a '/', any folder with this name will be excluded. +
+
+
+ +
+ +
+ + + FFiles that mark a folder to be excluded from indexing
+ ';' separated strings. Any folder that contains a file with this name will be excluded from indexing. +
+
+
+