Skip to content

Commit

Permalink
Update fsevent dependencies and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed May 7, 2019
1 parent e90fd8d commit 336e4d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "notify"
version = "4.0.10"
version = "4.0.11"
authors = [
"Félix Saparelli <[email protected]>",
"Jorge Israel Peña <[email protected]>",
Expand Down Expand Up @@ -34,8 +34,8 @@ mio = "^0.6.15"
mio-extras = "^2.0.5"

[target.'cfg(target_os="macos")'.dependencies]
fsevent = "^0.2.17"
fsevent-sys = "^0.1.3"
fsevent = "0.4"
fsevent-sys = "2"

[target.'cfg(windows)'.dependencies]
winapi = "^0.3.5"
Expand Down
28 changes: 16 additions & 12 deletions src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ extern crate fsevent as fse;
use super::debounce::{Debounce, EventTx};
use super::{op, DebouncedEvent, Error, RawEvent, RecursiveMode, Result, Watcher};
use fsevent_sys::core_foundation as cf;
use fsevent_sys::fsevent as fs;
use fsevent_sys as fs;
use libc;
use std::collections::HashMap;
use std::convert::AsRef;
use std::ffi::CStr;
use std::mem::transmute;
use std::path::{Path, PathBuf};
use std::ptr;
use std::slice;
use std::str::from_utf8;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
use std::os::raw;

/// FSEvents-based `Watcher` implementation
pub struct FsEventWatcher {
Expand All @@ -51,19 +53,19 @@ unsafe impl Sync for FsEventWatcher {}

fn translate_flags(flags: fse::StreamFlags) -> op::Op {
let mut ret = op::Op::empty();
if flags.contains(fse::ITEM_XATTR_MOD) || flags.contains(fse::ITEM_CHANGE_OWNER) {
if flags.contains(fse::StreamFlags::ITEM_XATTR_MOD) || flags.contains(fse::StreamFlags::ITEM_CHANGE_OWNER) {
ret.insert(op::Op::CHMOD);
}
if flags.contains(fse::ITEM_CREATED) {
if flags.contains(fse::StreamFlags::ITEM_CREATED) {
ret.insert(op::Op::CREATE);
}
if flags.contains(fse::ITEM_REMOVED) {
if flags.contains(fse::StreamFlags::ITEM_REMOVED) {
ret.insert(op::Op::REMOVE);
}
if flags.contains(fse::ITEM_RENAMED) {
if flags.contains(fse::StreamFlags::ITEM_RENAMED) {
ret.insert(op::Op::RENAME);
}
if flags.contains(fse::ITEM_MODIFIED) {
if flags.contains(fse::StreamFlags::ITEM_MODIFIED) {
ret.insert(op::Op::WRITE);
}
ret
Expand Down Expand Up @@ -102,7 +104,7 @@ impl FsEventWatcher {

if let Some(runloop) = self.runloop {
unsafe {
let runloop = runloop as *mut libc::c_void;
let runloop = runloop as *mut raw::c_void;

while !CFRunLoopIsWaiting(runloop) {
thread::yield_now();
Expand All @@ -127,7 +129,8 @@ impl FsEventWatcher {
fn remove_path<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
let str_path = path.as_ref().to_str().unwrap();
unsafe {
let cf_path = cf::str_path_to_cfstring_ref(str_path);
let mut err: cf::CFErrorRef = ptr::null_mut();
let cf_path = cf::str_path_to_cfstring_ref(str_path, &mut err);

let mut to_remove = Vec::new();
for idx in 0..cf::CFArrayGetCount(self.paths) {
Expand Down Expand Up @@ -165,7 +168,8 @@ impl FsEventWatcher {
}
let str_path = path.as_ref().to_str().unwrap();
unsafe {
let cf_path = cf::str_path_to_cfstring_ref(str_path);
let mut err: cf::CFErrorRef = ptr::null_mut();
let cf_path = cf::str_path_to_cfstring_ref(str_path, &mut err);
cf::CFArrayAppendValue(self.paths, cf_path);
cf::CFRelease(cf_path);
}
Expand Down Expand Up @@ -218,7 +222,7 @@ impl FsEventWatcher {
let (rl_tx, rl_rx) = channel();

thread::spawn(move || {
let stream = dummy as *mut libc::c_void;
let stream = dummy as *mut raw::c_void;
unsafe {
let cur_runloop = cf::CFRunLoopGetCurrent();

Expand Down Expand Up @@ -294,7 +298,7 @@ pub unsafe extern "C" fn callback(
}
}

if flag.contains(fse::MUST_SCAN_SUBDIRS) {
if flag.contains(fse::StreamFlags::MUST_SCAN_SUBDIRS) {
event_tx.send(RawEvent {
path: None,
op: Ok(op::Op::RESCAN),
Expand All @@ -303,7 +307,7 @@ pub unsafe extern "C" fn callback(
}

if handle_event {
if flag.contains(fse::ITEM_RENAMED) {
if flag.contains(fse::StreamFlags::ITEM_RENAMED) {
if let Some(e) = rename_event {
if e.cookie == Some((id - 1) as u32) {
event_tx.send(e);
Expand Down

0 comments on commit 336e4d0

Please sign in to comment.