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

Add IN_CLOSE_WRITE Event #93

Merged
merged 1 commit into from
Aug 14, 2016
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
5 changes: 4 additions & 1 deletion src/inotify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ impl mio::Handler for INotifyHandler {
if event.is_modify() {
o.insert(op::WRITE);
}
if event.is_close_write() {
o.insert(op::CLOSE_WRITE);
}
if event.is_attrib() {
o.insert(op::CHMOD);
}
Expand Down Expand Up @@ -253,7 +256,7 @@ impl INotifyHandler {
}

fn add_single_watch(&mut self, path: PathBuf, is_recursive: bool, watch_self: bool) -> Result<()> {
let mut flags = flags::IN_ATTRIB | flags::IN_CREATE | flags::IN_DELETE |
let mut flags = flags::IN_ATTRIB | flags::IN_CREATE | flags::IN_DELETE | flags::IN_CLOSE_WRITE |
flags::IN_MODIFY | flags::IN_MOVED_FROM | flags::IN_MOVED_TO;

if watch_self {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ pub mod op {
const RENAME = 0b001000,
/// Written
const WRITE = 0b010000,
/// Written
const CLOSE_WRITE = 0b100000,
/// Directories need to be rescanned
const RESCAN = 0b100000,
const RESCAN = 0b1000000,
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion tests/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ fn create_file() {
assert_eq!(inflate_events(recv_events(&rx)), vec![
(tdir.mkpath("file1"), op::CREATE, None),
]);
} else if cfg!(target_os="windows") {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::CREATE, None)
]);
} else {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::CREATE, None),
(tdir.mkpath("file1"), op::CLOSE_WRITE, None)
]);
}
}
Expand All @@ -77,9 +82,14 @@ fn write_file() {
assert_eq!(inflate_events(recv_events(&rx)), vec![
(tdir.mkpath("file1"), op::CREATE | op::WRITE, None), // excessive create event
]);
} else if cfg!(target_os="windows") {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::WRITE, None)
]);
} else {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::WRITE, None),
(tdir.mkpath("file1"), op::CLOSE_WRITE, None)
]);
}
}
Expand Down Expand Up @@ -297,8 +307,9 @@ fn create_rename_overwrite_file() {
assert_eq!(cookies.len(), 1);
assert_eq!(actual, vec![
(tdir.mkpath("file1a"), op::CREATE, None),
(tdir.mkpath("file1a"), op::CLOSE_WRITE, None),
(tdir.mkpath("file1a"), op::RENAME, Some(cookies[0])),
(tdir.mkpath("file1b"), op::RENAME, Some(cookies[0])),
(tdir.mkpath("file1b"), op::RENAME, Some(cookies[0]))
]);
}
}
Expand Down
62 changes: 52 additions & 10 deletions tests/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,18 @@ fn watch_recursive_create_directory() {
recv_events(&rx)
};

assert_eq!(actual, vec![
(tdir.mkpath("dir1"), op::CREATE, None),
(tdir.mkpath("dir1/file1"), op::CREATE, None)
]);
if cfg!(target_os="linux") {
assert_eq!(actual, vec![
(tdir.mkpath("dir1"), op::CREATE, None),
(tdir.mkpath("dir1/file1"), op::CREATE, None),
(tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None)
]);
} else {
assert_eq!(actual, vec![
(tdir.mkpath("dir1"), op::CREATE, None),
(tdir.mkpath("dir1/file1"), op::CREATE, None)
]);
}
}

#[test]
Expand Down Expand Up @@ -253,6 +261,17 @@ fn watch_recursive_move() {
(tdir.mkpath("dir1b"), op::RENAME, Some(cookies[0])),
(tdir.mkpath("dir1b/file2"), op::CREATE, None)
]);
} else if cfg!(target_os="linux") {
let cookies = extract_cookies(&actual);
assert_eq!(cookies.len(), 1);
assert_eq!(actual, vec![
(tdir.mkpath("dir1a/file1"), op::CREATE, None),
(tdir.mkpath("dir1a/file1"), op::CLOSE_WRITE, None),
(tdir.mkpath("dir1a"), op::RENAME, Some(cookies[0])),
(tdir.mkpath("dir1b"), op::RENAME, Some(cookies[0])),
(tdir.mkpath("dir1b/file2"), op::CREATE, None),
(tdir.mkpath("dir1b/file2"), op::CLOSE_WRITE, None)
]);
} else {
let cookies = extract_cookies(&actual);
assert_eq!(cookies.len(), 1);
Expand Down Expand Up @@ -383,10 +402,18 @@ fn watch_nonrecursive() {
"dir2/file2",
]);

assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("dir2"), op::CREATE, None),
(tdir.mkpath("file0"), op::CREATE, None)
]);
if cfg!(target_os="linux") {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("dir2"), op::CREATE, None),
(tdir.mkpath("file0"), op::CREATE, None),
(tdir.mkpath("file0"), op::CLOSE_WRITE, None)
]);
} else {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("dir2"), op::CREATE, None),
(tdir.mkpath("file0"), op::CREATE, None)
]);
}
}

#[test]
Expand All @@ -412,6 +439,11 @@ fn watch_file() {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::CREATE | op::WRITE, None) // excessive write create
]);
} else if cfg!(target_os="linux") {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::WRITE, None),
(tdir.mkpath("file1"), op::CLOSE_WRITE, None)
]);
} else {
assert_eq!(recv_events(&rx), vec![
(tdir.mkpath("file1"), op::WRITE, None)
Expand Down Expand Up @@ -941,9 +973,14 @@ fn self_rename_directory() {
if cfg!(target_os="macos") {
// macos doesn't watch files, but paths
assert_eq!(actual, vec![]);
} else {
} else if cfg!(target_os="linux") {
assert_eq!(actual, vec![
(tdir.mkpath("dir1/file1"), op::CREATE, None), // path doesn't get updated
(tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None)
]);
} else {
assert_eq!(actual, vec![
(tdir.mkpath("dir1/file1"), op::CREATE, None) // path doesn't get updated
]);
}

Expand Down Expand Up @@ -1012,9 +1049,14 @@ fn parent_rename_file() {
if cfg!(target_os="macos") {
// macos doesn't watch files, but paths
assert_eq!(actual, vec![]);
} else {
} else if cfg!(target_os="linux") {
assert_eq!(actual, vec![
(tdir.mkpath("dir1/file1"), op::WRITE, None), // path doesn't get updated
(tdir.mkpath("dir1/file1"), op::CLOSE_WRITE, None)
]);
} else {
assert_eq!(actual, vec![
(tdir.mkpath("dir1/file1"), op::WRITE, None) // path doesn't get updated
]);
}

Expand Down