From 55cd1cccee2b32a18d9d2503431b456532ab044b Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 4 Feb 2022 18:10:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Do=20not=20watch=20files=20that?= =?UTF-8?q?=20do=20not=20exist=20(#123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon-common/Core/Logger.swift | 4 ++-- phpmon/Domain/Watcher/PhpConfigWatcher.swift | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/phpmon-common/Core/Logger.swift b/phpmon-common/Core/Logger.swift index 87f2e81..8616528 100644 --- a/phpmon-common/Core/Logger.swift +++ b/phpmon-common/Core/Logger.swift @@ -27,13 +27,13 @@ class Log { static func err(_ item: Any) { if Verbosity.error.isApplicable() { - print(item) + print("[ERR] \(item)") } } static func warn(_ item: Any) { if Verbosity.warning.isApplicable() { - print(item) + print("[WRN] \(item)") } } diff --git a/phpmon/Domain/Watcher/PhpConfigWatcher.swift b/phpmon/Domain/Watcher/PhpConfigWatcher.swift index e97cfe5..7468339 100644 --- a/phpmon/Domain/Watcher/PhpConfigWatcher.swift +++ b/phpmon/Domain/Watcher/PhpConfigWatcher.swift @@ -47,6 +47,11 @@ class PhpConfigWatcher { } func addWatcher(for url: URL, eventMask: DispatchSource.FileSystemEvent, behaviour: FSWatcherBehaviour = .reloadsMenu) { + if !Filesystem.fileExists(url.path) { + Log.warn("No watcher was created for \(url.path) because the requested file does not exist.") + return + } + let watcher = FSWatcher(for: url, eventMask: eventMask, parent: self, behaviour: behaviour) self.watchers.append(watcher) }