From 1f2e1f974616b6030ea11bf12d7d84dfc931cb71 Mon Sep 17 00:00:00 2001 From: Cristian Kubis Date: Mon, 13 Oct 2014 15:07:30 +0200 Subject: [PATCH 1/3] adjusted naming pattern to avoind keyword collision --- src/wrapper.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/wrapper.rs b/src/wrapper.rs index 28ce6dc..b064bf7 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -157,59 +157,59 @@ 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; } @@ -217,15 +217,15 @@ impl Event { 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; } } From 46e5027761fdd73e79509d35ced35c451d74d25d Mon Sep 17 00:00:00 2001 From: Cristian Kubis Date: Mon, 13 Oct 2014 15:10:21 +0200 Subject: [PATCH 2/3] made Inotify and Event cloneable --- src/wrapper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wrapper.rs b/src/wrapper.rs index b064bf7..dac4419 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -22,7 +22,7 @@ use ffi::inotify_event; pub type Watch = c_int; - +#[deriving(Clone)] pub struct INotify { pub fd: c_int, events: Vec, @@ -139,7 +139,7 @@ impl INotify { } } - +#[deriving(Clone)] pub struct Event { pub wd : i32, pub mask : u32, From 62062882ccdf93d0c19d32f6f9c3b94df51784a2 Mon Sep 17 00:00:00 2001 From: Cristian Kubis Date: Mon, 13 Oct 2014 18:00:10 +0200 Subject: [PATCH 3/3] replaced static with const --- src/ffi.rs | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/ffi.rs b/src/ffi.rs index 75ebcca..945e1da 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -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 /// @@ -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. /// @@ -109,37 +109,37 @@ 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. /// @@ -147,7 +147,7 @@ pub static IN_MOVED_TO : uint32_t = 0x00000080; /// /// 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. /// @@ -155,7 +155,7 @@ pub static IN_CREATE : uint32_t = 0x00000100; /// /// 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. /// @@ -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. /// @@ -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. /// @@ -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.