From: Svjatoslav Agejenko Date: Sat, 18 Oct 2025 07:24:03 +0000 (+0300) Subject: Scan newly created directories for existing files. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=6c80c0984f0ff7f2a65402969d1a54387e216e49;p=alyverkko-cli.git Scan newly created directories for existing files. --- diff --git a/doc/index.org b/doc/index.org index e354ed1..cc81405 100644 --- a/doc/index.org +++ b/doc/index.org @@ -343,7 +343,7 @@ Adjust `prompt-dir` and `config-file` to match your setup." (push (match-string 1) models)))) (if (file-exists-p prompt-dir) - (let* ((files (directory-files prompt-dir t "\\`[^.].*\\.txt\\'")) + (let* ((files (directory-files prompt-dir t "\\`[^.].*\\.yaml\\'")) (aliases (mapcar #'file-name-base files))) (if aliases (let* ((selected-alias (completing-read "Select prompt alias: " aliases)) diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java index 8c37285..711e15c 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/mail_correspondant/MailCorrespondentCommand.java @@ -375,44 +375,58 @@ public class MailCorrespondentCommand implements Command { */ private void processDetectedFilesystemEvents(WatchKey key) throws IOException { Path dir = (Path) key.watchable(); - for (WatchEvent event : key.pollEvents()) { WatchEvent.Kind kind = event.kind(); - if (kind != ENTRY_CREATE && kind != ENTRY_MODIFY && kind != ENTRY_DELETE) { continue; } - @SuppressWarnings("unchecked") WatchEvent ev = (WatchEvent) event; Path filename = ev.context(); Path fullPath = dir.resolve(filename); - System.out.printf("Event: %s – %s%n", kind.name(), fullPath); - if (kind == ENTRY_DELETE) { // Remove any existing tasks for this file removeTasksForFile(fullPath); continue; } - // Handle directory creation if (Files.isDirectory(fullPath)) { if (kind == ENTRY_CREATE) { + // Register the new directory and its subdirectories for monitoring registerAllSubdirectories(fullPath); + // Scan the new directory for existing files to process + Files.walk(fullPath) + .filter(path -> { + try { + return Files.isRegularFile(path) && !Files.isHidden(path); + } catch (IOException e) { + System.err.println("Failed to check if file is hidden: " + path + " - " + e.getMessage()); + return false; // Skip files that cause errors + } + }) + .forEach(path -> { + try { + considerFileForQueuing(path); + } catch (IOException e) { + System.err.println("Failed to process file in new directory: " + path + " - " + e.getMessage()); + } + }); } continue; } - // Handle file events if (kind == ENTRY_MODIFY) { // Remove existing tasks for this file before adding new ones removeTasksForFile(fullPath); } - // Check if it's a regular, non-hidden file and needs processing - if (Files.isRegularFile(fullPath) && !Files.isHidden(fullPath)) { - considerFileForQueuing(fullPath); + try { + if (Files.isRegularFile(fullPath) && !Files.isHidden(fullPath)) { + considerFileForQueuing(fullPath); + } + } catch (IOException e) { + System.err.println("Failed to check file: " + fullPath + " - " + e.getMessage()); } } }