Skip to content

Lib only loaded once on Linux #11

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

Closed
Ryan1729 opened this issue Mar 21, 2017 · 11 comments
Closed

Lib only loaded once on Linux #11

Ryan1729 opened this issue Mar 21, 2017 · 11 comments

Comments

@Ryan1729
Copy link

When I try the example on my Linux (Ubuntu 16.04) machine, it works properly after the first change to test_shared.rs, but it does nothing if I change it a second time.

if I add println!("{:?}", file); just above this line and then run the example, changing 42 to 24 I get the following output when I run cargo build:

Value 42
Event { path: Some("target/debug/libtest_shared.so"), op: Ok(CHMOD) }
Value 24
Event { path: Some("target/debug/libtest_shared.so"), op: Ok(REMOVE) }
Value 24
Event { path: Some("target/debug/libtest_shared.so"), op: Ok(IGNORED) }
Value 24

But as mentioned before, if I try to change 24 to something else, the output just remains Value 24.

I'm not sure if this is the cause of the problem but I found this in the latest version of the notify library's docs:

Linux

When a watched file or directory is removed, its watch gets destroyed and no new events will be sent.

@emoon
Copy link
Owner

emoon commented Mar 21, 2017

Hi,

Thanks for the report. I tested this on Linux before but maybe something has changed so it doesn't work anymore.

Currently I'm a bit busy so I won't have time to look into the issue but I will try to get around doing it a bit later.

Cheers!

@Ryan1729
Copy link
Author

Fair enough, we all have lives.

Just for anyone else who has problems I managed to get something working for my use case based on this article.

@Ryan1729
Copy link
Author

Ryan1729 commented Oct 26, 2017

(this is a follow on from this thread. Since the link I made in the post above has broken I figure I should add some context here. Specifically, Rust 1.20.0 broke my workaround above, I reported it in this issue)

I now have a messy, but working proof-of-concept example that works (on my machine) here. The method comes from a suggestion in the Rust issue I reported and the basic idea is that separate versions of the library are compiled under distinct names. I haven't done extensive testing but it appears that the --crate-name parameter needs to be distinct for each version of the library as well, and that appears to be why putting the different versions in different folders isn't doing the trick.

Unfortunately I haven't found a good way, (as opposed to my messy method) to do this from a cargo build script, so I'm pursuing other options. Specifically I'm looking for something that won't require me to specify dependencies of the reloaded crate in the build script as well as the Cargo.toml.

@emoon
Copy link
Owner

emoon commented Oct 26, 2017

I will try to investigate more on my side. What I'm doing is that I load the shared object from a separate location from where it was generated so it should work. I also make sure I can read the file correct after it's being generated but I will take a closer look here what may cause it.

@emoon
Copy link
Owner

emoon commented Oct 27, 2017

@Ryan1729 which OS are you on? I would like try to to repro it.

@Ryan1729
Copy link
Author

Ryan1729 commented Oct 27, 2017 via email

@emoon
Copy link
Owner

emoon commented Oct 27, 2017

Cool. Thanks!

@Neopallium
Copy link
Contributor

@Ryan1729 @emoon Fixed in PR #14.

The issue is that inotify is watching the file's inode. When the file is deleted the inode is gone. When a new file is created it will get a new inode.

@runbmp
Copy link

runbmp commented Aug 27, 2019

Would you consider releasing a new version to crates.io to include this update?

@emoon
Copy link
Owner

emoon commented Aug 28, 2019

Yes! I will fix this when I get back home today.

@emoon
Copy link
Owner

emoon commented Aug 28, 2019

Version 0.4.0 has now been released!

@emoon emoon closed this as completed Apr 9, 2023
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

4 participants