axodotdev / oranda

🎁 generate beautiful landing pages for your developer tools

Home Page:https://opensource.axo.dev/oranda/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File watcher recognizes only first file change

homeworkprod opened this issue Β· comments

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.
commented

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)?

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.

commented

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

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.
commented

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.

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.

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.