Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for recursive symlink following #132

Open
evanpurkhiser opened this issue Nov 5, 2017 · 3 comments
Open

Support for recursive symlink following #132

evanpurkhiser opened this issue Nov 5, 2017 · 3 comments

Comments

@evanpurkhiser
Copy link

evanpurkhiser commented Nov 5, 2017

If I add a symlink to a directory it would be awesome if it's tree could be watched as well.

I suspect this might be difficult to support in a cross compatible way without additional work. For the non-recursive linux inotify, it looks like it's just the addition of resolving the symlink in here:

notify/node.go

Lines 82 to 87 in 7e20c15

for _, fi := range fi {
if fi.Mode()&(os.ModeSymlink|os.ModeDir) == os.ModeDir {
name := filepath.Join(nd.Name, fi.Name())
stack = append(stack, nd.addchild(name, name[len(nd.Name)+1:]))
}
}

(would end up looking something like this)

for _, fi := range fi {
	isLink := fi.Mode()&os.ModeSymlink == os.ModeSymlink

	if fi.IsDir() || isLink {
		name := filepath.Join(nd.Name, fi.Name())

		if isLink {
			name, err = filepath.EvalSymlinks(name)
			if err != nil {
				return err
			}
		}

		stack = append(stack, nd.addchild(name, name[len(nd.Name)+1:]))
	}
}
@rjeczalik
Copy link
Owner

If I add a symlink to a directory it would be awesome if it's tree could be watched as well.

This intentionally is not possible - os watchers (inotify, FSEvents) report events using canonical paths.

If a symlink to other directory tree was added then notify would start to report events coming from other tree that was not explicitly watched by a user, which may create confusion. The current approach is to leave decision whether to watch symlinked tree or not to the user.

Unrelated - from you snippet I learned there's a filepath.EvalSymlinks function. We could use it instead of the canonical() one that notify currently implements on its own.

@evanpurkhiser
Copy link
Author

evanpurkhiser commented Nov 5, 2017

The current approach is to leave decision whether to watch symlinked tree or not to the user.

There's no type of configuration for this though correct? The user would have to attach watchers to any symlinks added into the tree.

If a symlink to other directory tree was added then notify would start to report events coming from other tree that was not explicitly watched by a user, which may create confusion.

As far as I could tell, from my brief experiment, it actually reported paths relative to the root watched directory

@rjeczalik
Copy link
Owner

There's no type of configuration for this though correct?

Unfortunately no, current API was built with minimal configuration in mind, in fact there's no configuration at all. Right now we regret a bit this decision and we were previously planning to introduce (backward-compatible) v2 API with actual configuration.

As far as I could tell, from my brief experiment, it actually reported paths relative to the root watched directory.

I'm speaking off the top of my head, so I might be wrong. The relative paths might be true for inotify, but not for FSEvents and ReadDirChangesW (macOS / windows).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants