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

File watcher recognizes only first file change #517

Open
homeworkprod opened this issue Jul 4, 2023 · 7 comments
Open

File watcher recognizes only first file change #517

homeworkprod opened this issue Jul 4, 2023 · 7 comments

Comments

@homeworkprod
Copy link

Using oranda dev (version 0.1.0) inside of a Rust project path only seems to detect the first change to a file, but not subsequent changes.

How I can reproduce it:

  • File README.md and oranda.json exist in the same path.
  • Run orange dev.
  • Change oranda.json (to a different theme). Project gets rebuild.
  • Change oranda.json again. Project is not rebuild, no new command output.
  • Change README.md. Project gets rebuild.
  • Change README.md again. Project is not rebuild, no new command output.
@shadows-withal
Copy link
Contributor

hey! i can't reproduce this, here's my command log output:

log output
lu@koishi weird-oranda-test > oranda dev
↪ >o_o< INFO: Found 3 paths to watch, starting watch...
↪ >o_o< DEBUG: Files watched: ["/Users/lu/Projects/Checkouts/weird-oranda-test/README.md", "./oranda.json", "/Users/lu/Projects/Checkouts/weird-oranda-test/Cargo.toml"]
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
✓ >o_o< SUCCESS: Your project is available at: http://127.0.0.1:7979
↪ >o_o< INFO: Path(s) ["/Users/lu/Projects/Checkouts/weird-oranda-test/oranda.json"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
↪ >o_o< INFO: Path(s) ["/Users/lu/Projects/Checkouts/weird-oranda-test/oranda.json"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
↪ >o_o< INFO: Path(s) ["/Users/lu/Projects/Checkouts/weird-oranda-test/README.md"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
↪ >o_o< INFO: Path(s) ["/Users/lu/Projects/Checkouts/weird-oranda-test/README.md"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
↪ >o_o< INFO: Path(s) ["/Users/lu/Projects/Checkouts/weird-oranda-test/README.md"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.

maybe you're running into some file-descriptor-related trouble? we use notify under the hood, maybe you can try seeing if you run into the same kinds of issues using something like cargo-watch (which also uses notify)?

@homeworkprod
Copy link
Author

homeworkprod commented Jul 4, 2023

I tried it again and this time changing README.md triggered every time as expected, but changes to (using different editors, also during the same orange dev run) and even deleting and recreating oranda.json was not detected. I wonder if it could be specific to that one file(name) for some reason.

I don't usually use cargo-watch and don't have it at the ready, so testing that will have to wait for another day.

One bit that (according to prior experience) could be important: I have taken the binary from the tarball download, but not precompiled itself. Maybe the issue only appears with that pre-built binary.

@shadows-withal
Copy link
Contributor

there shouldn't be a difference between those two versions. can you paste your log output (specifically the "Files watched" line)?

@homeworkprod
Copy link
Author

homeworkprod commented Jul 4, 2023

For the record: In the case I remember, the binary in question was built on a CI with a different version of some (system) library than expected and that resulted in a bug.

If I find the time I might build oranda from source myself and see how the resulting binary behaves.

Here is the log:

$ oranda dev
↪ >o_o< INFO: Found 3 paths to watch, starting watch...
↪ >o_o< DEBUG: Files watched: ["/home/user/projects/project/README.md", "./oranda.json", "/home/user/projects/project/Cargo.toml"]
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
✓ >o_o< SUCCESS: Your project is available at: http://127.0.0.1:7979
# --- Editing and saving `oranda.json` for the first time.
↪ >o_o< INFO: Path(s) ["/home/user/projects/project/./oranda.json"] changed, rebuilding...
↪ >o_o< INFO: Running build...
↪ >o_o< INFO: Building components: artifacts
✓ >o_o< SUCCESS: Your site build is located in `public`.
# --- Editing and saving `oranda.json` for the second time.
# --- Editing and saving `oranda.json` for the third time.

@shadows-withal
Copy link
Contributor

In any case, this sounds more like something related to the library we use for file watching (https://github.com/notify-rs/notify), so maybe it's worth filing a bug there? All we do on oranda's side is listen to events from that library, so it shouldn't really happen according to our usage.

@homeworkprod
Copy link
Author

It could be related to the way vim writes backups; see notify-rs/notify#394. A recommendation there is to watch the whole directory. The way the library is used is still in the scope of this project.

@CosmicHorrorDev
Copy link

Stumbled on this issue...

I recently dealt with what I imagine is this same issue in another program. The gist is that some editors may rename/remove files on save which can bork watching depending on how you handle it. I haven't dug into how oranda handles events from the file watcher, but the way that I fixed it for the other project was to .unwatch() the old file and re-.watch() the new file on removal/rename events

https://github.com/trimental/inlyne/blob/312c9ee229a8156945c1a6d2a317346ea92c9a88/src/watcher/mod.rs#L106-L117

This is documented in the notify crate (although this seems to be a common issue to run into still. It feels like switching to the "new" file on rename/removal is the common desired case)

https://docs.rs/notify/latest/notify/event/enum.EventKind.html#variant.Remove

...

Some editors also trigger Remove events when saving files as they may opt for removing (or renaming) the original then creating a new file in-place.

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

No branches or pull requests

4 participants