Skip to content

Commit

Permalink
Merge pull request #238 from JohnTitor/bump-deps
Browse files Browse the repository at this point in the history
Some cleanups
  • Loading branch information
JohnTitor committed Jan 7, 2020
2 parents e2214e4 + 7868791 commit 812817d
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 208 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ matrix:

allow_failures:
- env: CARGO_CLIPPY=1
- os: osx # tests on macOS are very fragile, ignore status for now

before_install:
- set -e
Expand All @@ -76,8 +77,8 @@ script:
elif [[ ! -z "$CARGO_CLIPPY" ]]; then
cargo clippy
else
cargo test
cargo test --release
cargo test --no-fail-fast
cargo test --release --no-fail-fast
fi
after_script: set +e
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.0.15 (2020)

- DEPS: Update inotify to 0.7.
- DEPS(DEV): Replace tempdir with tempfile since tempdir is deprecated.

## 4.0.14 (2019-10-17)

- FIX: Fix deadlock in debouncer. [#210], [`6ccf3e8d`]
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ filetime = "0.2.5"
walkdir = "^2.0.1"

[target.'cfg(target_os="linux")'.dependencies]
inotify = { version = "^0.6.1", default-features = false }
inotify = { version = "^0.7", default-features = false }
mio = "^0.6.15"
mio-extras = "^2.0.5"

Expand All @@ -41,7 +41,7 @@ fsevent-sys = "2"
winapi = { version = "0.3.8", features = ["fileapi", "handleapi", "ioapiset", "minwinbase", "synchapi", "winbase", "winnt"] }

[dev-dependencies]
tempdir = "^0.3.4"
tempfile = "3"

[features]
timing_tests = []
Expand Down
18 changes: 9 additions & 9 deletions src/debounce/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl Debounce {
let timer = WatchTimer::new(tx.clone(), operations_buffer.clone(), delay);

Debounce {
tx: tx,
tx,
operations_buffer: operations_buffer,
rename_path: None,
rename_cookie: None,
timer: timer,
timer,
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ impl Debounce {
}

if let Ok(mut op_buf) = self.operations_buffer.lock() {
if let Some(&(ref operation, _, _)) = op_buf.get(&path) {
if let Some(&(operation, _, _)) = op_buf.get(&path) {
op = remove_repeated_events(op, operation);
} else if op.contains(op::Op::CREATE | op::Op::REMOVE) {
if path.exists() {
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Debounce {
}

// if the file has been renamed before, use original name as from_path
let use_from_path = from_from_path.or(self.rename_path.clone());
let use_from_path = from_from_path.or_else(|| self.rename_path.clone());

let &mut (ref mut operation, ref mut from_path, ref mut timer_id) =
op_buf.entry(path.clone()).or_insert((None, None, None));
Expand Down Expand Up @@ -442,7 +442,7 @@ impl Debounce {
}

// remember for deletion
remove_path = Some(path.clone());
remove_path = Some(path);
}

// change to remove event
Expand All @@ -455,14 +455,14 @@ impl Debounce {
None => {
*operation = Some(op::Op::REMOVE);
let _ = self.tx.send(DebouncedEvent::NoticeRemove(path.clone()));
restart_timer(timer_id, path.clone(), &mut self.timer);
restart_timer(timer_id, path, &mut self.timer);
}

// file has been renamed before, change to remove event /
// no need to emit NoticeRemove because the file has been renamed before
Some(op::Op::RENAME) => {
*operation = Some(op::Op::REMOVE);
restart_timer(timer_id, path.clone(), &mut self.timer);
restart_timer(timer_id, path, &mut self.timer);
}

// multiple remove events are possible if the file/directory
Expand All @@ -484,8 +484,8 @@ impl Debounce {
}
}

fn remove_repeated_events(mut op: op::Op, prev_op: &Option<op::Op>) -> op::Op {
if let Some(prev_op) = *prev_op {
fn remove_repeated_events(mut op: op::Op, prev_op: Option<op::Op>) -> op::Op {
if let Some(prev_op) = prev_op {
if prev_op.intersects(op::Op::CREATE | op::Op::WRITE | op::Op::CHMOD | op::Op::RENAME) {
op.remove(op::Op::CREATE);
}
Expand Down
6 changes: 3 additions & 3 deletions src/debounce/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ScheduleWorker {
// events Mutex, and retry after yielding.
match self.operations_buffer.try_lock() {
Ok(op_buf) => break (events, op_buf),
Err(::std::sync::TryLockError::Poisoned {..}) => return None,
Err(::std::sync::TryLockError::Poisoned { .. }) => return None,
Err(::std::sync::TryLockError::WouldBlock) => {
// drop the lock before yielding to give other threads a chance to complete
// their work.
Expand All @@ -64,7 +64,7 @@ impl ScheduleWorker {
fn fire_event(
&self,
ev: ScheduledEvent,
op_buf: &mut impl DerefMut<Target = OperationsBufferInner>
op_buf: &mut impl DerefMut<Target = OperationsBufferInner>,
) {
let ScheduledEvent { path, .. } = ev;
if let Some((op, from_path, _)) = op_buf.remove(&path) {
Expand Down Expand Up @@ -180,7 +180,7 @@ impl WatchTimer {
self.events.lock().unwrap().push_back(ScheduledEvent {
id: self.counter,
when: Instant::now() + self.delay,
path: path,
path,
});

self.new_event_trigger.notify_one();
Expand Down
8 changes: 5 additions & 3 deletions src/fsevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ 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 as fs;
use fsevent_sys::core_foundation as cf;
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;
Expand All @@ -30,7 +31,6 @@ 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 @@ -53,7 +53,9 @@ unsafe impl Sync for FsEventWatcher {}

fn translate_flags(flags: fse::StreamFlags) -> op::Op {
let mut ret = op::Op::empty();
if flags.contains(fse::StreamFlags::ITEM_XATTR_MOD) || flags.contains(fse::StreamFlags::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::StreamFlags::ITEM_CREATED) {
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,19 @@ pub mod op {
/// Multiple actions may be delivered in a single event.
pub struct Op: u32 {
/// Attributes changed
const CHMOD = 0b0000001;
const CHMOD = 0b000_0001;
/// Created
const CREATE = 0b0000010;
const CREATE = 0b000_0010;
/// Removed
const REMOVE = 0b0000100;
const REMOVE = 0b000_0100;
/// Renamed
const RENAME = 0b0001000;
const RENAME = 0b000_1000;
/// Written
const WRITE = 0b0010000;
const WRITE = 0b001_0000;
/// File opened for writing was closed
const CLOSE_WRITE = 0b0100000;
const CLOSE_WRITE = 0b010_0000;
/// Directories need to be rescanned
const RESCAN = 0b1000000;
const RESCAN = 0b100_0000;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PollWatcher {
watches: Arc::new(Mutex::new(HashMap::new())),
open: Arc::new(RwLock::new(true)),
};
let event_tx = EventTx::Raw { tx: tx };
let event_tx = EventTx::Raw { tx };
p.run(Duration::from_millis(delay as u64), event_tx);
Ok(p)
}
Expand Down Expand Up @@ -89,7 +89,7 @@ impl PollWatcher {
match paths.insert(
watch.clone(),
PathData {
mtime: mtime,
mtime,
last_check: current_time,
},
) {
Expand Down Expand Up @@ -133,7 +133,7 @@ impl PollWatcher {
match paths.insert(
path.to_path_buf(),
PathData {
mtime: mtime,
mtime,
last_check: current_time,
},
) {
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Watcher for PollWatcher {
match fs::metadata(path) {
Err(e) => {
self.event_tx.send(RawEvent {
path: Some(watch.clone()),
path: Some(watch),
op: Err(Error::Io(e)),
cookie: None,
});
Expand All @@ -228,15 +228,15 @@ impl Watcher for PollWatcher {
paths.insert(
watch.clone(),
PathData {
mtime: mtime,
mtime,
last_check: current_time,
},
);
watches.insert(
watch,
WatchData {
is_recursive: recursive_mode.is_recursive(),
paths: paths,
paths,
},
);
} else {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl Watcher for PollWatcher {
paths.insert(
path.to_path_buf(),
PathData {
mtime: mtime,
mtime,
last_check: current_time,
},
);
Expand All @@ -278,7 +278,7 @@ impl Watcher for PollWatcher {
watch,
WatchData {
is_recursive: recursive_mode.is_recursive(),
paths: paths,
paths,
},
);
}
Expand Down
30 changes: 15 additions & 15 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ impl ReadDirectoryChangesServer {
let server = ReadDirectoryChangesServer {
rx: action_rx,
event_tx: Arc::new(Mutex::new(event_tx)),
meta_tx: meta_tx,
cmd_tx: cmd_tx,
meta_tx,
cmd_tx,
watches: HashMap::new(),
wakeup_sem: wakeup_sem,
wakeup_sem,
};
server.run();
});
Expand All @@ -116,7 +116,7 @@ impl ReadDirectoryChangesServer {
Action::Unwatch(path) => self.remove_watch(path),
Action::Stop => {
stopped = true;
for (_, ws) in &self.watches {
for ws in self.watches.values() {
stop_watch(ws, &self.meta_tx);
}
break;
Expand Down Expand Up @@ -199,7 +199,7 @@ impl ReadDirectoryChangesServer {
// every watcher gets its own semaphore to signal completion
let semaphore =
unsafe { synchapi::CreateSemaphoreW(ptr::null_mut(), 0, 1, ptr::null_mut()) };
if semaphore == ptr::null_mut() || semaphore == INVALID_HANDLE_VALUE {
if semaphore.is_null() || semaphore == INVALID_HANDLE_VALUE {
unsafe {
handleapi::CloseHandle(handle);
}
Expand All @@ -211,7 +211,7 @@ impl ReadDirectoryChangesServer {
dir: dir_target,
file: wf,
complete_sem: semaphore,
is_recursive: is_recursive,
is_recursive,
};
let ws = WatchState {
dir_handle: handle,
Expand Down Expand Up @@ -244,8 +244,8 @@ fn stop_watch(ws: &WatchState, meta_tx: &Sender<MetaEvent>) {

fn start_read(rd: &ReadData, event_tx: Arc<Mutex<EventTx>>, handle: HANDLE) {
let mut request = Box::new(ReadDirectoryRequest {
event_tx: event_tx,
handle: handle,
event_tx,
handle,
buffer: [0u8; BUF_SIZE as usize],
data: rd.clone(),
});
Expand Down Expand Up @@ -433,20 +433,20 @@ impl ReadDirectoryChangesWatcher {

let wakeup_sem =
unsafe { synchapi::CreateSemaphoreW(ptr::null_mut(), 0, 1, ptr::null_mut()) };
if wakeup_sem == ptr::null_mut() || wakeup_sem == INVALID_HANDLE_VALUE {
if wakeup_sem.is_null() || wakeup_sem == INVALID_HANDLE_VALUE {
return Err(Error::Generic(
"Failed to create wakeup semaphore.".to_owned(),
));
}

let event_tx = EventTx::Raw { tx: tx };
let event_tx = EventTx::Raw { tx };

let action_tx = ReadDirectoryChangesServer::start(event_tx, meta_tx, cmd_tx, wakeup_sem);

Ok(ReadDirectoryChangesWatcher {
tx: action_tx,
cmd_rx: cmd_rx,
wakeup_sem: wakeup_sem,
cmd_rx,
wakeup_sem,
})
}

Expand All @@ -459,7 +459,7 @@ impl ReadDirectoryChangesWatcher {

let wakeup_sem =
unsafe { synchapi::CreateSemaphoreW(ptr::null_mut(), 0, 1, ptr::null_mut()) };
if wakeup_sem == ptr::null_mut() || wakeup_sem == INVALID_HANDLE_VALUE {
if wakeup_sem.is_null() || wakeup_sem == INVALID_HANDLE_VALUE {
return Err(Error::Generic(
"Failed to create wakeup semaphore.".to_owned(),
));
Expand All @@ -474,8 +474,8 @@ impl ReadDirectoryChangesWatcher {

Ok(ReadDirectoryChangesWatcher {
tx: action_tx,
cmd_rx: cmd_rx,
wakeup_sem: wakeup_sem,
cmd_rx,
wakeup_sem,
})
}

Expand Down
Loading

0 comments on commit 812817d

Please sign in to comment.