From e25789893dcf708e7e6c3584f462bc2652d7b65e Mon Sep 17 00:00:00 2001 From: tims <0xtimsb@gmail.com> Date: Sat, 4 Jan 2025 05:42:20 +0530 Subject: [PATCH] linux: Fix issue where relative symlinks were not being watched using fs watch (#22608) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #22607 Symlinks can be absolute or relative. When using [stow](https://www.gnu.org/software/stow/) to manage dotfiles, it creates relative symlinks to the target files. For example: - Original file: `/home/tims/dotfiles/zed/setting.json` - Symlink path: `/home/tims/.config/zed/setting.json` - Target path (relative to symlink): `../../dotfiles/zed/setting.json` The issue is that you can’t watch the symlink path because it’s relative and doesn't include the base path it is relative to. This PR fixes that by converting relative symlink paths to absolute paths. - Absolute path (after parent join): `/home/tims/.config/zed/../../dotfiles/zed/setting.json` (This works) - Canonicalized path (from absolute path): `/home/tims/dotfiles/zed/setting.json` (This works too, just more cleaner) Release Notes: - Fix issue where items on the Welcome page could not be toggled on Linux when using Stow to manage dotfiles --- crates/fs/src/fs.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rs index be9f3f4e0f..2cf633c021 100644 --- a/crates/fs/src/fs.rs +++ b/crates/fs/src/fs.rs @@ -720,7 +720,16 @@ impl Fs for RealFs { } // Check if path is a symlink and follow the target parent - if let Some(target) = self.read_link(&path).await.ok() { + if let Some(mut target) = self.read_link(&path).await.ok() { + // Check if symlink target is relative path, if so make it absolute + if target.is_relative() { + if let Some(parent) = path.parent() { + target = parent.join(target); + if let Ok(canonical) = self.canonicalize(&target).await { + target = canonical; + } + } + } watcher.add(&target).ok(); if let Some(parent) = target.parent() { watcher.add(parent).log_err();