• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    Rust
  • License
    ISC License
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Idiomatic inotify wrapper for the Rust programming language

inotify-rs crates.io Documentation Rust

Idiomatic inotify wrapper for the Rust programming language.

extern crate inotify;


use std::env;

use inotify::{
    EventMask,
    WatchMask,
    Inotify,
};


fn main() {
    let mut inotify = Inotify::init()
        .expect("Failed to initialize inotify");

    let current_dir = env::current_dir()
        .expect("Failed to determine current directory");

    inotify
        .watches()
        .add(
            current_dir,
            WatchMask::MODIFY | WatchMask::CREATE | WatchMask::DELETE,
        )
        .expect("Failed to add inotify watch");

    println!("Watching current directory for activity...");

    let mut buffer = [0u8; 4096];
    loop {
        let events = inotify
            .read_events_blocking(&mut buffer)
            .expect("Failed to read inotify events");

        for event in events {
            if event.mask.contains(EventMask::CREATE) {
                if event.mask.contains(EventMask::ISDIR) {
                    println!("Directory created: {:?}", event.name);
                } else {
                    println!("File created: {:?}", event.name);
                }
            } else if event.mask.contains(EventMask::DELETE) {
                if event.mask.contains(EventMask::ISDIR) {
                    println!("Directory deleted: {:?}", event.name);
                } else {
                    println!("File deleted: {:?}", event.name);
                }
            } else if event.mask.contains(EventMask::MODIFY) {
                if event.mask.contains(EventMask::ISDIR) {
                    println!("Directory modified: {:?}", event.name);
                } else {
                    println!("File modified: {:?}", event.name);
                }
            }
        }
    }
}

Usage

Include it in your Cargo.toml:

[dependencies]
inotify = "0.10"

Please refer to the documentation and the example above, for information on how to use it in your code.

Please note that inotify-rs is a relatively low-level wrapper around the original inotify API. And, of course, it is Linux-specific, just like inotify itself. If you are looking for a higher-level and platform-independent file system notification library, please consider notify.

If you need to access inotify in a way that this wrapper doesn't support, consider using inotify-sys instead.

Documentation

The most important piece of documentation for inotify-rs is the API reference, as it contains a thorough description of the complete API, as well as examples.

Additional examples can be found in the examples directory.

Please also make sure to read the inotify man page. Inotify use can be hard to get right, and this low-level wrapper won't protect you from all mistakes.

License

Copyright (c) Hanno Braun and contributors

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

More Repositories

1

fornjot

Early-stage b-rep CAD kernel, written in the Rust programming language.
Rust
1,987
star
2

vndf-2016

Von Neumann Defense Force
Rust
119
star
3

stepper

Universal Stepper Motor Interface
Rust
104
star
4

3mf-rs

3MF (3D Manufacturing Format) support for Rust
Rust
33
star
5

ramp-maker

Stepper Acceleration Ramp Generator
Rust
28
star
6

kari

Kari, an embeddable programming language, written in and for Rust
Rust
28
star
7

embedded

I'm teaching myself embedded programming. This repository is where I put my code. There's also a blog.
Rust
27
star
8

rum

An experiment with Rust and Emscripten.
Python
20
star
9

rustecs

Entity Component System for Rust
Rust
20
star
10

rust-dwm1001

[DEPRECATED] This repository was merged with https://github.com/braun-embedded/rust-dw1000
Rust
14
star
11

caterpillar

An experimental project to create an interactive programming language.
Rust
14
star
12

embedded-test-stand

A test stand for firmware applications.
Rust
11
star
13

cnc-mill

Rust
10
star
14

inotify-sys

Low-level inotify bindings for the Rust programming language
Rust
6
star
15

rust-embedded-timeout-macros

Rust macros for working with timeouts on top of embedded-hal APIs
Rust
6
star
16

flott

Flott Meta Repository
Rust
5
star
17

notebooks

open source stationery
5
star
18

www.fornjot.app

The Fornjot website
HTML
4
star
19

fornjot-extra

Components of Fornjot that are no longer actively maintained. Pull requests still welcome!
Rust
4
star
20

ScalableDynamics

An experimental 2D physics library for games.
Scala
3
star
21

stepper-terminal

Manual testing tool and full application example for Stepper.
Rust
3
star
22

stuff

Stuff I'm working on that's too insignificant to live in a dedicated repository.
Rust
3
star
23

model-api

Proof of concept for a web API that can export 3MF files from parametric OpenSCAD models
Rust
3
star
24

braun-embedded.com

The Braun Embedded website
SCSS
2
star
25

pi-pico-examples

Embedded examples using the Raspberry Pi Pico.
Rust
2
star
26

prusa-mini-enclosure

Enclosure for my Prusa Mini
Python
2
star
27

vndf-2020

Von Neumann Defense Force - a game about spaceships
Rust
2
star
28

upstart

Unfinished game prototype written in JavaScript, using the HTML5 Canvas element.
JavaScript
2
star
29

probe-rs-arch

Experimental probe-rs Arch Linux package.
Shell
1
star
30

rust-gnat

Unofficial Rust Board Support Crate for the Tlera Corp Gnat
Shell
1
star
31

lpc845-example

Example program for the LPC845, written in Rust
Rust
1
star
32

my-boss

Software that tells me what to do and when to do it.
Rust
1
star
33

hannobraun

1
star
34

hanno.braun-odw.eu

My personal website
SCSS
1
star
35

MissileGame

Not really a game yet, but it's about missiles, so the name is at least half-correct.
Scala
1
star
36

vndf

Von Neumann Defense Force
Rust
1
star
37

ludus

A game about gladiators. Made for #bbg challenge 5 (https://github.com/hughfdjackson/bbgchallenge5).
CoffeeScript
1
star
38

gravity

Unfinished game prototype written in JavaScript, using the HTML5 Canvas element.
JavaScript
1
star