Merge lp:~mandel/ubuntuone-client/add-watch-deferred into lp:ubuntuone-client
- add-watch-deferred
- Merge into trunk
Proposed by
Manuel de la Peña
Status: | Merged |
---|---|
Approved by: | Alejandro J. Cura |
Approved revision: | 1119 |
Merged at revision: | 1081 |
Proposed branch: | lp:~mandel/ubuntuone-client/add-watch-deferred |
Merge into: | lp:ubuntuone-client |
Prerequisite: | lp:~mandel/ubuntuone-client/fix-fsm |
Diff against target: |
446 lines (+74/-44) 6 files modified
tests/platform/test_filesystem_notifications.py (+40/-20) tests/syncdaemon/test_vm.py (+15/-11) ubuntuone/platform/linux/filesystem_notifications.py (+2/-2) ubuntuone/platform/windows/filesystem_notifications.py (+4/-2) ubuntuone/syncdaemon/local_rescan.py (+11/-7) ubuntuone/syncdaemon/volume_manager.py (+2/-2) |
To merge this branch: | bzr merge lp:~mandel/ubuntuone-client/add-watch-deferred |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Natalia Bidart (community) | Approve | ||
Review via email: mp+69816@code.launchpad.net |
Commit message
Changed add_watch to return a deferred so that we will be waiting for a successful callback before we assume that the watch is running.
Description of the change
Changed add_watch to return a deferred so that we will be waiting for a successful callback before we assume that the watch is running.
To post a comment you must log in.
- 1117. By Manuel de la Peña
-
Merged fix-fsm into add-watch-deferred.
- 1118. By Manuel de la Peña
-
Merged fix-fsm into add-watch-deferred.
- 1119. By Manuel de la Peña
-
Merged fix-fsm into add-watch-deferred.
Revision history for this message
Alejandro J. Cura (alecu) wrote : | # |
Code looks fine, and all tests pass!
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tests/platform/test_filesystem_notifications.py' | |||
2 | --- tests/platform/test_filesystem_notifications.py 2011-07-28 14:51:42 +0000 | |||
3 | +++ tests/platform/test_filesystem_notifications.py 2011-07-29 17:35:26 +0000 | |||
4 | @@ -239,6 +239,7 @@ | |||
5 | 239 | 239 | ||
6 | 240 | @skipIfOS('win32', 'There is no reasonable way to know when a file is ' | 240 | @skipIfOS('win32', 'There is no reasonable way to know when a file is ' |
7 | 241 | + 'opened on windows.') | 241 | + 'opened on windows.') |
8 | 242 | @defer.inlineCallbacks | ||
9 | 242 | def test_file_open(self): | 243 | def test_file_open(self): |
10 | 243 | """Test receiving the open signal on files.""" | 244 | """Test receiving the open signal on files.""" |
11 | 244 | testfile = os.path.join(self.root_dir, "foo") | 245 | testfile = os.path.join(self.root_dir, "foo") |
12 | @@ -246,15 +247,17 @@ | |||
13 | 246 | self.monitor.add_to_mute_filter("FS_FILE_OPEN", path=testfile) | 247 | self.monitor.add_to_mute_filter("FS_FILE_OPEN", path=testfile) |
14 | 247 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", path=testfile) | 248 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", path=testfile) |
15 | 248 | self.assertEqual(self._how_many_muted(), 2) | 249 | self.assertEqual(self._how_many_muted(), 2) |
17 | 249 | self.monitor.add_watch(self.root_dir) | 250 | yield self.monitor.add_watch(self.root_dir) |
18 | 250 | 251 | ||
19 | 251 | # generate the event | 252 | # generate the event |
20 | 252 | open(testfile) | 253 | open(testfile) |
21 | 253 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 254 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
23 | 254 | return self._deferred | 255 | test_result = yield self._deferred |
24 | 256 | defer.returnValue(test_result) | ||
25 | 255 | 257 | ||
26 | 256 | @skipIfOS('win32', 'There is no reasonable way to know when a file was ' | 258 | @skipIfOS('win32', 'There is no reasonable way to know when a file was ' |
27 | 257 | 'opened on windows') | 259 | 'opened on windows') |
28 | 260 | @defer.inlineCallbacks | ||
29 | 258 | def test_file_close_nowrite(self): | 261 | def test_file_close_nowrite(self): |
30 | 259 | """Test receiving the close_nowrite signal on files.""" | 262 | """Test receiving the close_nowrite signal on files.""" |
31 | 260 | testfile = os.path.join(self.root_dir, "foo") | 263 | testfile = os.path.join(self.root_dir, "foo") |
32 | @@ -262,13 +265,15 @@ | |||
33 | 262 | fh = open(testfile) | 265 | fh = open(testfile) |
34 | 263 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", path=testfile) | 266 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", path=testfile) |
35 | 264 | self.assertEqual(self._how_many_muted(), 1) | 267 | self.assertEqual(self._how_many_muted(), 1) |
37 | 265 | self.monitor.add_watch(self.root_dir) | 268 | yield self.monitor.add_watch(self.root_dir) |
38 | 266 | 269 | ||
39 | 267 | # generate the event | 270 | # generate the event |
40 | 268 | fh.close() | 271 | fh.close() |
41 | 269 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 272 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
43 | 270 | return self._deferred | 273 | test_result = yield self._deferred |
44 | 274 | defer.returnValue(test_result) | ||
45 | 271 | 275 | ||
46 | 276 | @defer.inlineCallbacks | ||
47 | 272 | def test_file_create_close_write(self): | 277 | def test_file_create_close_write(self): |
48 | 273 | """Test receiving the create and close_write signals on files.""" | 278 | """Test receiving the create and close_write signals on files.""" |
49 | 274 | testfile = os.path.join(self.root_dir, "foo") | 279 | testfile = os.path.join(self.root_dir, "foo") |
50 | @@ -276,53 +281,61 @@ | |||
51 | 276 | self.monitor.add_to_mute_filter("FS_FILE_OPEN", path=testfile) | 281 | self.monitor.add_to_mute_filter("FS_FILE_OPEN", path=testfile) |
52 | 277 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path=testfile) | 282 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path=testfile) |
53 | 278 | self.assertEqual(self._how_many_muted(), 3) | 283 | self.assertEqual(self._how_many_muted(), 3) |
55 | 279 | self.monitor.add_watch(self.root_dir) | 284 | yield self.monitor.add_watch(self.root_dir) |
56 | 280 | 285 | ||
57 | 281 | # generate the event | 286 | # generate the event |
58 | 282 | fd = open(testfile, "w") | 287 | fd = open(testfile, "w") |
59 | 283 | fd.write('test') | 288 | fd.write('test') |
60 | 284 | fd.close() | 289 | fd.close() |
61 | 285 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 290 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
63 | 286 | return self._deferred | 291 | test_result = yield self._deferred |
64 | 292 | defer.returnValue(test_result) | ||
65 | 287 | 293 | ||
66 | 294 | @defer.inlineCallbacks | ||
67 | 288 | def test_dir_create(self): | 295 | def test_dir_create(self): |
68 | 289 | """Test receiving the create signal on dirs.""" | 296 | """Test receiving the create signal on dirs.""" |
69 | 290 | testdir = os.path.join(self.root_dir, "foo") | 297 | testdir = os.path.join(self.root_dir, "foo") |
70 | 291 | self.monitor.add_to_mute_filter("FS_DIR_CREATE", path=testdir) | 298 | self.monitor.add_to_mute_filter("FS_DIR_CREATE", path=testdir) |
71 | 292 | self.assertEqual(self._how_many_muted(), 1) | 299 | self.assertEqual(self._how_many_muted(), 1) |
73 | 293 | self.monitor.add_watch(self.root_dir) | 300 | yield self.monitor.add_watch(self.root_dir) |
74 | 294 | 301 | ||
75 | 295 | # generate the event | 302 | # generate the event |
76 | 296 | os.mkdir(testdir) | 303 | os.mkdir(testdir) |
77 | 297 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 304 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
79 | 298 | return self._deferred | 305 | test_result = yield self._deferred |
80 | 306 | defer.returnValue(test_result) | ||
81 | 299 | 307 | ||
82 | 308 | @defer.inlineCallbacks | ||
83 | 300 | def test_file_delete(self): | 309 | def test_file_delete(self): |
84 | 301 | """Test the delete signal on a file.""" | 310 | """Test the delete signal on a file.""" |
85 | 302 | testfile = os.path.join(self.root_dir, "foo") | 311 | testfile = os.path.join(self.root_dir, "foo") |
86 | 303 | open(testfile, "w").close() | 312 | open(testfile, "w").close() |
87 | 304 | self.monitor.add_to_mute_filter("FS_FILE_DELETE", path=testfile) | 313 | self.monitor.add_to_mute_filter("FS_FILE_DELETE", path=testfile) |
88 | 305 | self.assertEqual(self._how_many_muted(), 1) | 314 | self.assertEqual(self._how_many_muted(), 1) |
90 | 306 | self.monitor.add_watch(self.root_dir) | 315 | yield self.monitor.add_watch(self.root_dir) |
91 | 307 | 316 | ||
92 | 308 | # generate the event | 317 | # generate the event |
93 | 309 | os.remove(testfile) | 318 | os.remove(testfile) |
94 | 310 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 319 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
96 | 311 | return self._deferred | 320 | test_result = yield self._deferred |
97 | 321 | defer.returnValue(test_result) | ||
98 | 312 | 322 | ||
99 | 323 | @defer.inlineCallbacks | ||
100 | 313 | def test_dir_delete(self): | 324 | def test_dir_delete(self): |
101 | 314 | """Test the delete signal on a dir.""" | 325 | """Test the delete signal on a dir.""" |
102 | 315 | testdir = os.path.join(self.root_dir, "foo") | 326 | testdir = os.path.join(self.root_dir, "foo") |
103 | 316 | os.mkdir(testdir) | 327 | os.mkdir(testdir) |
104 | 317 | self.monitor.add_to_mute_filter("FS_DIR_DELETE", path=testdir) | 328 | self.monitor.add_to_mute_filter("FS_DIR_DELETE", path=testdir) |
105 | 318 | self.assertEqual(self._how_many_muted(), 1) | 329 | self.assertEqual(self._how_many_muted(), 1) |
107 | 319 | self.monitor.add_watch(self.root_dir) | 330 | yield self.monitor.add_watch(self.root_dir) |
108 | 320 | 331 | ||
109 | 321 | # generate the event | 332 | # generate the event |
110 | 322 | os.rmdir(testdir) | 333 | os.rmdir(testdir) |
111 | 323 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 334 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
113 | 324 | return self._deferred | 335 | test_result = yield self._deferred |
114 | 336 | defer.returnValue(test_result) | ||
115 | 325 | 337 | ||
116 | 338 | @defer.inlineCallbacks | ||
117 | 326 | def test_file_moved_inside(self): | 339 | def test_file_moved_inside(self): |
118 | 327 | """Test the synthesis of the FILE_MOVE event.""" | 340 | """Test the synthesis of the FILE_MOVE event.""" |
119 | 328 | fromfile = os.path.join(self.root_dir, "foo") | 341 | fromfile = os.path.join(self.root_dir, "foo") |
120 | @@ -335,13 +348,15 @@ | |||
121 | 335 | self.monitor.add_to_mute_filter("FS_FILE_MOVE", | 348 | self.monitor.add_to_mute_filter("FS_FILE_MOVE", |
122 | 336 | path_from=fromfile, path_to=tofile) | 349 | path_from=fromfile, path_to=tofile) |
123 | 337 | self.assertEqual(self._how_many_muted(), 1) | 350 | self.assertEqual(self._how_many_muted(), 1) |
125 | 338 | self.monitor.add_watch(self.root_dir) | 351 | yield self.monitor.add_watch(self.root_dir) |
126 | 339 | 352 | ||
127 | 340 | # generate the event | 353 | # generate the event |
128 | 341 | os.rename(fromfile, tofile) | 354 | os.rename(fromfile, tofile) |
129 | 342 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 355 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
131 | 343 | return self._deferred | 356 | test_result = yield self._deferred |
132 | 357 | defer.returnValue(test_result) | ||
133 | 344 | 358 | ||
134 | 359 | @defer.inlineCallbacks | ||
135 | 345 | def test_dir_moved_inside(self): | 360 | def test_dir_moved_inside(self): |
136 | 346 | """Test the synthesis of the DIR_MOVE event.""" | 361 | """Test the synthesis of the DIR_MOVE event.""" |
137 | 347 | fromdir = os.path.join(self.root_dir, "foo") | 362 | fromdir = os.path.join(self.root_dir, "foo") |
138 | @@ -354,13 +369,15 @@ | |||
139 | 354 | self.monitor.add_to_mute_filter("FS_DIR_MOVE", | 369 | self.monitor.add_to_mute_filter("FS_DIR_MOVE", |
140 | 355 | path_from=fromdir, path_to=todir) | 370 | path_from=fromdir, path_to=todir) |
141 | 356 | self.assertEqual(self._how_many_muted(), 1) | 371 | self.assertEqual(self._how_many_muted(), 1) |
143 | 357 | self.monitor.add_watch(self.root_dir) | 372 | yield self.monitor.add_watch(self.root_dir) |
144 | 358 | 373 | ||
145 | 359 | # generate the event | 374 | # generate the event |
146 | 360 | os.rename(fromdir, todir) | 375 | os.rename(fromdir, todir) |
147 | 361 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 376 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
149 | 362 | return self._deferred | 377 | test_result = yield self._deferred |
150 | 378 | defer.returnValue(test_result) | ||
151 | 363 | 379 | ||
152 | 380 | @defer.inlineCallbacks | ||
153 | 364 | def test_file_moved_from_conflict(self): | 381 | def test_file_moved_from_conflict(self): |
154 | 365 | """Test the handling of the FILE_MOVE event when source is conflict.""" | 382 | """Test the handling of the FILE_MOVE event when source is conflict.""" |
155 | 366 | fromfile = os.path.join(self.root_dir, "foo.u1conflict") | 383 | fromfile = os.path.join(self.root_dir, "foo.u1conflict") |
156 | @@ -373,13 +390,15 @@ | |||
157 | 373 | self.monitor.add_to_mute_filter("FS_FILE_MOVE", | 390 | self.monitor.add_to_mute_filter("FS_FILE_MOVE", |
158 | 374 | path_from=fromfile, path_to=tofile) | 391 | path_from=fromfile, path_to=tofile) |
159 | 375 | self.assertEqual(self._how_many_muted(), 2) | 392 | self.assertEqual(self._how_many_muted(), 2) |
161 | 376 | self.monitor.add_watch(self.root_dir) | 393 | yield self.monitor.add_watch(self.root_dir) |
162 | 377 | 394 | ||
163 | 378 | # generate the event | 395 | # generate the event |
164 | 379 | os.rename(fromfile, tofile) | 396 | os.rename(fromfile, tofile) |
165 | 380 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 397 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
167 | 381 | return self._deferred | 398 | test_result = yield self._deferred |
168 | 399 | defer.returnValue(test_result) | ||
169 | 382 | 400 | ||
170 | 401 | @defer.inlineCallbacks | ||
171 | 383 | def test_file_moved_from_partial(self): | 402 | def test_file_moved_from_partial(self): |
172 | 384 | """Test the handling of the FILE_MOVE event when source is partial.""" | 403 | """Test the handling of the FILE_MOVE event when source is partial.""" |
173 | 385 | fromfile = os.path.join(self.root_dir, "mdid.u1partial.foo") | 404 | fromfile = os.path.join(self.root_dir, "mdid.u1partial.foo") |
174 | @@ -390,9 +409,10 @@ | |||
175 | 390 | self.monitor.add_to_mute_filter("FS_FILE_CREATE", path=tofile) | 409 | self.monitor.add_to_mute_filter("FS_FILE_CREATE", path=tofile) |
176 | 391 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path=tofile) | 410 | self.monitor.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path=tofile) |
177 | 392 | self.assertEqual(self._how_many_muted(), 2) | 411 | self.assertEqual(self._how_many_muted(), 2) |
179 | 393 | self.monitor.add_watch(root_dir) | 412 | yield self.monitor.add_watch(root_dir) |
180 | 394 | 413 | ||
181 | 395 | # generate the event | 414 | # generate the event |
182 | 396 | os.rename(fromfile, tofile) | 415 | os.rename(fromfile, tofile) |
183 | 397 | reactor.callLater(self.timeout - 0.2, self.check_filter) | 416 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
185 | 398 | return self._deferred | 417 | test_result = yield self._deferred |
186 | 418 | defer.returnValue(test_result) | ||
187 | 399 | 419 | ||
188 | === modified file 'tests/syncdaemon/test_vm.py' | |||
189 | --- tests/syncdaemon/test_vm.py 2011-07-28 15:43:05 +0000 | |||
190 | +++ tests/syncdaemon/test_vm.py 2011-07-29 17:35:26 +0000 | |||
191 | @@ -421,7 +421,7 @@ | |||
192 | 421 | self.main.fs.create(path, share.volume_id, is_dir=True) | 421 | self.main.fs.create(path, share.volume_id, is_dir=True) |
193 | 422 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) | 422 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) |
194 | 423 | # add a inotify watch to the dir | 423 | # add a inotify watch to the dir |
196 | 424 | self.main.event_q.add_watch(path) | 424 | yield self.main.event_q.add_watch(path) |
197 | 425 | files = ['a_file', os.path.join('dir', 'file'), | 425 | files = ['a_file', os.path.join('dir', 'file'), |
198 | 426 | os.path.join('dir','subdir','file')] | 426 | os.path.join('dir','subdir','file')] |
199 | 427 | for i, file in enumerate(files): | 427 | for i, file in enumerate(files): |
200 | @@ -824,15 +824,17 @@ | |||
201 | 824 | self.assertEquals('fake_share_uuid', share.node_id) | 824 | self.assertEquals('fake_share_uuid', share.node_id) |
202 | 825 | self.assertEquals(None, self.vm.shares.get('share_id_1')) | 825 | self.assertEquals(None, self.vm.shares.get('share_id_1')) |
203 | 826 | 826 | ||
204 | 827 | @defer.inlineCallbacks | ||
205 | 827 | def test_remove_watch(self): | 828 | def test_remove_watch(self): |
206 | 828 | """Test for VolumeManager._remove_watch""" | 829 | """Test for VolumeManager._remove_watch""" |
207 | 829 | path = os.path.join(self.root_dir, 'dir') | 830 | path = os.path.join(self.root_dir, 'dir') |
208 | 830 | make_dir(path, recursive=True) | 831 | make_dir(path, recursive=True) |
210 | 831 | self.main.event_q.add_watch(path) | 832 | yield self.main.event_q.add_watch(path) |
211 | 832 | self.assertIn(path, self.main.event_q.monitor._general_watchs) | 833 | self.assertIn(path, self.main.event_q.monitor._general_watchs) |
212 | 833 | self.vm._remove_watch(path) | 834 | self.vm._remove_watch(path) |
213 | 834 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs) | 835 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs) |
214 | 835 | 836 | ||
215 | 837 | @defer.inlineCallbacks | ||
216 | 836 | def test_remove_watches(self): | 838 | def test_remove_watches(self): |
217 | 837 | """Test for VolumeManager._remove_watches""" | 839 | """Test for VolumeManager._remove_watches""" |
218 | 838 | dirs = ['dir', os.path.join('dir', 'subdir'), 'emptydir'] | 840 | dirs = ['dir', os.path.join('dir', 'subdir'), 'emptydir'] |
219 | @@ -843,9 +845,9 @@ | |||
220 | 843 | make_dir(path, recursive=True) | 845 | make_dir(path, recursive=True) |
221 | 844 | self.main.fs.create(path, "", is_dir=True) | 846 | self.main.fs.create(path, "", is_dir=True) |
222 | 845 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) | 847 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) |
224 | 846 | self.main.event_q.add_watch(path) | 848 | yield self.main.event_q.add_watch(path) |
225 | 847 | # insert the root_dir in the list | 849 | # insert the root_dir in the list |
227 | 848 | self.main.event_q.add_watch(self.root_dir) | 850 | yield self.main.event_q.add_watch(self.root_dir) |
228 | 849 | paths.insert(0, self.root_dir) | 851 | paths.insert(0, self.root_dir) |
229 | 850 | for path in paths: | 852 | for path in paths: |
230 | 851 | self.assertIn(path, self.main.event_q.monitor._general_watchs) | 853 | self.assertIn(path, self.main.event_q.monitor._general_watchs) |
231 | @@ -854,13 +856,14 @@ | |||
232 | 854 | for path in paths: | 856 | for path in paths: |
233 | 855 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs) | 857 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs) |
234 | 856 | 858 | ||
235 | 859 | @defer.inlineCallbacks | ||
236 | 857 | def test_remove_watches_after_dir_rename(self): | 860 | def test_remove_watches_after_dir_rename(self): |
237 | 858 | """Test for VolumeManager._remove_watches after dir rename.""" | 861 | """Test for VolumeManager._remove_watches after dir rename.""" |
238 | 859 | path = os.path.join(self.root_dir, 'testit') | 862 | path = os.path.join(self.root_dir, 'testit') |
239 | 860 | os.mkdir(path) | 863 | os.mkdir(path) |
240 | 861 | self.main.fs.create(path, "", is_dir=True) | 864 | self.main.fs.create(path, "", is_dir=True) |
241 | 862 | self.main.fs.set_node_id(path, 'dir_node_id') | 865 | self.main.fs.set_node_id(path, 'dir_node_id') |
243 | 863 | self.main.event_q.add_watch(path) | 866 | yield self.main.event_q.add_watch(path) |
244 | 864 | 867 | ||
245 | 865 | os.rename(path, path+'.old') | 868 | os.rename(path, path+'.old') |
246 | 866 | # remove the watches | 869 | # remove the watches |
247 | @@ -869,13 +872,14 @@ | |||
248 | 869 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs, | 872 | self.assertNotIn(path, self.main.event_q.monitor._general_watchs, |
249 | 870 | 'watch should not be present') | 873 | 'watch should not be present') |
250 | 871 | 874 | ||
251 | 875 | @defer.inlineCallbacks | ||
252 | 872 | def test_delete_fsm_object(self): | 876 | def test_delete_fsm_object(self): |
253 | 873 | """Test for VolumeManager._delete_fsm_object""" | 877 | """Test for VolumeManager._delete_fsm_object""" |
254 | 874 | path = os.path.abspath(os.path.join(self.root_dir, 'dir')) | 878 | path = os.path.abspath(os.path.join(self.root_dir, 'dir')) |
255 | 875 | make_dir(path, recursive=True) | 879 | make_dir(path, recursive=True) |
256 | 876 | self.main.fs.create(path, "", is_dir=True) | 880 | self.main.fs.create(path, "", is_dir=True) |
257 | 877 | self.main.fs.set_node_id(path, 'dir_node_id') | 881 | self.main.fs.set_node_id(path, 'dir_node_id') |
259 | 878 | self.main.event_q.add_watch(path) | 882 | yield self.main.event_q.add_watch(path) |
260 | 879 | self.assertIn(path, self.main.event_q.monitor._general_watchs) | 883 | self.assertIn(path, self.main.event_q.monitor._general_watchs) |
261 | 880 | self.assertTrue(self.main.fs.get_by_path(path), path) | 884 | self.assertTrue(self.main.fs.get_by_path(path), path) |
262 | 881 | # remove the watch | 885 | # remove the watch |
263 | @@ -1082,7 +1086,7 @@ | |||
264 | 1082 | self.main.fs.create(path, share.volume_id, is_dir=True) | 1086 | self.main.fs.create(path, share.volume_id, is_dir=True) |
265 | 1083 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) | 1087 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) |
266 | 1084 | # add a inotify watch to the dir | 1088 | # add a inotify watch to the dir |
268 | 1085 | self.main.event_q.add_watch(path) | 1089 | yield self.main.event_q.add_watch(path) |
269 | 1086 | files = ['a_file', os.path.join('dir', 'file'), | 1090 | files = ['a_file', os.path.join('dir', 'file'), |
270 | 1087 | os.path.join('dir','subdir','file')] | 1091 | os.path.join('dir','subdir','file')] |
271 | 1088 | for i, file in enumerate(files): | 1092 | for i, file in enumerate(files): |
272 | @@ -1207,7 +1211,7 @@ | |||
273 | 1207 | # add a inotify watch to the dirs | 1211 | # add a inotify watch to the dirs |
274 | 1208 | for path, is_dir in paths: | 1212 | for path, is_dir in paths: |
275 | 1209 | if is_dir: | 1213 | if is_dir: |
277 | 1210 | self.main.event_q.add_watch(path) | 1214 | yield self.main.event_q.add_watch(path) |
278 | 1211 | self.assertEquals(len(paths), len(dirs+files)+1, paths) | 1215 | self.assertEquals(len(paths), len(dirs+files)+1, paths) |
279 | 1212 | 1216 | ||
280 | 1213 | # unsubscribe from it | 1217 | # unsubscribe from it |
281 | @@ -1420,7 +1424,7 @@ | |||
282 | 1420 | self.main.fs.create(path, udf.volume_id, is_dir=True) | 1424 | self.main.fs.create(path, udf.volume_id, is_dir=True) |
283 | 1421 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) | 1425 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) |
284 | 1422 | # add a inotify watch to the dir | 1426 | # add a inotify watch to the dir |
286 | 1423 | self.main.event_q.add_watch(path) | 1427 | yield self.main.event_q.add_watch(path) |
287 | 1424 | files = ['a_file', os.path.join('dir','file'), | 1428 | files = ['a_file', os.path.join('dir','file'), |
288 | 1425 | os.path.join('dir','subdir','file')] | 1429 | os.path.join('dir','subdir','file')] |
289 | 1426 | for i, file in enumerate(files): | 1430 | for i, file in enumerate(files): |
290 | @@ -2038,7 +2042,7 @@ | |||
291 | 2038 | self.main.fs.create(path, udf.volume_id, is_dir=True) | 2042 | self.main.fs.create(path, udf.volume_id, is_dir=True) |
292 | 2039 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) | 2043 | self.main.fs.set_node_id(path, 'dir_node_id'+str(i)) |
293 | 2040 | # add a inotify watch to the dir | 2044 | # add a inotify watch to the dir |
295 | 2041 | self.main.event_q.add_watch(path) | 2045 | yield self.main.event_q.add_watch(path) |
296 | 2042 | files = ['a_file', os.path.join('dir','file'), | 2046 | files = ['a_file', os.path.join('dir','file'), |
297 | 2043 | os.path.join('dir','subdir','file')] | 2047 | os.path.join('dir','subdir','file')] |
298 | 2044 | for i, file in enumerate(files): | 2048 | for i, file in enumerate(files): |
299 | @@ -2095,7 +2099,7 @@ | |||
300 | 2095 | # add a inotify watch to the dirs | 2099 | # add a inotify watch to the dirs |
301 | 2096 | for path, is_dir in paths: | 2100 | for path, is_dir in paths: |
302 | 2097 | if is_dir: | 2101 | if is_dir: |
304 | 2098 | self.main.event_q.add_watch(path) | 2102 | yield self.main.event_q.add_watch(path) |
305 | 2099 | self.assertEquals(len(paths), len(dirs+files)+1, paths) | 2103 | self.assertEquals(len(paths), len(dirs+files)+1, paths) |
306 | 2100 | 2104 | ||
307 | 2101 | # unsubscribe from it | 2105 | # unsubscribe from it |
308 | 2102 | 2106 | ||
309 | === modified file 'ubuntuone/platform/linux/filesystem_notifications.py' | |||
310 | --- ubuntuone/platform/linux/filesystem_notifications.py 2011-07-27 17:10:57 +0000 | |||
311 | +++ ubuntuone/platform/linux/filesystem_notifications.py 2011-07-29 17:35:26 +0000 | |||
312 | @@ -457,13 +457,13 @@ | |||
313 | 457 | # not add it if already there | 457 | # not add it if already there |
314 | 458 | if dirpath in w_dict: | 458 | if dirpath in w_dict: |
315 | 459 | self.log.debug("Watch already there for %r", dirpath) | 459 | self.log.debug("Watch already there for %r", dirpath) |
317 | 460 | return False | 460 | return defer.succeed(False) |
318 | 461 | 461 | ||
319 | 462 | # add the watch! | 462 | # add the watch! |
320 | 463 | self.log.debug("Adding %s inotify watch to %r", w_type, dirpath) | 463 | self.log.debug("Adding %s inotify watch to %r", w_type, dirpath) |
321 | 464 | result = w_manager.add_watch(dirpath, events) | 464 | result = w_manager.add_watch(dirpath, events) |
322 | 465 | w_dict[dirpath] = result[dirpath] | 465 | w_dict[dirpath] = result[dirpath] |
324 | 466 | return True | 466 | return defer.succeed(True) |
325 | 467 | 467 | ||
326 | 468 | def inotify_watch_fix(self, pathfrom, pathto): | 468 | def inotify_watch_fix(self, pathfrom, pathto): |
327 | 469 | """Fix the path in inotify structures.""" | 469 | """Fix the path in inotify structures.""" |
328 | 470 | 470 | ||
329 | === modified file 'ubuntuone/platform/windows/filesystem_notifications.py' | |||
330 | --- ubuntuone/platform/windows/filesystem_notifications.py 2011-07-29 17:35:26 +0000 | |||
331 | +++ ubuntuone/platform/windows/filesystem_notifications.py 2011-07-29 17:35:26 +0000 | |||
332 | @@ -695,8 +695,10 @@ | |||
333 | 695 | # is also watching it kids | 695 | # is also watching it kids |
334 | 696 | if not self._watch_manager.get_wd(dirpath): | 696 | if not self._watch_manager.get_wd(dirpath): |
335 | 697 | # we need to add a watch which will also watch its kids | 697 | # we need to add a watch which will also watch its kids |
338 | 698 | self._watch_manager.add_watch(dirpath, FILESYSTEM_MONITOR_MASK, | 698 | return self._watch_manager.add_watch(dirpath, |
339 | 699 | auto_add=True) | 699 | FILESYSTEM_MONITOR_MASK, |
340 | 700 | auto_add=True) | ||
341 | 701 | return defer.succeed(True) | ||
342 | 700 | 702 | ||
343 | 701 | def is_frozen(self): | 703 | def is_frozen(self): |
344 | 702 | """Checks if there's something frozen.""" | 704 | """Checks if there's something frozen.""" |
345 | 703 | 705 | ||
346 | === modified file 'ubuntuone/syncdaemon/local_rescan.py' | |||
347 | --- ubuntuone/syncdaemon/local_rescan.py 2011-07-27 17:10:57 +0000 | |||
348 | +++ ubuntuone/syncdaemon/local_rescan.py 2011-07-29 17:35:26 +0000 | |||
349 | @@ -235,6 +235,7 @@ | |||
350 | 235 | self._process_next_queue(None) | 235 | self._process_next_queue(None) |
351 | 236 | return self._previous_deferred | 236 | return self._previous_deferred |
352 | 237 | 237 | ||
353 | 238 | @defer.inlineCallbacks | ||
354 | 238 | def _add_watches_to_udf_ancestors(self, volume): | 239 | def _add_watches_to_udf_ancestors(self, volume): |
355 | 239 | """Add a inotify watch to volume's ancestors if it's an UDF.""" | 240 | """Add a inotify watch to volume's ancestors if it's an UDF.""" |
356 | 240 | added_watches = [] | 241 | added_watches = [] |
357 | @@ -252,10 +253,10 @@ | |||
358 | 252 | if not access(ancestor): | 253 | if not access(ancestor): |
359 | 253 | log_info("Tree broken at path: %r", volume.path) | 254 | log_info("Tree broken at path: %r", volume.path) |
360 | 254 | revert_watches() | 255 | revert_watches() |
362 | 255 | return False | 256 | defer.returnValue(False) |
363 | 256 | 257 | ||
364 | 257 | log_debug("Adding watch to UDF's ancestor %r", ancestor) | 258 | log_debug("Adding watch to UDF's ancestor %r", ancestor) |
366 | 258 | really_added = self.eq.add_watch(ancestor) | 259 | really_added = yield self.eq.add_watch(ancestor) |
367 | 259 | # only note it for the revert if the watch was not there before | 260 | # only note it for the revert if the watch was not there before |
368 | 260 | if really_added: | 261 | if really_added: |
369 | 261 | added_watches.append(ancestor) | 262 | added_watches.append(ancestor) |
370 | @@ -263,10 +264,10 @@ | |||
371 | 263 | # finally, check that UDF is ok in disk | 264 | # finally, check that UDF is ok in disk |
372 | 264 | if not access(volume.path): | 265 | if not access(volume.path): |
373 | 265 | revert_watches() | 266 | revert_watches() |
375 | 266 | return False | 267 | defer.returnValue(False) |
376 | 267 | 268 | ||
377 | 268 | # all is ok | 269 | # all is ok |
379 | 269 | return True | 270 | defer.returnValue(True) |
380 | 270 | 271 | ||
381 | 271 | def _process_next_queue(self, _): | 272 | def _process_next_queue(self, _): |
382 | 272 | """Process the next item in the queue, if any.""" | 273 | """Process the next item in the queue, if any.""" |
383 | @@ -280,13 +281,14 @@ | |||
384 | 280 | # more to scan | 281 | # more to scan |
385 | 281 | scan_info = self._queue.pop() | 282 | scan_info = self._queue.pop() |
386 | 282 | 283 | ||
387 | 284 | @defer.inlineCallbacks | ||
388 | 283 | def safe_scan(): | 285 | def safe_scan(): |
389 | 284 | """Scan safely""" | 286 | """Scan safely""" |
390 | 285 | try: | 287 | try: |
391 | 286 | # add watches to UDF ancestors and check UDF is ok | 288 | # add watches to UDF ancestors and check UDF is ok |
392 | 287 | volume = scan_info[0] | 289 | volume = scan_info[0] |
393 | 288 | if isinstance(volume, volume_manager.UDF): | 290 | if isinstance(volume, volume_manager.UDF): |
395 | 289 | udf_ok = self._add_watches_to_udf_ancestors(volume) | 291 | udf_ok = yield self._add_watches_to_udf_ancestors(volume) |
396 | 290 | if not udf_ok: | 292 | if not udf_ok: |
397 | 291 | self._process_next_queue(None) | 293 | self._process_next_queue(None) |
398 | 292 | return | 294 | return |
399 | @@ -615,12 +617,13 @@ | |||
400 | 615 | filesdirs[fname] = is_dir, statinfo, changed | 617 | filesdirs[fname] = is_dir, statinfo, changed |
401 | 616 | return filesdirs | 618 | return filesdirs |
402 | 617 | 619 | ||
403 | 620 | @defer.inlineCallbacks | ||
404 | 618 | def _scan_one_dir(self, scan_info): | 621 | def _scan_one_dir(self, scan_info): |
405 | 619 | """Gets one dir and compares with fsm.""" | 622 | """Gets one dir and compares with fsm.""" |
406 | 620 | share, dirpath, udf_mode = scan_info | 623 | share, dirpath, udf_mode = scan_info |
407 | 621 | 624 | ||
408 | 622 | log_debug("Adding watch to %r", dirpath) | 625 | log_debug("Adding watch to %r", dirpath) |
410 | 623 | self.eq.add_watch(dirpath) | 626 | yield self.eq.add_watch(dirpath) |
411 | 624 | 627 | ||
412 | 625 | to_later = [] | 628 | to_later = [] |
413 | 626 | self.eq.freeze_begin(dirpath) | 629 | self.eq.freeze_begin(dirpath) |
414 | @@ -698,4 +701,5 @@ | |||
415 | 698 | d.addCallback(filter_delete_events) | 701 | d.addCallback(filter_delete_events) |
416 | 699 | d.addCallback(self.eq.freeze_commit) | 702 | d.addCallback(self.eq.freeze_commit) |
417 | 700 | d.addCallback(control) | 703 | d.addCallback(control) |
419 | 701 | return d | 704 | result = yield d |
420 | 705 | defer.returnValue(result) | ||
421 | 702 | 706 | ||
422 | === modified file 'ubuntuone/syncdaemon/volume_manager.py' | |||
423 | --- ubuntuone/syncdaemon/volume_manager.py 2011-07-28 15:43:05 +0000 | |||
424 | +++ ubuntuone/syncdaemon/volume_manager.py 2011-07-29 17:35:26 +0000 | |||
425 | @@ -943,6 +943,7 @@ | |||
426 | 943 | self.shares[share.volume_id] = share | 943 | self.shares[share.volume_id] = share |
427 | 944 | self.m.event_q.push('VM_SHARE_CHANGED', share_id=share.volume_id) | 944 | self.m.event_q.push('VM_SHARE_CHANGED', share_id=share.volume_id) |
428 | 945 | 945 | ||
429 | 946 | @defer.inlineCallbacks | ||
430 | 946 | def _create_share_dir(self, share): | 947 | def _create_share_dir(self, share): |
431 | 947 | """ Creates the share root dir, and set the permissions. """ | 948 | """ Creates the share root dir, and set the permissions. """ |
432 | 948 | # XXX: verterok: This is going to be moved into fsm | 949 | # XXX: verterok: This is going to be moved into fsm |
433 | @@ -953,7 +954,7 @@ | |||
434 | 953 | # add the watch after the mkdir | 954 | # add the watch after the mkdir |
435 | 954 | if share.can_write(): | 955 | if share.can_write(): |
436 | 955 | self.log.debug('adding inotify watch to: %s', share.path) | 956 | self.log.debug('adding inotify watch to: %s', share.path) |
438 | 956 | self.m.event_q.add_watch(share.path) | 957 | yield self.m.event_q.add_watch(share.path) |
439 | 957 | # if it's a ro share, change the perms | 958 | # if it's a ro share, change the perms |
440 | 958 | if not share.can_write(): | 959 | if not share.can_write(): |
441 | 959 | set_dir_readonly(share.path) | 960 | set_dir_readonly(share.path) |
442 | @@ -1949,4 +1950,3 @@ | |||
443 | 1949 | def _serialize(self, value): | 1950 | def _serialize(self, value): |
444 | 1950 | """Serialize value to string using protocol.""" | 1951 | """Serialize value to string using protocol.""" |
445 | 1951 | return cPickle.dumps(value.__dict__, protocol=2) | 1952 | return cPickle.dumps(value.__dict__, protocol=2) |
446 | 1952 |
Looks good!