Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fsevent dependencies #195

Merged
merged 2 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,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]
kernel32-sys = "^0.2.1"
Expand Down
30 changes: 18 additions & 12 deletions src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ extern crate fsevent as fse;
use super::debounce::{Debounce, EventTx};
use super::{op, Config, Error, Event, RawEvent, RecursiveMode, Result, Watcher};
use crossbeam_channel::{unbounded, Receiver, Sender};
use fsevent_sys as fs;
use fsevent_sys::core_foundation as cf;
use fsevent_sys::fsevent as fs;
use libc;
use std::collections::HashMap;
use std::convert::AsRef;
use std::ffi::CStr;
use std::mem::transmute;
use std::os::raw;
use std::path::{Path, PathBuf};
use std::ptr;
use std::slice;
use std::str::from_utf8;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -51,19 +53,21 @@ 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::METADATA);
}
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 +106,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 +131,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 +170,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 @@ -219,7 +225,7 @@ impl FsEventWatcher {
let (rl_tx, rl_rx) = unbounded();

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 @@ -300,7 +306,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 @@ -309,7 +315,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