Skip to content

Commit

Permalink
Merge pull request #35 from musicinmybrain/inotify-0.11
Browse files Browse the repository at this point in the history
Update inotify dependency from 0.10.0 to 0.11.0
  • Loading branch information
SoptikHa2 authored Jan 12, 2025
2 parents eff3598 + 31a8079 commit b51373c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 24 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ anyhow = "1.0.65"
cfg-if = "1.0.0"

[target.'cfg(target_os = "linux")'.dependencies]
inotify = "0.10.0" # Watch files and auto-reload on changes
inotify = "0.11.0" # Watch files and auto-reload on changes

[target.'cfg(any(target_os="macos", target_os="dragonfly", target_os="freebsd", target_os="netbsd", target_os="openbsd"))'.dependencies]
kqueue = "1.0.6" # Watch files and auto-reload on changes
18 changes: 4 additions & 14 deletions src/file_watcher/inotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub struct FileWatchImpl {

impl FileWatcherImpl {
pub fn init() -> Result<FileWatcherImpl> {
let ino = match Inotify::init() {
Ok(i) => i,
Err(msg) => return Result::Err(msg),
};
let ino = Inotify::init()?;

Result::Ok(FileWatcherImpl {
inotify: ino,
Expand All @@ -30,15 +27,11 @@ impl FileWatcherImpl {
pub fn add_watch(&mut self, file_path: &PathBuf) -> Result<&FileWatchImpl> {
let mask: inotify::WatchMask = inotify::WatchMask::MODIFY;

let watch = match self.inotify.watches().add(file_path, mask) {
Ok(w) => w,
Err(msg) => return Result::Err(msg),
};

let watch = self.inotify.watches().add(file_path, mask)?;
let fw = FileWatchImpl { descriptor: watch };

self.watches.push(fw);
return Result::Ok(self.watches.last().unwrap());
Result::Ok(self.watches.last().unwrap())
}

pub fn rm_watch(&mut self, fw: &FileWatchImpl) -> Result<()> {
Expand All @@ -62,10 +55,7 @@ impl FileWatcherImpl {

pub fn any_events(&mut self) -> Result<bool> {
let mut buffer = [0; 1024];
let events = match self.inotify.read_events(&mut buffer) {
Result::Ok(ev) => ev,
Result::Err(err) => return Result::Err(err),
};
let events = self.inotify.read_events(&mut buffer)?;

Result::Ok(events.count() > 0)
}
Expand Down
5 changes: 1 addition & 4 deletions src/file_watcher/kqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ pub struct FileWatchImpl {

impl FileWatcherImpl {
pub fn init() -> Result<FileWatcherImpl> {
let kq = match KQueue::new() {
Ok(value) => value,
Err(msg) => return Result::Err(msg),
};
let kq = KQueue::new()?;

Ok(FileWatcherImpl {
kq,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl<'a> Tui<'a> {
}
}

impl<'a> UiAgent for Tui<'a> {
impl UiAgent for Tui<'_> {
fn start(mut self) -> Result<ApplicationExitReason> {
// Setup event loop and input handling
let (tx, rx) = mpsc::channel();
Expand Down

0 comments on commit b51373c

Please sign in to comment.