Skip to content

Commit

Permalink
[macOS] Emit FileModifiedEvent on permission change (#815)
Browse files Browse the repository at this point in the history
* [fsevents] emit permission changes as modified events

alongside other metadata modifications

* added test for chmod events

* added changelog entry
  • Loading branch information
SamSchott committed Jul 13, 2021
1 parent 44ced23 commit 8407554
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion changelog.rst
Expand Up @@ -9,7 +9,8 @@ Changelog
2021-xx-x • `full history <https://github.com/gorakhargosh/watchdog/compare/v2.1.3...master>`__

- [watchmedo] Fix usage of ``os.setsid()`` and ``os.killpg()`` Unix-only functions. (`#809 <https://github.com/gorakhargosh/watchdog/pull/809>`_)
- Thanks to our beloved contributors: @replabrobin, @BoboTiG
- [mac] Fix missing ``FileModifiedEvent`` on permission or ownership changes of a file. (`#809 <https://github.com/gorakhargosh/watchdog/pull/814>`_)
- Thanks to our beloved contributors: @replabrobin, @BoboTiG, @SamSchott

2.1.3
~~~~~
Expand Down
11 changes: 8 additions & 3 deletions src/watchdog/observers/fsevents.py
Expand Up @@ -156,6 +156,11 @@ def _is_historic_created_event(self, event):

return in_history or before_start

@staticmethod
def _is_meta_mod(event):
"""Returns True if the event indicates a change in metadata."""
return event.is_inode_meta_mod or event.is_xattr_mod or event.is_owner_change

def queue_events(self, timeout, events):

if logger.getEffectiveLevel() <= logging.DEBUG:
Expand Down Expand Up @@ -209,7 +214,7 @@ def queue_events(self, timeout, events):

self._fs_view.add(event.inode)

if event.is_modified or event.is_inode_meta_mod or event.is_xattr_mod:
if event.is_modified or self._is_meta_mod(event):
self._queue_modified_event(event, src_path, src_dirname)

self._queue_deleted_event(event, src_path, src_dirname)
Expand All @@ -222,7 +227,7 @@ def queue_events(self, timeout, events):

self._fs_view.add(event.inode)

if event.is_modified or event.is_inode_meta_mod or event.is_xattr_mod:
if event.is_modified or self._is_meta_mod(event):
self._queue_modified_event(event, src_path, src_dirname)

if event.is_renamed:
Expand All @@ -247,7 +252,7 @@ def queue_events(self, timeout, events):

events.remove(dst_event)

if dst_event.is_modified or dst_event.is_inode_meta_mod or dst_event.is_xattr_mod:
if dst_event.is_modified or self._is_meta_mod(dst_event):
self._queue_modified_event(dst_event, dst_path, dst_dirname)

if dst_event.is_removed:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_emitter.py
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import os
import stat
import time
import pytest
import logging
Expand Down Expand Up @@ -195,6 +196,21 @@ def test_modify():
assert isinstance(event, FileClosedEvent)


@pytest.mark.flaky(max_runs=5, min_passes=1, rerun_filter=rerun_filter)
def test_chmod():
mkfile(p('a'))
start_watching()

# Note: We use S_IREAD here because chmod on Windows only
# allows setting the read-only flag.
os.chmod(p('a'), stat.S_IREAD)

expect_event(FileModifiedEvent(p('a')))

# Reset permissions to allow cleanup.
os.chmod(p('a'), stat.S_IWRITE)


@pytest.mark.flaky(max_runs=5, min_passes=1, rerun_filter=rerun_filter)
def test_move():
mkdir(p('dir1'))
Expand Down

0 comments on commit 8407554

Please sign in to comment.