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 missing exception objects #766

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Changelog

2021-0x-x • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.0.1...master>`__

- Thanks to our beloved contributors: @
- [mac] Add missing exception objects (`#766 <https://github.com/gorakhargosh/watchdog/pull/766>`_)

- Thanks to our beloved contributors: @CCP-Aporia


2.0.1
Expand Down
8 changes: 7 additions & 1 deletion src/watchdog_fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ watchdog_add_watch(PyObject *self, PyObject *args)
&python_callback, &paths_to_watch));

/* Watch must not already be scheduled. */
G_RETURN_NULL_IF(PyDict_Contains(watch_to_stream, watch) == 1);
if(PyDict_Contains(watch_to_stream, watch) == 1) {
PyErr_Format(PyExc_RuntimeError, "Cannot add watch %S - it is already scheduled", watch);
return NULL;
}

/* Create an instance of the callback information structure. */
stream_callback_info_ref = PyMem_New(StreamCallbackInfo, 1);
CCP-Aporia marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -689,6 +692,9 @@ watchdog_add_watch(PyObject *self, PyObject *args)
{
FSEventStreamInvalidate(stream_ref);
FSEventStreamRelease(stream_ref);
// There's no documentation on _why_ this might fail - "it ought to always succeed". But if it fails the
// documentation says to "fall back to performing recursive scans of the directories [...] as appropriate".
PyErr_SetString(PyExc_SystemError, "Cannot start fsevents stream. Use a kqueue or polling observer instead.");
return NULL;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/test_fsevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ def test_coalesced_event_check(event, expectation):
assert event.is_coalesced == expectation


def test_add_watch_twice(observer):
""" Adding the same watch twice used to result in a null pointer return without an exception.

See https://github.com/gorakhargosh/watchdog/issues/765
"""

a = p("a")
mkdir(a)
h = FileSystemEventHandler()
w = ObservedWatch(a, recursive=False)

def callback(path, inodes, flags, ids):
pass

_fsevents.add_watch(h, w, callback, [w.path])
with pytest.raises(RuntimeError):
_fsevents.add_watch(h, w, callback, [w.path])
_fsevents.remove_watch(w)
rmdir(a)


def test_remove_watch_twice():
"""
ValueError: PyCapsule_GetPointer called with invalid PyCapsule object
Expand Down