linux: Fix issue where relative symlinks were not being watched using fs watch (#22608)
tims
created
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
@@ -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();