Skip to content

Fixed move keyword collision and made cloneable #3

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

Merged
merged 3 commits into from
Oct 13, 2014
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
52 changes: 26 additions & 26 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub use libc::read;
/// [execve(2)]: http://man7.org/linux/man-pages/man2/execve.2.html
/// [open(2)]: http://man7.org/linux/man-pages/man2/open.2.html
/// [fcntl(2)]: http://man7.org/linux/man-pages/man2/fcntl.2.html
pub static IN_CLOEXEC : c_int = 0o2000000;
pub const IN_CLOEXEC : c_int = 0o2000000;

/// Flag: Set the O_NONBLOCK file status flag
///
Expand Down Expand Up @@ -81,15 +81,15 @@ pub static IN_CLOEXEC : c_int = 0o2000000;
/// [read(2)]: http://man7.org/linux/man-pages/man2/read.2.html
/// [write(2)]: http://man7.org/linux/man-pages/man2/write.2.html
/// [fcntl(2)]: http://man7.org/linux/man-pages/man2/fcntl.2.html
pub static IN_NONBLOCK: c_int = 0o4000;
pub const IN_NONBLOCK: c_int = 0o4000;

/// Event: File was accessed.
///
/// When monitoring a directory, the event may occur both for the
/// directory itself and the files within.
pub static IN_ACCESS : uint32_t = 0x00000001;
pub const IN_ACCESS : uint32_t = 0x00000001;

pub static IN_MODIFY : uint32_t = 0x00000002;
pub const IN_MODIFY : uint32_t = 0x00000002;

/// Event: Metadata has changed.
///
Expand All @@ -109,53 +109,53 @@ pub static IN_MODIFY : uint32_t = 0x00000002;
/// [link(2)]: http://man7.org/linux/man-pages/man2/link.2.html
/// [unlink(2)]: http://man7.org/linux/man-pages/man2/link.2.html
/// [chown(2)]: http://man7.org/linux/man-pages/man2/link.2.html
pub static IN_ATTRIB : uint32_t = 0x00000004;
pub const IN_ATTRIB : uint32_t = 0x00000004;

/// Event: File opened for writing was closed.
///
/// When monitoring a directory, the event may occur both for the
/// directory itself and the files within.
pub static IN_CLOSE_WRITE : uint32_t = 0x00000008;
pub const IN_CLOSE_WRITE : uint32_t = 0x00000008;

/// Event: File not opened for writing was closed.
///
/// When monitoring a directory, the event may occur both for the
/// directory itself and the files within.
pub static IN_CLOSE_NOWRITE: uint32_t = 0x00000010;
pub const IN_CLOSE_NOWRITE: uint32_t = 0x00000010;

/// Event: File was opened.
///
/// When monitoring a directory, the event may occur both for the
/// directory itself and the files within.
pub static IN_OPEN : uint32_t = 0x00000020;
pub const IN_OPEN : uint32_t = 0x00000020;

/// Event: File or directory was moved away.
///
/// When monitoring a directory, the event may occur *only* for
/// the files within, not the directory itself.
pub static IN_MOVED_FROM : uint32_t = 0x00000040;
pub const IN_MOVED_FROM : uint32_t = 0x00000040;

/// Event: File or directory was moved in.
///
/// When monitoring a directory, the event may occur *only* for
/// the files within, not the directory itself.
pub static IN_MOVED_TO : uint32_t = 0x00000080;
pub const IN_MOVED_TO : uint32_t = 0x00000080;

/// Event: File or directory was created.
///
/// This may also include hard links, symlinks, and UNIX sockets.
///
/// When monitoring a directory, the event may occur *only* for
/// the files within, not the directory itself.
pub static IN_CREATE : uint32_t = 0x00000100;
pub const IN_CREATE : uint32_t = 0x00000100;

/// Event: File or directory was deleted.
///
/// This may also include hard links, symlinks, and UNIX sockets.
///
/// When monitoring a directory, the event may occur *only* for
/// the files within, not the directory itself.
pub static IN_DELETE : uint32_t = 0x00000200;
pub const IN_DELETE : uint32_t = 0x00000200;

/// Event: Watched file or directory was deleted.
///
Expand All @@ -166,34 +166,34 @@ pub static IN_DELETE : uint32_t = 0x00000200;
/// An IN_IGNORED event will subsequently be generated.
///
/// [mv(1)]: http://man7.org/linux/man-pages/man1/mv.1.html
pub static IN_DELETE_SELF : uint32_t = 0x00000400;
pub const IN_DELETE_SELF : uint32_t = 0x00000400;

/// Event: Watched file or directory was moved.
pub static IN_MOVE_SELF : uint32_t = 0x00000800;
pub const IN_MOVE_SELF : uint32_t = 0x00000800;

/// Event: File or directory was moved away or in.
///
/// When monitoring a directory, the event may occur *only* for
/// the files within, not the directory itself.
pub static IN_MOVE : uint32_t = (IN_MOVED_FROM | IN_MOVED_TO);
pub const IN_MOVE : uint32_t = (IN_MOVED_FROM | IN_MOVED_TO);

/// Event: File opened was closed.
///
/// When monitoring a directory, the event may occur both for the
/// directory itself and the files within.
pub static IN_CLOSE: uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE);
pub const IN_CLOSE: uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE);

/// Event: Any event occured.
pub static IN_ALL_EVENTS: uint32_t = (
pub const IN_ALL_EVENTS: uint32_t = (
IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_CLOSE_NOWRITE
| IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | IN_DELETE
| IN_DELETE_SELF | IN_MOVE_SELF);

/// Option: Don't watch children (if self is a directory).
pub static IN_ONLYDIR : uint32_t = 0x01000000;
pub const IN_ONLYDIR : uint32_t = 0x01000000;

/// Option: Don't dereference (if self is a symlink).
pub static IN_DONT_FOLLOW: uint32_t = 0x02000000;
pub const IN_DONT_FOLLOW: uint32_t = 0x02000000;

/// Option: Don't watch unlinked children.
///
Expand All @@ -208,28 +208,28 @@ pub static IN_DONT_FOLLOW: uint32_t = 0x02000000;
/// > IN_EXCL_UNLINK changes this behavior, so that events are
/// > not generated for children after they have been unlinked
/// > from the watched directory.
pub static IN_EXCL_UNLINK: uint32_t = 0x04000000;
pub const IN_EXCL_UNLINK: uint32_t = 0x04000000;

/// Option: Add events to an existing watch instead of replacing it.
///
/// > If a watch instance already exists for the filesystem
/// > object corresponding to self, add (|) the events to the
/// > watch mask instead of replacing it.
pub static IN_MASK_ADD : uint32_t = 0x20000000;
pub const IN_MASK_ADD : uint32_t = 0x20000000;

/// Option: Listen for one event, then remove the watch.
pub static IN_ONESHOT : uint32_t = 0x80000000;
pub const IN_ONESHOT : uint32_t = 0x80000000;

/// Info: Subject of this event is a directory.
pub static IN_ISDIR : uint32_t = 0x40000000;
pub const IN_ISDIR : uint32_t = 0x40000000;

/// Info: Filesystem containing self was unmounted.
///
/// An IN_IGNORED event will subsequently be generated.
pub static IN_UNMOUNT : uint32_t = 0x00002000;
pub const IN_UNMOUNT : uint32_t = 0x00002000;

/// Info: Event queue overflowed.
pub static IN_Q_OVERFLOW: uint32_t = 0x00004000;
pub const IN_Q_OVERFLOW: uint32_t = 0x00004000;

/// Info: Watch was removed.
///
Expand All @@ -240,7 +240,7 @@ pub static IN_Q_OVERFLOW: uint32_t = 0x00004000;
/// See the BUGS section of [inotify(7)] for more details.
///
/// [inotify(7)]: http://man7.org/linux/man-pages/man7/inotify.7.html
pub static IN_IGNORED : uint32_t = 0x00008000;
pub const IN_IGNORED : uint32_t = 0x00008000;


/// Describes an event.
Expand Down
38 changes: 19 additions & 19 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ffi::inotify_event;

pub type Watch = c_int;


#[deriving(Clone)]
pub struct INotify {
pub fd: c_int,
events: Vec<Event>,
Expand Down Expand Up @@ -139,7 +139,7 @@ impl INotify {
}
}


#[deriving(Clone)]
pub struct Event {
pub wd : i32,
pub mask : u32,
Expand All @@ -157,75 +157,75 @@ impl Event {
}
}

pub fn access(&self) -> bool {
pub fn is_access(&self) -> bool {
return self.mask & ffi::IN_ACCESS > 0;
}

pub fn modify(&self) -> bool {
pub fn is_modify(&self) -> bool {
return self.mask & ffi::IN_MODIFY > 0;
}

pub fn attrib(&self) -> bool {
pub fn is_attrib(&self) -> bool {
return self.mask & ffi::IN_ATTRIB > 0;
}

pub fn close_write(&self) -> bool {
pub fn is_close_write(&self) -> bool {
return self.mask & ffi::IN_CLOSE_WRITE > 0;
}

pub fn close_nowrite(&self) -> bool {
pub fn is_close_nowrite(&self) -> bool {
return self.mask & ffi::IN_CLOSE_NOWRITE > 0;
}

pub fn open(&self) -> bool {
pub fn is_open(&self) -> bool {
return self.mask & ffi::IN_OPEN > 0;
}

pub fn moved_from(&self) -> bool {
pub fn is_moved_from(&self) -> bool {
return self.mask & ffi::IN_MOVED_FROM > 0;
}

pub fn moved_to(&self) -> bool {
pub fn is_moved_to(&self) -> bool {
return self.mask & ffi::IN_MOVED_TO > 0;
}

pub fn create(&self) -> bool {
pub fn is_create(&self) -> bool {
return self.mask & ffi::IN_CREATE > 0;
}

pub fn delete(&self) -> bool {
pub fn is_delete(&self) -> bool {
return self.mask & ffi::IN_DELETE > 0;
}

pub fn delete_self(&self) -> bool {
pub fn is_delete_self(&self) -> bool {
return self.mask & ffi::IN_DELETE_SELF > 0;
}

pub fn move_self(&self) -> bool {
pub fn is_move_self(&self) -> bool {
return self.mask & ffi::IN_MOVE_SELF > 0;
}

pub fn move(&self) -> bool {
pub fn is_move(&self) -> bool {
return self.mask & ffi::IN_MOVE > 0;
}

pub fn close(&self) -> bool {
pub fn is_close(&self) -> bool {
return self.mask & ffi::IN_CLOSE > 0;
}

pub fn is_dir(&self) -> bool {
return self.mask & ffi::IN_ISDIR > 0;
}

pub fn unmount(&self) -> bool {
pub fn is_unmount(&self) -> bool {
return self.mask & ffi::IN_UNMOUNT > 0;
}

pub fn queue_overflow(&self) -> bool {
pub fn is_queue_overflow(&self) -> bool {
return self.mask & ffi::IN_Q_OVERFLOW > 0;
}

pub fn ignored(&self) -> bool {
pub fn is_ignored(&self) -> bool {
return self.mask & ffi::IN_IGNORED > 0;
}
}