* * @param {import('./models/Library')} library
(library)
| 127 | * @param {import('./models/Library')} library |
| 128 | */ |
| 129 | updateLibrary(library) { |
| 130 | if (this.disabled) return |
| 131 | |
| 132 | const libwatcher = this.libraryWatchers.find((lib) => lib.id === library.id) |
| 133 | if (libwatcher) { |
| 134 | // Library watcher was disabled |
| 135 | if (library.settings.disableWatcher) { |
| 136 | Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher disabled`) |
| 137 | libwatcher.watcher.close() |
| 138 | this.libraryWatchers = this.libraryWatchers.filter((lw) => lw.id !== libwatcher.id) |
| 139 | return |
| 140 | } |
| 141 | |
| 142 | libwatcher.name = library.name |
| 143 | |
| 144 | // If any folder paths were added or removed then re-init watcher |
| 145 | const folderPaths = library.libraryFolders.map((f) => f.path) |
| 146 | const pathsToAdd = folderPaths.filter((path) => !libwatcher.paths.includes(path)) |
| 147 | const pathsRemoved = libwatcher.paths.filter((path) => !folderPaths.includes(path)) |
| 148 | if (pathsToAdd.length || pathsRemoved.length) { |
| 149 | Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`) |
| 150 | |
| 151 | libwatcher.watcher.close() |
| 152 | this.libraryWatchers = this.libraryWatchers.filter((lw) => lw.id !== libwatcher.id) |
| 153 | this.buildLibraryWatcher(library) |
| 154 | } |
| 155 | } else if (!library.settings.disableWatcher) { |
| 156 | // Library watcher was enabled |
| 157 | Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher enabled - initializing`) |
| 158 | this.buildLibraryWatcher(library) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * |
no test coverage detected