Merge lp:~mandel/ubuntuone-client/fix-802726 into lp:ubuntuone-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1034
Merged at revision: 1032
Proposed branch: lp:~mandel/ubuntuone-client/fix-802726
Merge into: lp:ubuntuone-client
Diff against target: 116 lines (+44/-8)
2 files modified
tests/platform/windows/test_filesystem_notifications.py (+37/-7)
ubuntuone/platform/windows/filesystem_notifications.py (+7/-1)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/fix-802726
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+66373@code.launchpad.net

Commit message

- Added an extra filtering to ensure that the IN_OPEN|IN_ISDIR masked events do not get to the fsm (LP: #802726).

Description of the change

fixes: lp:802726

Adds an extra filtering to ensure that the IN_OPEN|IN_ISDIR masked events do not get to the fsm.

To post a comment you must log in.
1031. By Manuel de la Peña

Link bug

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Very good!

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/windows/test_filesystem_notifications.py'
2--- tests/platform/windows/test_filesystem_notifications.py 2011-04-01 16:07:13 +0000
3+++ tests/platform/windows/test_filesystem_notifications.py 2011-06-30 12:21:13 +0000
4@@ -71,7 +71,7 @@
5 FILE_NOTIFY_CHANGE_LAST_ACCESS
6
7 def _perform_operations(self, path, mask, auto_add, actions, number_events):
8- """Performs the file operations and returns the recorded events."""
9+ """Perform the file operations and returns the recorded events."""
10 manager = WatchManager()
11 manager.add_watch(path, mask, auto_add=auto_add)
12 handler = TestCaseHandler()
13@@ -85,6 +85,22 @@
14 notifier.stop()
15 return events
16
17+ def _perform_timed_operations(self, path, mask, auto_add, actions,
18+ time_out):
19+ """Perform the file operations and returns the recorded events."""
20+ manager = WatchManager()
21+ manager.add_watch(path, mask, auto_add=auto_add)
22+ handler = TestCaseHandler()
23+ notifier = Notifier(manager, handler)
24+ # execution the actions
25+ actions()
26+ # process the recorded events
27+ time.sleep(time_out)
28+ notifier.process_events()
29+ events = handler.processed_events
30+ notifier.stop()
31+ return events
32+
33 def test_file_create(self):
34 """Test that the correct event is returned on a file create."""
35 file_name = os.path.join(self.basedir, 'test_file_create')
36@@ -368,6 +384,20 @@
37 notifier.stop()
38 self.assertEqual(0, len(handler.processed_events))
39
40+ def test_open_dir_muted(self):
41+ """Test that the opening of dirs is ignored."""
42+ dir_name = os.path.join(tempfile.mkdtemp(), 'test_dir_open')
43+ # create file before we record
44+ os.mkdir(dir_name)
45+
46+ def open_dir():
47+ """Action for the test."""
48+ os.startfile(dir_name)
49+
50+ events = self._perform_timed_operations(self.basedir, self.mask, False,
51+ open_dir, 2)
52+ self.assertEqual(0, len(events))
53+
54
55 class TestWatchManager(MockerTestCase):
56 """Test the watch manager."""
57@@ -452,6 +482,8 @@
58 """Test the wd is returned when there is a watch for the path."""
59 self.manager._wdm = {1: self.watch}
60 path = 'path'
61+ self.watch.auto_add
62+ self.mocker.result(True)
63 self.watch.path
64 self.mocker.result(path)
65 self.mocker.replay()
66@@ -482,12 +514,12 @@
67 path = 'path'
68 self.watch.path
69 self.mocker.result(path)
70- self.watch.path
71- self.mocker.result(path)
72- self.watch.stop_watching()
73+ self.watch.auto_add
74+ self.mocker.result(True)
75+ self.watch.exclude_filter = ANY
76 self.mocker.replay()
77 self.manager.rm_path(path)
78- self.assertEqual(None, self.manager._wdm.get(1))
79+ self.assertEqual(self.watch, self.manager._wdm.get(1))
80
81 def test_rm_child_path(self):
82 """Test the removal of a child path."""
83@@ -495,8 +527,6 @@
84 path = 'path'
85 self.watch.path
86 self.mocker.result(path)
87- self.watch.path
88- self.mocker.result(path)
89 self.watch.auto_add
90 self.mocker.result(True)
91 self.watch.exclude_filter = ANY
92
93=== modified file 'ubuntuone/platform/windows/filesystem_notifications.py'
94--- ubuntuone/platform/windows/filesystem_notifications.py 2011-06-29 20:11:28 +0000
95+++ ubuntuone/platform/windows/filesystem_notifications.py 2011-06-30 12:21:13 +0000
96@@ -171,6 +171,12 @@
97 self._subdirs.append(path)
98 return is_dir
99
100+ def _is_excluded(self, event):
101+ """Return if an event is ignored."""
102+ return (self.exclude_filter and self.exclude_filter(event)) or\
103+ event.mask == IN_OPEN | IN_ISDIR
104+
105+
106 def _process_events(self):
107 """Process the events form the queue."""
108 # we transform the events to be the same as the one in pyinotify
109@@ -221,7 +227,7 @@
110 # the exclude filter returns False, that is, the event will not
111 # be excluded
112 self.log.debug('Event is %s.', event)
113- if not self.exclude_filter or not self.exclude_filter(event):
114+ if not self._is_excluded(event):
115 self.log.debug('Addding event %s to queue.', event)
116 self.events_queue.put(event)
117

Subscribers

People subscribed via source and target branches