Giter Site home page Giter Site logo

Comments (3)

Atul9 avatar Atul9 commented on July 17, 2024 1

@hannobraun I would like to take this up. I have opened up a PR for this - #130

from inotify-rs.

emarcotte avatar emarcotte commented on July 17, 2024

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.

hannobraun avatar hannobraun commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.