From 2fbdfec0c0a3f5da64764e7821e84db30b664e49 Mon Sep 17 00:00:00 2001 From: Marcus <56945030+maspio@users.noreply.github.com> Date: Mon, 11 Dec 2023 13:03:28 +0100 Subject: [PATCH] feat(Local File Trigger Node): Add polling option typically good to watch network files/folders (#7942) Adding more chokidar options to watch files/folders especially usePolling typically good to watch network volumes. Inspired by [https://github.com/n8n-io/n8n/pull/4914/files](https://github.com/n8n-io/n8n/pull/4914/files) --- .../LocalFileTrigger/LocalFileTrigger.node.ts | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/nodes-base/nodes/LocalFileTrigger/LocalFileTrigger.node.ts b/packages/nodes-base/nodes/LocalFileTrigger/LocalFileTrigger.node.ts index 65b698d0be..3b9dce008d 100644 --- a/packages/nodes-base/nodes/LocalFileTrigger/LocalFileTrigger.node.ts +++ b/packages/nodes-base/nodes/LocalFileTrigger/LocalFileTrigger.node.ts @@ -125,6 +125,13 @@ export class LocalFileTrigger implements INodeType { placeholder: 'Add Option', default: {}, options: [ + { + displayName: 'Await Write Finish', + name: 'awaitWriteFinish', + type: 'boolean', + default: false, + description: 'Whether to wait until files finished writing to avoid partially read', + }, { displayName: 'Include Linked Files/Folders', name: 'followSymlinks', @@ -142,7 +149,13 @@ export class LocalFileTrigger implements INodeType { description: 'Files or paths to ignore. The whole path is tested, not just the filename. Supports Anymatch- syntax.', }, - + { + displayName: 'Ignore Existing Files/Folders', + name: 'ignoreInitial', + type: 'boolean', + default: true, + description: 'Whether to ignore existing files/folders to not trigger an event', + }, { displayName: 'Max Folder Depth', name: 'depth', @@ -180,6 +193,14 @@ export class LocalFileTrigger implements INodeType { default: -1, description: 'How deep into the folder structure to watch for changes', }, + { + displayName: 'Use Polling', + name: 'usePolling', + type: 'boolean', + default: false, + description: + 'Whether to use polling for watching. Typically necessary to successfully watch files over a network.', + }, ], }, ], @@ -200,12 +221,15 @@ export class LocalFileTrigger implements INodeType { const watcher = watch(path, { ignored: options.ignored === '' ? undefined : options.ignored, persistent: true, - ignoreInitial: true, + ignoreInitial: + options.ignoreInitial === undefined ? true : (options.ignoreInitial as boolean), followSymlinks: options.followSymlinks === undefined ? true : (options.followSymlinks as boolean), depth: [-1, undefined].includes(options.depth as number) ? undefined : (options.depth as number), + usePolling: options.usePolling as boolean, + awaitWriteFinish: options.awaitWriteFinish as boolean, }); const executeTrigger = (event: string, pathString: string) => {