handle symlinks for hot-reloading (nix) #121
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
on nix, using home-manager, we typically have config files as symlinks to nix store. this breaks the current implementation, as it will not detect anything has changed. nix store does not store mtime (because the result should be identical no matter when you build it).
this PR adds correct handling of the watcher, not just for nix, but in general:
if it is a symlink and the mtime changes, but it still points to the same target file and that file hasn't updated mtime, then we can ignore this because the config file hasn't changed, only the symlink.
likewise, if the symlink path changes (from a previous symlink in a chain), but the ultimate target is unchanged, we can ignore this.
we cannot ignore if the symlinks end up pointing to a completely different canonical path, then it's a different file entirely and we reload it.
we cannot ignore if the target file's mtime is modified. the config changed and we reload it.
if the path changes and the mtime, then we need to reload it even more than before.
if neither the canonical path, nor the mtime of config changed, then the config didn't change. doesn't matter what the symlinks do, it still points to the same target.