From 9120982bed86c53c80c35400a35fa0916f50e7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 27 May 2020 17:56:28 +0200 Subject: [PATCH] Fix watching symlinked paths with FSEvents. The events reported always use the canonical path, which broke the relative path logic. TO counter this, the canonical path is now determined explicitly. --- source/eventcore/drivers/posix/watchers.d | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/source/eventcore/drivers/posix/watchers.d b/source/eventcore/drivers/posix/watchers.d index d2fd2a0..ba9de14 100644 --- a/source/eventcore/drivers/posix/watchers.d +++ b/source/eventcore/drivers/posix/watchers.d @@ -228,14 +228,30 @@ final class FSEventsEventDriverWatchers(Events : EventDriverEvents) : EventDrive final override WatcherID watchDirectory(string path, bool recursive, FileChangesCallback on_change) @trusted { - import std.path : absolutePath; + import std.file : isSymlink, readLink; + import std.path : absolutePath, buildPath, buildNormalizedPath, dirName, pathSplitter; FSEventStreamContext ctx; ctx.info = () @trusted { return cast(void*)this; } (); + static string resolveSymlinks(string path) + { + string res; + foreach (ps; path.pathSplitter) { + if (!res.length) res = ps; + else res = buildPath(res, ps); + if (isSymlink(res)) { + res = readLink(res).absolutePath(dirName(res)); + } + } + return res.buildNormalizedPath; + } + string abspath; - try abspath = absolutePath(path); - catch (Exception e) assert(false, e.msg); + try abspath = resolveSymlinks(absolutePath(path)); + catch (Exception e) { + return WatcherID.invalid; + } if (m_handleCounter == 0) { m_handleCounter++;