Comments (3)
@hannobraun I would like to take this up. I have opened up a PR for this - #130
from inotify-rs.
It seems like (unless I'm completely misunderstanding) the workaround demonstrated in this example only really works if:
1- Your buffer size is <= 32
2- You never get events with > 32
For instance, this dummy program:
let stream = inotify3
.event_stream([0; 32])
.map_err(|e| println!("inotify error: {:?}", e))
.for_each(move |event| {
println!("E: {:?}", event);
Ok(())
});
tokio::run(stream);
Gets
inotify error: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }
When a file name is too long.
Seems like a limitation on arrays (check https://doc.rust-lang.org/std/primitive.array.html notes on array sizes as they related to AsMut/AsRef).
The best work around I've found for this is to include the bytes module as suggested in the original pull request. This seems to work so far:
let mut inotify = Inotify::init().unwrap();
// TODO: http://man7.org/linux/man-pages/man7/inotify.7.html
// sizeof(struct inotify_event) + NAME_MAX + 1
let mut buf = BytesMut::with_capacity(4096);
for _ in 0..4096 {
buf.put(0u8);
}
inotify.add_watch("/home/emarcotte/Projects/fwatch", WatchMask::ALL_EVENTS)
.expect("Couldn't add watch");
println!("Running...");
let stream = inotify
.event_stream(buf)
.map_err(|e| println!("inotify error: {:?}", e))
.for_each(move |event| {
println!("E: {:?}", event);
Ok(())
});
tokio::run(stream);
I guess all of this is to say, it might still be worth having a pretty decent example floating around to show how this works with larger file names/tokio integration/etc.
It might be nice to figure out how to provide the max size of the inotify event in order to build reasonably sized buffers. Of course, I have no idea how to do that yet :)
from inotify-rs.
Thanks for your comment, @emarcotte! I agree with everything you said.
It seems like (unless I'm completely misunderstanding) the workaround demonstrated in this example only really works if:
1- Your buffer size is <= 32
2- You never get events with > 32
Yes, that is to be expected. I'm hoping that will care of itself soon-ish, once support for const generics lands in the compiler, and is then used to implement those traits for any array size.
The best work around I've found for this is to include the bytes module as suggested in the original pull request. This seems to work so far:
Thanks for the example. Really neat! A Vec<u8>
should work too, although I haven't tried it.
I guess all of this is to say, it might still be worth having a pretty decent example floating around to show how this works with larger file names/tokio integration/etc.
Totally agree, but I think the best place for such an examples (or better, multiple such examples) is in the API documentation of the event_stream
method. I've opened a follow-up issue, where I've linked to your comment. Hopefully someone will pick that up.
It might be nice to figure out how to provide the max size of the inotify event in order to build reasonably sized buffers. Of course, I have no idea how to do that yet :)
Yes, it would be great if someone figured out what a reasonable buffer size is, and added that information to the API documentation.
from inotify-rs.
Related Issues (20)
- Cutting a release for #171 and #173 HOT 1
- Consider addressing buffer alignment in a more robust way HOT 2
- `Inotify::event_stream` is error-prone HOT 2
- Add separate API for adding/removing watches
- Implement ToOwned for `Event<&'a OsStr>` HOT 9
- Consider using cargo clippy in test workflows HOT 1
- Consider increasing the buffer size for the stream example HOT 2
- Using Inotify::read_events in async context HOT 3
- Is it possible to get full path from Event? HOT 3
- Update minimum supported Rust version HOT 1
- duplicate event reports HOT 9
- Async runtime agnostic. HOT 2
- Bump MSRV to at least 1.56 HOT 1
- documentation for `Inotify::watches` is broken in 0.10.1 HOT 4
- Invalid argument when trying to monitor /dev/snd HOT 2
- Update dependency `bitflags` to v2? HOT 3
- docs.rs links from inotify to inotify_sys are broken HOT 4
- Fail CI build on doc warnings
- Example in API reference is broken HOT 6
- Recursive Directory Watching HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inotify-rs.