Anonymous avatar Anonymous committed d4fcd4e

Add remove_watch.

Comments (0)

Files changed (1)

inotify/_inotify.c

 #include <Python.h>
 #include <sys/inotify.h>
 
-static PyObject *pyinotify_init(PyObject *self, PyObject *args)
+static PyObject *init(PyObject *self, PyObject *args)
 {
     PyObject *ret = NULL;
     int fd = -1;
     "Initialise an inotify instance.\n"
     "Return a file descriptor associated with a new inotify event queue.");
 
-static PyObject *pyinotify_add_watch(PyObject *self, PyObject *args)
+static PyObject *add_watch(PyObject *self, PyObject *args)
 {
     PyObject *ret = NULL;
     uint32_t mask;
     add_watch_doc,
     "add_watch(fd, path, mask) -> wd\n"
     "\n"
-    "Add a watch to an initialised inotify instance.\n"
+    "Add a watch to an inotify instance, or modify an existing watch.\n"
     "\n"
     "        fd: file descriptor returned by init()\n"
     "        path: path to watch\n"
     "        mask: mask of events to watch for\n"
     "\n"
-    "Return a numeric watch descriptor.");
+    "Return a unique numeric watch descriptor for the inotify instance\n"
+    "mapped by the file descriptor.");
+
+static PyObject *remove_watch(PyObject *self, PyObject *args)
+{
+    PyObject *ret = NULL;
+    uint32_t wd;
+    int fd;
+    int r;
+    
+    if (!PyArg_ParseTuple(args, "iI:remove_watch", &fd, &wd))
+	goto bail;
+
+    r = inotify_rm_watch(fd, wd);
+    if (r == -1) {
+	PyErr_SetFromErrno(PyExc_OSError);
+	goto bail;
+    }
+    
+    Py_INCREF(Py_None);
+    
+    goto done;
+    
+bail:
+    Py_XDECREF(ret);
+    
+done:
+    return ret;
+}
+
+PyDoc_STRVAR(
+    remove_watch_doc,
+    "remove_watch(fd, wd)\n"
+    "\n"
+    "        fd: file descriptor returned by init()\n"
+    "        wd: watch descriptor returned by add_watch()\n"
+    "\n"
+    "Remove a watch associated with the watch descriptor wd from the\n"
+    "inotify instance associated with the file descriptor fd.\n"
+    "\n"
+    "Removing a watch causes an IN_IGNORED event to be generated for this\n"
+    "watch descriptor.");
 
 static PyMethodDef methods[] = {
-    {"init", pyinotify_init, METH_VARARGS, init_doc},
-    {"add_watch", pyinotify_add_watch, METH_VARARGS, add_watch_doc},
+    {"init", init, METH_VARARGS, init_doc},
+    {"add_watch", add_watch, METH_VARARGS, add_watch_doc},
+    {"remove_watch", remove_watch, METH_VARARGS, remove_watch_doc},
     {NULL},
 };
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.