Merge lp:~facundo/ubuntuone-client/non-bouncing-filesystem into lp:ubuntuone-client
- non-bouncing-filesystem
- Merge into trunk
Proposed by
Facundo Batista
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Guillermo Gonzalez | ||||
Approved revision: | 256 | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~facundo/ubuntuone-client/non-bouncing-filesystem | ||||
Merge into: | lp:ubuntuone-client | ||||
Diff against target: |
689 lines 9 files modified
contrib/testing/testcase.py (+1/-0) tests/syncdaemon/test_eq_inotify.py (+179/-0) tests/syncdaemon/test_eventqueue.py (+66/-0) tests/syncdaemon/test_fsm.py (+15/-6) tests/syncdaemon/test_localrescan.py (+4/-2) tests/syncdaemon/test_sync.py (+4/-0) ubuntuone/syncdaemon/event_queue.py (+69/-13) ubuntuone/syncdaemon/filesystem_manager.py (+26/-2) ubuntuone/syncdaemon/main.py (+1/-0) |
||||
To merge this branch: | bzr merge lp:~facundo/ubuntuone-client/non-bouncing-filesystem | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guillermo Gonzalez | Approve | ||
John Lenton (community) | Approve | ||
Ubuntu One hackers | Pending | ||
Review via email: mp+13419@code.launchpad.net |
Commit message
Now we avoid the filesystem event bouncing.
Description of the change
To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote : | # |
Revision history for this message
John Lenton (chipaca) wrote : | # |
I love it. Lurve, lurve, luv it.
review:
Approve
Revision history for this message
Guillermo Gonzalez (verterok) wrote : | # |
I *really* like this
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'contrib/testing/testcase.py' | |||
2 | --- contrib/testing/testcase.py 2009-10-12 16:00:16 +0000 | |||
3 | +++ contrib/testing/testcase.py 2009-10-15 15:40:24 +0000 | |||
4 | @@ -102,6 +102,7 @@ | |||
5 | 102 | self.fs = fs_manager.FileSystemManager(self.data_dir, | 102 | self.fs = fs_manager.FileSystemManager(self.data_dir, |
6 | 103 | self.partials_dir, self.vm) | 103 | self.partials_dir, self.vm) |
7 | 104 | self.event_q = event_queue.EventQueue(self.fs) | 104 | self.event_q = event_queue.EventQueue(self.fs) |
8 | 105 | self.fs.register_eq(self.event_q) | ||
9 | 105 | self.action_q = FakeActionQueue(self.event_q) | 106 | self.action_q = FakeActionQueue(self.event_q) |
10 | 106 | self.state = main.SyncDaemonStateManager(self, 2, 0) | 107 | self.state = main.SyncDaemonStateManager(self, 2, 0) |
11 | 107 | self.event_q.subscribe(self.vm) | 108 | self.event_q.subscribe(self.vm) |
12 | 108 | 109 | ||
13 | === modified file 'tests/syncdaemon/test_eq_inotify.py' | |||
14 | --- tests/syncdaemon/test_eq_inotify.py 2009-09-30 18:02:18 +0000 | |||
15 | +++ tests/syncdaemon/test_eq_inotify.py 2009-10-15 15:40:24 +0000 | |||
16 | @@ -885,6 +885,185 @@ | |||
17 | 885 | return self._deferred | 885 | return self._deferred |
18 | 886 | 886 | ||
19 | 887 | 887 | ||
20 | 888 | class MutedSignalsTests(BaseTwisted): | ||
21 | 889 | '''Test that EQ filter some signals on demand.''' | ||
22 | 890 | |||
23 | 891 | class DontHitMe(object): | ||
24 | 892 | '''we shouldn't be called''' | ||
25 | 893 | # class-closure, cannot use self, pylint: disable-msg=E0213 | ||
26 | 894 | def __init__(innerself, obj): | ||
27 | 895 | innerself.obj = obj | ||
28 | 896 | def handle_default(innerself, *a): | ||
29 | 897 | '''Something here? Error!''' | ||
30 | 898 | innerself.obj.finished_error("don't hit me! received %s" % (a,)) | ||
31 | 899 | |||
32 | 900 | def check_filter(self, _=None): | ||
33 | 901 | self.assertFalse(self.eq._processor._to_mute._cnt) | ||
34 | 902 | self.finished_ok() | ||
35 | 903 | |||
36 | 904 | def test_file_open(self): | ||
37 | 905 | '''Test receiving the open signal on files.''' | ||
38 | 906 | testfile = os.path.join(self.root_dir, "foo") | ||
39 | 907 | open(testfile, "w").close() | ||
40 | 908 | self.eq.add_to_mute_filter("FS_FILE_OPEN", testfile) | ||
41 | 909 | self.eq.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", testfile) | ||
42 | 910 | |||
43 | 911 | self.eq.inotify_add_watch(self.root_dir) | ||
44 | 912 | self.eq.subscribe(self.DontHitMe(self)) | ||
45 | 913 | |||
46 | 914 | # generate the event | ||
47 | 915 | open(testfile) | ||
48 | 916 | reactor.callLater(.1, self.check_filter) | ||
49 | 917 | return self._deferred | ||
50 | 918 | |||
51 | 919 | def test_file_close_nowrite(self): | ||
52 | 920 | '''Test receiving the close_nowrite signal on files.''' | ||
53 | 921 | testfile = os.path.join(self.root_dir, "foo") | ||
54 | 922 | open(testfile, "w").close() | ||
55 | 923 | fh = open(testfile) | ||
56 | 924 | self.eq.add_to_mute_filter("FS_FILE_CLOSE_NOWRITE", testfile) | ||
57 | 925 | |||
58 | 926 | self.eq.inotify_add_watch(self.root_dir) | ||
59 | 927 | self.eq.subscribe(self.DontHitMe(self)) | ||
60 | 928 | |||
61 | 929 | # generate the event | ||
62 | 930 | fh.close() | ||
63 | 931 | reactor.callLater(.1, self.check_filter) | ||
64 | 932 | return self._deferred | ||
65 | 933 | |||
66 | 934 | def test_file_create_close_write(self): | ||
67 | 935 | '''Test receiving the create and close_write signals on files.''' | ||
68 | 936 | testfile = os.path.join(self.root_dir, "foo") | ||
69 | 937 | self.eq.add_to_mute_filter("FS_FILE_CREATE", testfile) | ||
70 | 938 | self.eq.add_to_mute_filter("FS_FILE_OPEN", testfile) | ||
71 | 939 | self.eq.add_to_mute_filter("FS_FILE_CLOSE_WRITE", testfile) | ||
72 | 940 | |||
73 | 941 | self.eq.inotify_add_watch(self.root_dir) | ||
74 | 942 | self.eq.subscribe(self.DontHitMe(self)) | ||
75 | 943 | |||
76 | 944 | # generate the event | ||
77 | 945 | open(testfile, "w").close() | ||
78 | 946 | reactor.callLater(.1, self.check_filter) | ||
79 | 947 | return self._deferred | ||
80 | 948 | |||
81 | 949 | def test_dir_create(self): | ||
82 | 950 | '''Test receiving the create signal on dirs.''' | ||
83 | 951 | testdir = os.path.join(self.root_dir, "foo") | ||
84 | 952 | self.eq.add_to_mute_filter("FS_DIR_CREATE", testdir) | ||
85 | 953 | |||
86 | 954 | self.eq.inotify_add_watch(self.root_dir) | ||
87 | 955 | self.eq.subscribe(self.DontHitMe(self)) | ||
88 | 956 | |||
89 | 957 | # generate the event | ||
90 | 958 | os.mkdir(testdir) | ||
91 | 959 | reactor.callLater(.1, self.check_filter) | ||
92 | 960 | return self._deferred | ||
93 | 961 | |||
94 | 962 | def test_file_delete(self): | ||
95 | 963 | '''Test the delete signal on a file.''' | ||
96 | 964 | testfile = os.path.join(self.root_dir, "foo") | ||
97 | 965 | open(testfile, "w").close() | ||
98 | 966 | self.eq.add_to_mute_filter("FS_FILE_DELETE", testfile) | ||
99 | 967 | |||
100 | 968 | self.eq.inotify_add_watch(self.root_dir) | ||
101 | 969 | self.eq.subscribe(self.DontHitMe(self)) | ||
102 | 970 | |||
103 | 971 | # generate the event | ||
104 | 972 | os.remove(testfile) | ||
105 | 973 | reactor.callLater(.1, self.check_filter) | ||
106 | 974 | return self._deferred | ||
107 | 975 | |||
108 | 976 | def test_dir_delete(self): | ||
109 | 977 | '''Test the delete signal on a dir.''' | ||
110 | 978 | testdir = os.path.join(self.root_dir, "foo") | ||
111 | 979 | os.mkdir(testdir) | ||
112 | 980 | self.eq.add_to_mute_filter("FS_DIR_DELETE", testdir) | ||
113 | 981 | |||
114 | 982 | self.eq.inotify_add_watch(self.root_dir) | ||
115 | 983 | self.eq.subscribe(self.DontHitMe(self)) | ||
116 | 984 | |||
117 | 985 | # generate the event | ||
118 | 986 | os.rmdir(testdir) | ||
119 | 987 | reactor.callLater(.1, self.check_filter) | ||
120 | 988 | return self._deferred | ||
121 | 989 | |||
122 | 990 | def test_file_moved_inside(self): | ||
123 | 991 | '''Test the synthesis of the FILE_MOVE event.''' | ||
124 | 992 | fromfile = os.path.join(self.root_dir, "foo") | ||
125 | 993 | self.fs.create(fromfile, "") | ||
126 | 994 | self.fs.set_node_id(fromfile, "from_node_id") | ||
127 | 995 | tofile = os.path.join(self.root_dir, "bar") | ||
128 | 996 | self.fs.create(tofile, "") | ||
129 | 997 | self.fs.set_node_id(tofile, "to_node_id") | ||
130 | 998 | open(fromfile, "w").close() | ||
131 | 999 | self.eq.add_to_mute_filter("FS_FILE_MOVE", fromfile, tofile) | ||
132 | 1000 | |||
133 | 1001 | self.eq.inotify_add_watch(self.root_dir) | ||
134 | 1002 | self.eq.subscribe(self.DontHitMe(self)) | ||
135 | 1003 | |||
136 | 1004 | # generate the event | ||
137 | 1005 | os.rename(fromfile, tofile) | ||
138 | 1006 | reactor.callLater(.1, self.check_filter) | ||
139 | 1007 | return self._deferred | ||
140 | 1008 | |||
141 | 1009 | def test_dir_moved_inside(self): | ||
142 | 1010 | '''Test the synthesis of the DIR_MOVE event.''' | ||
143 | 1011 | fromdir = os.path.join(self.root_dir, "foo") | ||
144 | 1012 | self.fs.create(fromdir, "") | ||
145 | 1013 | self.fs.set_node_id(fromdir, "from_node_id") | ||
146 | 1014 | todir = os.path.join(self.root_dir, "bar") | ||
147 | 1015 | self.fs.create(todir, "") | ||
148 | 1016 | self.fs.set_node_id(todir, "to_node_id") | ||
149 | 1017 | os.mkdir(fromdir) | ||
150 | 1018 | self.eq.add_to_mute_filter("FS_DIR_MOVE", fromdir, todir) | ||
151 | 1019 | |||
152 | 1020 | self.eq.inotify_add_watch(self.root_dir) | ||
153 | 1021 | self.eq.subscribe(self.DontHitMe(self)) | ||
154 | 1022 | |||
155 | 1023 | # generate the event | ||
156 | 1024 | os.rename(fromdir, todir) | ||
157 | 1025 | reactor.callLater(.1, self.check_filter) | ||
158 | 1026 | return self._deferred | ||
159 | 1027 | |||
160 | 1028 | def test_file_moved_to_conflict(self): | ||
161 | 1029 | '''Test the handling of the FILE_MOVE event when dest is conflict.''' | ||
162 | 1030 | fromfile = os.path.join(self.root_dir, "foo") | ||
163 | 1031 | self.fs.create(fromfile, "") | ||
164 | 1032 | self.fs.set_node_id(fromfile, "from_node_id") | ||
165 | 1033 | tofile = os.path.join(self.root_dir, "foo.u1conflict") | ||
166 | 1034 | self.fs.create(tofile, "") | ||
167 | 1035 | self.fs.set_node_id(tofile, "to_node_id") | ||
168 | 1036 | open(fromfile, "w").close() | ||
169 | 1037 | self.eq.add_to_mute_filter("FS_FILE_MOVE", fromfile, tofile) | ||
170 | 1038 | |||
171 | 1039 | self.eq.inotify_add_watch(self.root_dir) | ||
172 | 1040 | self.eq.subscribe(self.DontHitMe(self)) | ||
173 | 1041 | |||
174 | 1042 | # generate the event | ||
175 | 1043 | os.rename(fromfile, tofile) | ||
176 | 1044 | reactor.callLater(.1, self.check_filter) | ||
177 | 1045 | return self._deferred | ||
178 | 1046 | |||
179 | 1047 | def test_file_moved_from_partial(self): | ||
180 | 1048 | '''Test the handling of the FILE_MOVE event when source is partial.''' | ||
181 | 1049 | fromfile = os.path.join(self.root_dir, "mdid.u1partial.foo") | ||
182 | 1050 | root_dir = os.path.join(self.root_dir, "my_files") | ||
183 | 1051 | tofile = os.path.join(root_dir, "foo") | ||
184 | 1052 | mypath = functools.partial(os.path.join, root_dir) | ||
185 | 1053 | os.mkdir(root_dir) | ||
186 | 1054 | open(fromfile, "w").close() | ||
187 | 1055 | self.eq.add_to_mute_filter("FS_FILE_CREATE", tofile) | ||
188 | 1056 | self.eq.add_to_mute_filter("FS_FILE_CLOSE_WRITE", tofile) | ||
189 | 1057 | |||
190 | 1058 | self.eq.inotify_add_watch(root_dir) | ||
191 | 1059 | self.eq.subscribe(self.DontHitMe(self)) | ||
192 | 1060 | |||
193 | 1061 | # generate the event | ||
194 | 1062 | os.rename(fromfile, tofile) | ||
195 | 1063 | reactor.callLater(.1, self.check_filter) | ||
196 | 1064 | return self._deferred | ||
197 | 1065 | |||
198 | 1066 | |||
199 | 888 | def test_suite(): | 1067 | def test_suite(): |
200 | 889 | # pylint: disable-msg=C0111 | 1068 | # pylint: disable-msg=C0111 |
201 | 890 | return unittest.TestLoader().loadTestsFromName(__name__) | 1069 | return unittest.TestLoader().loadTestsFromName(__name__) |
202 | 891 | 1070 | ||
203 | === modified file 'tests/syncdaemon/test_eventqueue.py' | |||
204 | --- tests/syncdaemon/test_eventqueue.py 2009-09-01 20:35:36 +0000 | |||
205 | +++ tests/syncdaemon/test_eventqueue.py 2009-10-15 15:40:24 +0000 | |||
206 | @@ -47,6 +47,7 @@ | |||
207 | 47 | self.fs.set_by_path(path=self.root_dir, | 47 | self.fs.set_by_path(path=self.root_dir, |
208 | 48 | local_hash=None, server_hash=None) | 48 | local_hash=None, server_hash=None) |
209 | 49 | self.eq = event_queue.EventQueue(self.fs) | 49 | self.eq = event_queue.EventQueue(self.fs) |
210 | 50 | self.fs.register_eq(self.eq) | ||
211 | 50 | 51 | ||
212 | 51 | def tearDown(self): | 52 | def tearDown(self): |
213 | 52 | '''Clean up the tests.''' | 53 | '''Clean up the tests.''' |
214 | @@ -301,6 +302,71 @@ | |||
215 | 301 | return d | 302 | return d |
216 | 302 | 303 | ||
217 | 303 | 304 | ||
218 | 305 | class MuteFilterTests(unittest.TestCase): | ||
219 | 306 | '''Tests the MuteFilter class.''' | ||
220 | 307 | |||
221 | 308 | def setUp(self): | ||
222 | 309 | self.mf = event_queue.MuteFilter() | ||
223 | 310 | |||
224 | 311 | def test_empty(self): | ||
225 | 312 | '''Nothing there.''' | ||
226 | 313 | self.assertFalse(self.mf._cnt) | ||
227 | 314 | |||
228 | 315 | def test_add_one(self): | ||
229 | 316 | '''Adds one element.''' | ||
230 | 317 | self.mf.add("foo") | ||
231 | 318 | self.assertEqual(self.mf._cnt, dict(foo=1)) | ||
232 | 319 | |||
233 | 320 | def test_add_two_different(self): | ||
234 | 321 | '''Adds two different elements.''' | ||
235 | 322 | self.mf.add("foo") | ||
236 | 323 | self.mf.add("bar") | ||
237 | 324 | self.assertEqual(self.mf._cnt, dict(foo=1, bar=1)) | ||
238 | 325 | |||
239 | 326 | def test_add_two_equal(self): | ||
240 | 327 | '''Adds one element twice.''' | ||
241 | 328 | self.mf.add("foo") | ||
242 | 329 | self.mf.add("foo") | ||
243 | 330 | self.assertEqual(self.mf._cnt, dict(foo=2)) | ||
244 | 331 | |||
245 | 332 | def test_add_two_equal_and_third(self): | ||
246 | 333 | '''Adds one element.''' | ||
247 | 334 | self.mf.add("foo") | ||
248 | 335 | self.mf.add("bar") | ||
249 | 336 | self.mf.add("bar") | ||
250 | 337 | self.assertEqual(self.mf._cnt, dict(foo=1, bar=2)) | ||
251 | 338 | |||
252 | 339 | def test_pop_simple(self): | ||
253 | 340 | '''Pops one element.''' | ||
254 | 341 | self.mf.add("foo") | ||
255 | 342 | self.assertFalse(self.mf.pop("bar")) | ||
256 | 343 | self.assertEqual(self.mf._cnt, dict(foo=1)) | ||
257 | 344 | self.assertTrue(self.mf.pop("foo")) | ||
258 | 345 | self.assertFalse(self.mf._cnt) | ||
259 | 346 | |||
260 | 347 | def test_pop_complex(self): | ||
261 | 348 | '''Pops several elements.''' | ||
262 | 349 | # add several | ||
263 | 350 | self.mf.add("foo") | ||
264 | 351 | self.mf.add("bar") | ||
265 | 352 | self.mf.add("bar") | ||
266 | 353 | self.assertEqual(self.mf._cnt, dict(foo=1, bar=2)) | ||
267 | 354 | |||
268 | 355 | # clean bar | ||
269 | 356 | self.assertTrue(self.mf.pop("bar")) | ||
270 | 357 | self.assertEqual(self.mf._cnt, dict(foo=1, bar=1)) | ||
271 | 358 | self.assertTrue(self.mf.pop("bar")) | ||
272 | 359 | self.assertEqual(self.mf._cnt, dict(foo=1)) | ||
273 | 360 | self.assertFalse(self.mf.pop("bar")) | ||
274 | 361 | self.assertEqual(self.mf._cnt, dict(foo=1)) | ||
275 | 362 | |||
276 | 363 | # clean foo | ||
277 | 364 | self.assertTrue(self.mf.pop("foo")) | ||
278 | 365 | self.assertFalse(self.mf._cnt) | ||
279 | 366 | self.assertFalse(self.mf.pop("foo")) | ||
280 | 367 | self.assertFalse(self.mf._cnt) | ||
281 | 368 | |||
282 | 369 | |||
283 | 304 | def test_suite(): | 370 | def test_suite(): |
284 | 305 | # pylint: disable-msg=C0111 | 371 | # pylint: disable-msg=C0111 |
285 | 306 | return unittest.TestLoader().loadTestsFromName(__name__) | 372 | return unittest.TestLoader().loadTestsFromName(__name__) |
286 | 307 | 373 | ||
287 | === modified file 'tests/syncdaemon/test_fsm.py' | |||
288 | --- tests/syncdaemon/test_fsm.py 2009-10-09 17:52:07 +0000 | |||
289 | +++ tests/syncdaemon/test_fsm.py 2009-10-15 15:40:24 +0000 | |||
290 | @@ -36,6 +36,7 @@ | |||
291 | 36 | METADATA_VERSION, | 36 | METADATA_VERSION, |
292 | 37 | ) | 37 | ) |
293 | 38 | from ubuntuone.syncdaemon.volume_manager import Share, allow_writes | 38 | from ubuntuone.syncdaemon.volume_manager import Share, allow_writes |
294 | 39 | from ubuntuone.syncdaemon.event_queue import EventQueue | ||
295 | 39 | 40 | ||
296 | 40 | TESTS_DIR = os.path.join(os.getcwd(), "tmp") | 41 | TESTS_DIR = os.path.join(os.getcwd(), "tmp") |
297 | 41 | 42 | ||
298 | @@ -62,12 +63,15 @@ | |||
299 | 62 | self.partials_dir = os.path.join(TESTS_DIR, "partials") | 63 | self.partials_dir = os.path.join(TESTS_DIR, "partials") |
300 | 63 | self.fsm = FileSystemManager(self.fsmdir, self.partials_dir, | 64 | self.fsm = FileSystemManager(self.fsmdir, self.partials_dir, |
301 | 64 | FakeVolumeManager(self.root_dir)) | 65 | FakeVolumeManager(self.root_dir)) |
302 | 66 | self.eq = EventQueue(self.fsm) | ||
303 | 67 | self.fsm.register_eq(self.eq) | ||
304 | 65 | self.share = self.create_share('share', 'share_name', | 68 | self.share = self.create_share('share', 'share_name', |
305 | 66 | self.fsm, self.shares_dir) | 69 | self.fsm, self.shares_dir) |
306 | 67 | self.share_path = self.share.path | 70 | self.share_path = self.share.path |
307 | 68 | 71 | ||
308 | 69 | def tearDown(self): | 72 | def tearDown(self): |
309 | 70 | """ Clean up the tests. """ | 73 | """ Clean up the tests. """ |
310 | 74 | self.eq.shutdown() | ||
311 | 71 | self.rmtree(TESTS_DIR) | 75 | self.rmtree(TESTS_DIR) |
312 | 72 | 76 | ||
313 | 73 | @staticmethod | 77 | @staticmethod |
314 | @@ -2090,7 +2094,7 @@ | |||
315 | 2090 | os.chmod(os.path.join(dirpath, dir), 0777) | 2094 | os.chmod(os.path.join(dirpath, dir), 0777) |
316 | 2091 | for file in files: | 2095 | for file in files: |
317 | 2092 | os.chmod(os.path.join(dirpath, file), 0666) | 2096 | os.chmod(os.path.join(dirpath, file), 0666) |
319 | 2093 | shutil.rmtree(TESTS_DIR) | 2097 | FSMTestCase.tearDown(self) |
320 | 2094 | 2098 | ||
321 | 2095 | def test_file_ro_share_fail(self): | 2099 | def test_file_ro_share_fail(self): |
322 | 2096 | """ Test that manual creation of a file, fails on a ro-share. """ | 2100 | """ Test that manual creation of a file, fails on a ro-share. """ |
323 | @@ -2241,21 +2245,25 @@ | |||
324 | 2241 | FSMTestCase.setUp(self) | 2245 | FSMTestCase.setUp(self) |
325 | 2242 | # create a ro share | 2246 | # create a ro share |
326 | 2243 | self.share_ro = self.create_share('share_ro', 'share_ro_name', | 2247 | self.share_ro = self.create_share('share_ro', 'share_ro_name', |
328 | 2244 | self.fsm, self.shares_dir, access_level='View') | 2248 | self.fsm, self.shares_dir, |
329 | 2249 | access_level='View') | ||
330 | 2245 | self.share_ro_path = self.share_ro.path | 2250 | self.share_ro_path = self.share_ro.path |
331 | 2246 | 2251 | ||
332 | 2247 | def test_write_in_ro_share(self): | 2252 | def test_write_in_ro_share(self): |
333 | 2248 | """test the EnableShareWrite context manager in a ro share""" | 2253 | """test the EnableShareWrite context manager in a ro share""" |
334 | 2249 | path = os.path.join(self.share_ro_path, 'foo', 'a_file_in_a_ro_share') | 2254 | path = os.path.join(self.share_ro_path, 'foo', 'a_file_in_a_ro_share') |
335 | 2250 | data = 'yes I can write!' | 2255 | data = 'yes I can write!' |
337 | 2251 | can_write_parent = os.access(os.path.dirname(self.share_ro_path), os.W_OK) | 2256 | can_write_parent = os.access(os.path.dirname(self.share_ro_path), |
338 | 2257 | os.W_OK) | ||
339 | 2252 | with EnableShareWrite(self.share_ro, path): | 2258 | with EnableShareWrite(self.share_ro, path): |
340 | 2253 | with open(path, 'w') as f: | 2259 | with open(path, 'w') as f: |
341 | 2254 | f.write(data) | 2260 | f.write(data) |
342 | 2255 | self.assertEquals(data, open(path, 'r').read()) | 2261 | self.assertEquals(data, open(path, 'r').read()) |
343 | 2256 | self.assertFalse(os.access(self.share_ro_path, os.W_OK)) | 2262 | self.assertFalse(os.access(self.share_ro_path, os.W_OK)) |
344 | 2257 | # check that the parent permissions are ok | 2263 | # check that the parent permissions are ok |
346 | 2258 | self.assertEquals(can_write_parent, os.access(os.path.dirname(self.share_ro_path), os.W_OK)) | 2264 | self.assertEquals(can_write_parent, |
347 | 2265 | os.access(os.path.dirname(self.share_ro_path), | ||
348 | 2266 | os.W_OK)) | ||
349 | 2259 | # fail to write directly in the share | 2267 | # fail to write directly in the share |
350 | 2260 | self.assertRaises(IOError, open, path, 'w') | 2268 | self.assertRaises(IOError, open, path, 'w') |
351 | 2261 | 2269 | ||
352 | @@ -2291,7 +2299,8 @@ | |||
353 | 2291 | os.makedirs(self.root_dir) | 2299 | os.makedirs(self.root_dir) |
354 | 2292 | self.data_dir = os.path.join(TESTS_DIR, "data") | 2300 | self.data_dir = os.path.join(TESTS_DIR, "data") |
355 | 2293 | self.partials_dir = os.path.join(TESTS_DIR, "partials") | 2301 | self.partials_dir = os.path.join(TESTS_DIR, "partials") |
357 | 2294 | self.main = FakeMain(self.root_dir, self.shares_dir, self.data_dir, self.partials_dir) | 2302 | self.main = FakeMain(self.root_dir, self.shares_dir, |
358 | 2303 | self.data_dir, self.partials_dir) | ||
359 | 2295 | self.fsm = self.main.fs | 2304 | self.fsm = self.main.fs |
360 | 2296 | self.share = self.create_share('share', 'share_name', | 2305 | self.share = self.create_share('share', 'share_name', |
361 | 2297 | self.fsm, self.shares_dir) | 2306 | self.fsm, self.shares_dir) |
362 | @@ -2300,7 +2309,7 @@ | |||
363 | 2300 | def tearDown(self): | 2309 | def tearDown(self): |
364 | 2301 | """ Clean up the tests. """ | 2310 | """ Clean up the tests. """ |
365 | 2302 | self.main.shutdown() | 2311 | self.main.shutdown() |
367 | 2303 | FSMTestCase.tearDown(self) | 2312 | self.rmtree(TESTS_DIR) |
368 | 2304 | 2313 | ||
369 | 2305 | 2314 | ||
370 | 2306 | @staticmethod | 2315 | @staticmethod |
371 | 2307 | 2316 | ||
372 | === modified file 'tests/syncdaemon/test_localrescan.py' | |||
373 | --- tests/syncdaemon/test_localrescan.py 2009-09-22 15:19:25 +0000 | |||
374 | +++ tests/syncdaemon/test_localrescan.py 2009-10-15 15:40:24 +0000 | |||
375 | @@ -46,9 +46,10 @@ | |||
376 | 46 | '''Store stuff as pushed.''' | 46 | '''Store stuff as pushed.''' |
377 | 47 | self.pushed.append((event, path)) | 47 | self.pushed.append((event, path)) |
378 | 48 | 48 | ||
380 | 49 | def freeze_begin(self, *a): | 49 | def _fake(self, *a): |
381 | 50 | '''fake''' | 50 | '''fake''' |
383 | 51 | inotify_add_watch = inotify_has_watch = freeze_rollback = is_frozen = freeze_begin | 51 | inotify_add_watch = inotify_has_watch = freeze_rollback = is_frozen = _fake |
384 | 52 | freeze_begin = add_to_mute_filter = _fake | ||
385 | 52 | 53 | ||
386 | 53 | def freeze_commit(self, events): | 54 | def freeze_commit(self, events): |
387 | 54 | '''just store events''' | 55 | '''just store events''' |
388 | @@ -88,6 +89,7 @@ | |||
389 | 88 | self.vm) | 89 | self.vm) |
390 | 89 | self.fsm.create(usrdir, "") | 90 | self.fsm.create(usrdir, "") |
391 | 90 | self.eq = FakeEQ() | 91 | self.eq = FakeEQ() |
392 | 92 | self.fsm.register_eq(self.eq) | ||
393 | 91 | self.aq = FakeAQ() | 93 | self.aq = FakeAQ() |
394 | 92 | 94 | ||
395 | 93 | def tearDown(self): | 95 | def tearDown(self): |
396 | 94 | 96 | ||
397 | === modified file 'tests/syncdaemon/test_sync.py' | |||
398 | --- tests/syncdaemon/test_sync.py 2009-09-01 20:35:36 +0000 | |||
399 | +++ tests/syncdaemon/test_sync.py 2009-10-15 15:40:24 +0000 | |||
400 | @@ -38,6 +38,7 @@ | |||
401 | 38 | from ubuntuone.syncdaemon.main import Main | 38 | from ubuntuone.syncdaemon.main import Main |
402 | 39 | from ubuntuone.syncdaemon.sync import FSKey | 39 | from ubuntuone.syncdaemon.sync import FSKey |
403 | 40 | from ubuntuone.syncdaemon.volume_manager import Share | 40 | from ubuntuone.syncdaemon.volume_manager import Share |
404 | 41 | from ubuntuone.syncdaemon.event_queue import EventQueue | ||
405 | 41 | 42 | ||
406 | 42 | DBusInterface.test = True | 43 | DBusInterface.test = True |
407 | 43 | 44 | ||
408 | @@ -57,12 +58,15 @@ | |||
409 | 57 | os.makedirs(self.partials_dir) | 58 | os.makedirs(self.partials_dir) |
410 | 58 | self.fsm = FileSystemManager(self.fsmdir, self.partials_dir, | 59 | self.fsm = FileSystemManager(self.fsmdir, self.partials_dir, |
411 | 59 | FakeVolumeManager(self.root_dir)) | 60 | FakeVolumeManager(self.root_dir)) |
412 | 61 | self.eq = EventQueue(self.fsm) | ||
413 | 62 | self.fsm.register_eq(self.eq) | ||
414 | 60 | self.share = self.create_share('share', 'share_name', | 63 | self.share = self.create_share('share', 'share_name', |
415 | 61 | self.fsm, self.shares_dir) | 64 | self.fsm, self.shares_dir) |
416 | 62 | self.share_path = self.share.path | 65 | self.share_path = self.share.path |
417 | 63 | 66 | ||
418 | 64 | def tearDown(self): | 67 | def tearDown(self): |
419 | 65 | """ Clean up the test dir""" | 68 | """ Clean up the test dir""" |
420 | 69 | self.eq.shutdown() | ||
421 | 66 | shutil.rmtree(self.test_dir) | 70 | shutil.rmtree(self.test_dir) |
422 | 67 | 71 | ||
423 | 68 | @staticmethod | 72 | @staticmethod |
424 | 69 | 73 | ||
425 | === modified file 'ubuntuone/syncdaemon/event_queue.py' | |||
426 | --- ubuntuone/syncdaemon/event_queue.py 2009-09-30 18:02:18 +0000 | |||
427 | +++ ubuntuone/syncdaemon/event_queue.py 2009-10-15 15:40:24 +0000 | |||
428 | @@ -149,6 +149,35 @@ | |||
429 | 149 | 149 | ||
430 | 150 | DEFAULT_HANDLER = "handle_default" # receives (event_name, *args, **kwargs) | 150 | DEFAULT_HANDLER = "handle_default" # receives (event_name, *args, **kwargs) |
431 | 151 | 151 | ||
432 | 152 | |||
433 | 153 | class MuteFilter(object): | ||
434 | 154 | '''Stores what needs to be muted.''' | ||
435 | 155 | def __init__(self): | ||
436 | 156 | self._cnt = {} | ||
437 | 157 | self.log = logging.getLogger('ubuntuone.SyncDaemon.MuteFilter') | ||
438 | 158 | |||
439 | 159 | def add(self, element): | ||
440 | 160 | '''Adds and element to the filter.''' | ||
441 | 161 | self.log.debug("Adding: %s", element) | ||
442 | 162 | self._cnt[element] = self._cnt.get(element, 0) + 1 | ||
443 | 163 | |||
444 | 164 | def pop(self, element): | ||
445 | 165 | '''Pops an element from the filter, if there, and returns if it was.''' | ||
446 | 166 | if element not in self._cnt: | ||
447 | 167 | return False | ||
448 | 168 | |||
449 | 169 | self._cnt[element] = self._cnt.get(element, 0) - 1 | ||
450 | 170 | if not self._cnt[element]: | ||
451 | 171 | # reached zero | ||
452 | 172 | del self._cnt[element] | ||
453 | 173 | |||
454 | 174 | # log what happened and how many items we have left | ||
455 | 175 | q = sum(self._cnt.itervalues()) | ||
456 | 176 | self.log.debug("Blocking %s (%d left)", element, q) | ||
457 | 177 | |||
458 | 178 | return True | ||
459 | 179 | |||
460 | 180 | |||
461 | 152 | class _INotifyProcessor(pyinotify.ProcessEvent): | 181 | class _INotifyProcessor(pyinotify.ProcessEvent): |
462 | 153 | '''Helper class that is called from inpotify when an event happens. | 182 | '''Helper class that is called from inpotify when an event happens. |
463 | 154 | 183 | ||
464 | @@ -162,6 +191,24 @@ | |||
465 | 162 | self.timer = None | 191 | self.timer = None |
466 | 163 | self.frozen_path = None | 192 | self.frozen_path = None |
467 | 164 | self.frozen_evts = False | 193 | self.frozen_evts = False |
468 | 194 | self._to_mute = MuteFilter() | ||
469 | 195 | |||
470 | 196 | def add_to_mute_filter(self, event, *paths): | ||
471 | 197 | '''Add an event and path(s) to the mute filter.''' | ||
472 | 198 | # all events have one path except the MOVEs | ||
473 | 199 | if event in ("FS_FILE_MOVE", "FS_DIR_MOVE"): | ||
474 | 200 | f_path, t_path = paths | ||
475 | 201 | is_from_forreal = not self.is_ignored(f_path) | ||
476 | 202 | is_to_forreal = not self.is_ignored(t_path) | ||
477 | 203 | if is_from_forreal and is_to_forreal: | ||
478 | 204 | self._to_mute.add((event, f_path, t_path)) | ||
479 | 205 | elif is_to_forreal: | ||
480 | 206 | self._to_mute.add(('FS_FILE_CREATE', t_path)) | ||
481 | 207 | self._to_mute.add(('FS_FILE_CLOSE_WRITE', t_path)) | ||
482 | 208 | else: | ||
483 | 209 | path = paths[0] | ||
484 | 210 | if not self.is_ignored(path): | ||
485 | 211 | self._to_mute.add((event, path)) | ||
486 | 165 | 212 | ||
487 | 166 | def on_timeout(self): | 213 | def on_timeout(self): |
488 | 167 | '''Called on timeout.''' | 214 | '''Called on timeout.''' |
489 | @@ -174,7 +221,7 @@ | |||
490 | 174 | try: | 221 | try: |
491 | 175 | self.timer.cancel() | 222 | self.timer.cancel() |
492 | 176 | except error.AlreadyCalled: | 223 | except error.AlreadyCalled: |
494 | 177 | # self.timeout() was *just* called, do noting here | 224 | # self.timeout() was *just* called, do nothing here |
495 | 178 | return | 225 | return |
496 | 179 | self.push_event(self.held_event) | 226 | self.push_event(self.held_event) |
497 | 180 | self.held_event = None | 227 | self.held_event = None |
498 | @@ -234,7 +281,7 @@ | |||
499 | 234 | try: | 281 | try: |
500 | 235 | self.timer.cancel() | 282 | self.timer.cancel() |
501 | 236 | except error.AlreadyCalled: | 283 | except error.AlreadyCalled: |
503 | 237 | # self.timeout() was *just* called, do noting here | 284 | # self.timeout() was *just* called, do nothing here |
504 | 238 | pass | 285 | pass |
505 | 239 | else: | 286 | else: |
506 | 240 | f_path = os.path.join(self.held_event.path, | 287 | f_path = os.path.join(self.held_event.path, |
507 | @@ -255,17 +302,17 @@ | |||
508 | 255 | evtname = "FS_FILE_" | 302 | evtname = "FS_FILE_" |
509 | 256 | if f_share_id != t_share_id: | 303 | if f_share_id != t_share_id: |
510 | 257 | # if the share_id are != push a delete/create | 304 | # if the share_id are != push a delete/create |
513 | 258 | self.eq.push(evtname+"DELETE", f_path) | 305 | self.eq_push(evtname+"DELETE", f_path) |
514 | 259 | self.eq.push(evtname+"CREATE", t_path) | 306 | self.eq_push(evtname+"CREATE", t_path) |
515 | 260 | if not this_is_a_dir: | 307 | if not this_is_a_dir: |
517 | 261 | self.eq.push('FS_FILE_CLOSE_WRITE', t_path) | 308 | self.eq_push('FS_FILE_CLOSE_WRITE', t_path) |
518 | 262 | else: | 309 | else: |
520 | 263 | self.eq.push(evtname+"MOVE", f_path, t_path) | 310 | self.eq_push(evtname+"MOVE", f_path, t_path) |
521 | 264 | elif is_to_forreal: | 311 | elif is_to_forreal: |
522 | 265 | # this is the case of a MOVE from something ignored | 312 | # this is the case of a MOVE from something ignored |
523 | 266 | # to a valid filename | 313 | # to a valid filename |
526 | 267 | self.eq.push('FS_FILE_CREATE', t_path) | 314 | self.eq_push('FS_FILE_CREATE', t_path) |
527 | 268 | self.eq.push('FS_FILE_CLOSE_WRITE', t_path) | 315 | self.eq_push('FS_FILE_CLOSE_WRITE', t_path) |
528 | 269 | 316 | ||
529 | 270 | self.held_event = None | 317 | self.held_event = None |
530 | 271 | return | 318 | return |
531 | @@ -279,7 +326,12 @@ | |||
532 | 279 | self.push_event(event) | 326 | self.push_event(event) |
533 | 280 | t_path = os.path.join(event.path, event.name) | 327 | t_path = os.path.join(event.path, event.name) |
534 | 281 | if not os.path.isdir(t_path): | 328 | if not os.path.isdir(t_path): |
536 | 282 | self.eq.push('FS_FILE_CLOSE_WRITE', t_path) | 329 | self.eq_push('FS_FILE_CLOSE_WRITE', t_path) |
537 | 330 | |||
538 | 331 | def eq_push(self, *event_data): | ||
539 | 332 | '''Sends to EQ the event data, maybe filtering it.''' | ||
540 | 333 | if not self._to_mute.pop(event_data): | ||
541 | 334 | self.eq.push(*event_data) | ||
542 | 283 | 335 | ||
543 | 284 | def process_default(self, event): | 336 | def process_default(self, event): |
544 | 285 | '''Push the event into the EventQueue.''' | 337 | '''Push the event into the EventQueue.''' |
545 | @@ -313,7 +365,7 @@ | |||
546 | 313 | if not self.is_ignored(fullpath): | 365 | if not self.is_ignored(fullpath): |
547 | 314 | if evt_name == 'FS_DIR_DELETE': | 366 | if evt_name == 'FS_DIR_DELETE': |
548 | 315 | self.handle_dir_delete(fullpath) | 367 | self.handle_dir_delete(fullpath) |
550 | 316 | self.eq.push(evt_name, fullpath) | 368 | self.eq_push(evt_name, fullpath) |
551 | 317 | 369 | ||
552 | 318 | def freeze_begin(self, path): | 370 | def freeze_begin(self, path): |
553 | 319 | """Puts in hold all the events for this path.""" | 371 | """Puts in hold all the events for this path.""" |
554 | @@ -346,7 +398,7 @@ | |||
555 | 346 | # push the received events | 398 | # push the received events |
556 | 347 | for evt_name, path in events: | 399 | for evt_name, path in events: |
557 | 348 | if not self.is_ignored(path): | 400 | if not self.is_ignored(path): |
559 | 349 | self.eq.push(evt_name, path) | 401 | self.eq_push(evt_name, path) |
560 | 350 | 402 | ||
561 | 351 | self.frozen_path = None | 403 | self.frozen_path = None |
562 | 352 | self.frozen_evts = False | 404 | self.frozen_evts = False |
563 | @@ -360,9 +412,9 @@ | |||
564 | 360 | if path == fullpath: | 412 | if path == fullpath: |
565 | 361 | continue | 413 | continue |
566 | 362 | if is_dir: | 414 | if is_dir: |
568 | 363 | self.eq.push('FS_DIR_DELETE', path) | 415 | self.eq_push('FS_DIR_DELETE', path) |
569 | 364 | else: | 416 | else: |
571 | 365 | self.eq.push('FS_FILE_DELETE', path) | 417 | self.eq_push('FS_FILE_DELETE', path) |
572 | 366 | 418 | ||
573 | 367 | 419 | ||
574 | 368 | class EventQueue(object): | 420 | class EventQueue(object): |
575 | @@ -384,6 +436,10 @@ | |||
576 | 384 | self.dispatch_queue = Queue() | 436 | self.dispatch_queue = Queue() |
577 | 385 | self.empty_event_queue_callbacks = set() | 437 | self.empty_event_queue_callbacks = set() |
578 | 386 | 438 | ||
579 | 439 | def add_to_mute_filter(self, *info): | ||
580 | 440 | '''Adds info to mute filter in the processor.''' | ||
581 | 441 | self._processor.add_to_mute_filter(*info) | ||
582 | 442 | |||
583 | 387 | def add_empty_event_queue_callback(self, callback): | 443 | def add_empty_event_queue_callback(self, callback): |
584 | 388 | """add a callback for when the even queue has no more events.""" | 444 | """add a callback for when the even queue has no more events.""" |
585 | 389 | self.empty_event_queue_callbacks.add(callback) | 445 | self.empty_event_queue_callbacks.add(callback) |
586 | 390 | 446 | ||
587 | === modified file 'ubuntuone/syncdaemon/filesystem_manager.py' | |||
588 | --- ubuntuone/syncdaemon/filesystem_manager.py 2009-10-13 16:03:54 +0000 | |||
589 | +++ ubuntuone/syncdaemon/filesystem_manager.py 2009-10-15 15:40:24 +0000 | |||
590 | @@ -221,6 +221,7 @@ | |||
591 | 221 | cache_compact_threshold=4) | 221 | cache_compact_threshold=4) |
592 | 222 | self.shares = {} | 222 | self.shares = {} |
593 | 223 | self.vm = vm | 223 | self.vm = vm |
594 | 224 | self.eq = None # this will be registered later | ||
595 | 224 | 225 | ||
596 | 225 | # create the indexes | 226 | # create the indexes |
597 | 226 | self._idx_path = {} | 227 | self._idx_path = {} |
598 | @@ -244,9 +245,14 @@ | |||
599 | 244 | logger("initialized: idx_path: %s, idx_node_id: %s, shares: %s" % | 245 | logger("initialized: idx_path: %s, idx_node_id: %s, shares: %s" % |
600 | 245 | (len(self._idx_path), len(self._idx_node_id), len(self.shares))) | 246 | (len(self._idx_path), len(self._idx_node_id), len(self.shares))) |
601 | 246 | 247 | ||
602 | 248 | def register_eq(self, eq): | ||
603 | 249 | '''Registers an EventQueue here.''' | ||
604 | 250 | self.eq = eq | ||
605 | 251 | |||
606 | 247 | def _safe_fs_iteritems(self): | 252 | def _safe_fs_iteritems(self): |
609 | 248 | """returns a 'safe' iterator over the items of the FileShelf. | 253 | """Returns a 'safe' iterator over the items of the FileShelf. |
610 | 249 | it's 'safe' because broked metadata objects are deleted and not | 254 | |
611 | 255 | It's 'safe' because broken metadata objects are deleted and not | ||
612 | 250 | returned. | 256 | returned. |
613 | 251 | """ | 257 | """ |
614 | 252 | def safeget_mdobj(mdid): | 258 | def safeget_mdobj(mdid): |
615 | @@ -566,6 +572,11 @@ | |||
616 | 566 | # pylint: disable-msg=W0704 | 572 | # pylint: disable-msg=W0704 |
617 | 567 | try: | 573 | try: |
618 | 568 | with contextlib.nested(from_context, to_context): | 574 | with contextlib.nested(from_context, to_context): |
619 | 575 | if mdobj["is_dir"]: | ||
620 | 576 | expected_event = "FS_DIR_MOVE" | ||
621 | 577 | else: | ||
622 | 578 | expected_event = "FS_FILE_MOVE" | ||
623 | 579 | self.eq.add_to_mute_filter(expected_event, path_from, path_to) | ||
624 | 569 | shutil.move(path_from, path_to) | 580 | shutil.move(path_from, path_to) |
625 | 570 | except IOError, e: | 581 | except IOError, e: |
626 | 571 | # file was not yet created | 582 | # file was not yet created |
627 | @@ -652,8 +663,10 @@ | |||
628 | 652 | try: | 663 | try: |
629 | 653 | with self._enable_share_write(mdobj['share_id'], path): | 664 | with self._enable_share_write(mdobj['share_id'], path): |
630 | 654 | if self.is_dir(path=path): | 665 | if self.is_dir(path=path): |
631 | 666 | self.eq.add_to_mute_filter("FS_DIR_DELETE", path) | ||
632 | 655 | os.rmdir(path) | 667 | os.rmdir(path) |
633 | 656 | else: | 668 | else: |
634 | 669 | self.eq.add_to_mute_filter("FS_FILE_DELETE", path) | ||
635 | 657 | os.remove(path) | 670 | os.remove(path) |
636 | 658 | except OSError, e: | 671 | except OSError, e: |
637 | 659 | if e.errno == errno.ENOTEMPTY: | 672 | if e.errno == errno.ENOTEMPTY: |
638 | @@ -674,6 +687,11 @@ | |||
639 | 674 | to_path = base_to_path + "." + str(ind) | 687 | to_path = base_to_path + "." + str(ind) |
640 | 675 | with self._enable_share_write(mdobj['share_id'], path): | 688 | with self._enable_share_write(mdobj['share_id'], path): |
641 | 676 | try: | 689 | try: |
642 | 690 | if mdobj["is_dir"]: | ||
643 | 691 | expected_event = "FS_DIR_MOVE" | ||
644 | 692 | else: | ||
645 | 693 | expected_event = "FS_FILE_MOVE" | ||
646 | 694 | self.eq.add_to_mute_filter(expected_event, path, to_path) | ||
647 | 677 | os.rename(path, to_path) | 695 | os.rename(path, to_path) |
648 | 678 | except OSError, e: | 696 | except OSError, e: |
649 | 679 | if e.errno == errno.ENOENT: | 697 | if e.errno == errno.ENOENT: |
650 | @@ -739,7 +757,10 @@ | |||
651 | 739 | with self._enable_share_write(share_id, os.path.dirname(path)): | 757 | with self._enable_share_write(share_id, os.path.dirname(path)): |
652 | 740 | # if we don't have the dir yet, create it | 758 | # if we don't have the dir yet, create it |
653 | 741 | if is_dir and not os.path.exists(path): | 759 | if is_dir and not os.path.exists(path): |
654 | 760 | self.eq.add_to_mute_filter("FS_DIR_CREATE", path) | ||
655 | 742 | os.mkdir(path) | 761 | os.mkdir(path) |
656 | 762 | |||
657 | 763 | # don't alert EQ, partials are in other directory, not watched | ||
658 | 743 | open(partial_path, "w").close() | 764 | open(partial_path, "w").close() |
659 | 744 | mdobj["info"]["last_partial_created"] = time.time() | 765 | mdobj["info"]["last_partial_created"] = time.time() |
660 | 745 | mdobj["info"]["is_partial"] = True | 766 | mdobj["info"]["is_partial"] = True |
661 | @@ -786,6 +807,8 @@ | |||
662 | 786 | 807 | ||
663 | 787 | partial_path = self._get_partial_path(mdobj) | 808 | partial_path = self._get_partial_path(mdobj) |
664 | 788 | with self._enable_share_write(share_id, path): | 809 | with self._enable_share_write(share_id, path): |
665 | 810 | self.eq.add_to_mute_filter("FS_FILE_CREATE", path) | ||
666 | 811 | self.eq.add_to_mute_filter("FS_FILE_CLOSE_WRITE", path) | ||
667 | 789 | shutil.move(partial_path, path) | 812 | shutil.move(partial_path, path) |
668 | 790 | mdobj["local_hash"] = local_hash | 813 | mdobj["local_hash"] = local_hash |
669 | 791 | mdobj["info"]["last_downloaded"] = time.time() | 814 | mdobj["info"]["last_downloaded"] = time.time() |
670 | @@ -805,6 +828,7 @@ | |||
671 | 805 | partial_path = self._get_partial_path(mdobj) | 828 | partial_path = self._get_partial_path(mdobj) |
672 | 806 | #pylint: disable-msg=W0704 | 829 | #pylint: disable-msg=W0704 |
673 | 807 | try: | 830 | try: |
674 | 831 | # don't alert EQ, partials are in other directory, not watched | ||
675 | 808 | os.remove(partial_path) | 832 | os.remove(partial_path) |
676 | 809 | except OSError, e: | 833 | except OSError, e: |
677 | 810 | # we only remove it if its there. | 834 | # we only remove it if its there. |
678 | 811 | 835 | ||
679 | === modified file 'ubuntuone/syncdaemon/main.py' | |||
680 | --- ubuntuone/syncdaemon/main.py 2009-10-09 08:19:05 +0000 | |||
681 | +++ ubuntuone/syncdaemon/main.py 2009-10-15 15:40:24 +0000 | |||
682 | @@ -109,6 +109,7 @@ | |||
683 | 109 | self.partials_dir, | 109 | self.partials_dir, |
684 | 110 | self.vm) | 110 | self.vm) |
685 | 111 | self.event_q = event_queue.EventQueue(self.fs) | 111 | self.event_q = event_queue.EventQueue(self.fs) |
686 | 112 | self.fs.register_eq(self.event_q) | ||
687 | 112 | self.oauth_client = OAuthClient(self.realm) | 113 | self.oauth_client = OAuthClient(self.realm) |
688 | 113 | self.state = SyncDaemonStateManager(self, handshake_timeout, | 114 | self.state = SyncDaemonStateManager(self, handshake_timeout, |
689 | 114 | max_handshake_timeouts) | 115 | max_handshake_timeouts) |
Now we avoid the filesystem event bouncing.
Before, when SD removed a file (for example), the event FS_FILE_DELETED arrived from the filesystem. As the event from filesystem is related to a "path", it may happen that if a new file is created with that path *before* the event from filesystem arrives, the event will impact the new node, incorrectly.
So, we need to avoid these bouncing events. For this I put a MuteFilter en EQ to whom the expected events are added, and it filters them. As the one that touches disk is FSM, this is pretty clean.
Regarding tests, I added some to test MuteFilter itself, and also to test EQ filtering the events. But as FSM now has a reference to EQ, I had to change some other tests because of this.