Merge lp:~nataliabidart/ubuntuone-client/no-more-oses into lp:ubuntuone-client
- no-more-oses
- Merge into trunk
Proposed by
Natalia Bidart
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 1099 |
Merged at revision: | 1097 |
Proposed branch: | lp:~nataliabidart/ubuntuone-client/no-more-oses |
Merge into: | lp:ubuntuone-client |
Prerequisite: | lp:~nataliabidart/ubuntuone-client/unify-os-helper-tests |
Diff against target: |
2026 lines (+321/-273) 18 files modified
tests/platform/test_filesystem_notifications.py (+9/-8) tests/platform/test_os_helper.py (+8/-8) tests/syncdaemon/test_action_queue.py (+4/-4) tests/syncdaemon/test_config.py (+10/-9) tests/syncdaemon/test_eq_inotify.py (+96/-85) tests/syncdaemon/test_fsm.py (+93/-83) tests/syncdaemon/test_localrescan.py (+8/-8) tests/syncdaemon/test_main.py (+27/-22) tests/syncdaemon/test_sync.py (+4/-3) tests/syncdaemon/test_vm.py (+14/-9) ubuntuone/platform/linux/filesystem_notifications.py (+4/-3) ubuntuone/platform/windows/filesystem_notifications.py (+4/-2) ubuntuone/syncdaemon/file_shelf.py (+12/-3) ubuntuone/syncdaemon/filesystem_manager.py (+1/-1) ubuntuone/syncdaemon/filesystem_notifications.py (+2/-1) ubuntuone/syncdaemon/local_rescan.py (+1/-1) ubuntuone/syncdaemon/vm_helper.py (+2/-1) ubuntuone/syncdaemon/volume_manager.py (+22/-22) |
To merge this branch: | bzr merge lp:~nataliabidart/ubuntuone-client/no-more-oses |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alejandro J. Cura (community) | Approve | ||
Review via email: mp+70890@code.launchpad.net |
Commit message
- Removed most of the calls to: os.rename, os.chmod, os.path.exists, os.remove and os.rmdir (LP: #823261).
Description of the change
To post a comment you must log in.
- 1099. By Natalia Bidart
-
Changes from dependency branch.
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-06-24 19:48:00 +0000 |
3 | +++ tests/platform/test_filesystem_notifications.py 2011-08-09 16:37:30 +0000 |
4 | @@ -23,12 +23,13 @@ |
5 | import unittest |
6 | |
7 | from twisted.internet import defer, reactor |
8 | +from ubuntuone.devtools.handlers import MementoHandler |
9 | +from ubuntuone.devtools.testcase import skipIfOS |
10 | |
11 | from tests.platform import _GeneralINotifyProcessor |
12 | from contrib.testing import testcase |
13 | +from ubuntuone.platform import remove_file, remove_dir, rename |
14 | from ubuntuone.syncdaemon.tritcask import Tritcask |
15 | -from ubuntuone.devtools.handlers import MementoHandler |
16 | -from ubuntuone.devtools.testcase import skipIfOS |
17 | from ubuntuone.syncdaemon import ( |
18 | event_queue, |
19 | filesystem_manager, |
20 | @@ -315,7 +316,7 @@ |
21 | yield self.monitor.add_watch(self.root_dir) |
22 | |
23 | # generate the event |
24 | - os.remove(testfile) |
25 | + remove_file(testfile) |
26 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
27 | test_result = yield self._deferred |
28 | defer.returnValue(test_result) |
29 | @@ -330,7 +331,7 @@ |
30 | yield self.monitor.add_watch(self.root_dir) |
31 | |
32 | # generate the event |
33 | - os.rmdir(testdir) |
34 | + remove_dir(testdir) |
35 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
36 | test_result = yield self._deferred |
37 | defer.returnValue(test_result) |
38 | @@ -351,7 +352,7 @@ |
39 | yield self.monitor.add_watch(self.root_dir) |
40 | |
41 | # generate the event |
42 | - os.rename(fromfile, tofile) |
43 | + rename(fromfile, tofile) |
44 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
45 | test_result = yield self._deferred |
46 | defer.returnValue(test_result) |
47 | @@ -372,7 +373,7 @@ |
48 | yield self.monitor.add_watch(self.root_dir) |
49 | |
50 | # generate the event |
51 | - os.rename(fromdir, todir) |
52 | + rename(fromdir, todir) |
53 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
54 | test_result = yield self._deferred |
55 | defer.returnValue(test_result) |
56 | @@ -393,7 +394,7 @@ |
57 | yield self.monitor.add_watch(self.root_dir) |
58 | |
59 | # generate the event |
60 | - os.rename(fromfile, tofile) |
61 | + rename(fromfile, tofile) |
62 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
63 | test_result = yield self._deferred |
64 | defer.returnValue(test_result) |
65 | @@ -412,7 +413,7 @@ |
66 | yield self.monitor.add_watch(root_dir) |
67 | |
68 | # generate the event |
69 | - os.rename(fromfile, tofile) |
70 | + rename(fromfile, tofile) |
71 | reactor.callLater(self.timeout - 0.2, self.check_filter) |
72 | test_result = yield self._deferred |
73 | defer.returnValue(test_result) |
74 | |
75 | === modified file 'tests/platform/test_os_helper.py' |
76 | --- tests/platform/test_os_helper.py 2011-08-09 16:37:30 +0000 |
77 | +++ tests/platform/test_os_helper.py 2011-08-09 16:37:30 +0000 |
78 | @@ -84,7 +84,7 @@ |
79 | set_dir_readwrite(self.basedir) |
80 | foo_dir = os.path.join(self.basedir, 'foo') |
81 | os.mkdir(foo_dir) |
82 | - self.assertTrue(os.path.exists(foo_dir)) |
83 | + self.assertTrue(path_exists(foo_dir)) |
84 | |
85 | def test_allow_writes(self): |
86 | """Test for allow_writes.""" |
87 | @@ -92,7 +92,7 @@ |
88 | with allow_writes(self.basedir): |
89 | foo_dir = os.path.join(self.basedir, 'foo') |
90 | os.mkdir(foo_dir) |
91 | - self.assertTrue(os.path.exists(foo_dir)) |
92 | + self.assertTrue(path_exists(foo_dir)) |
93 | |
94 | def test_set_file_readonly(self): |
95 | """Test for set_file_readonly.""" |
96 | @@ -135,16 +135,16 @@ |
97 | """Test the remove dir.""" |
98 | testdir = os.path.join(self.basedir, 'foodir') |
99 | os.mkdir(testdir) |
100 | - assert os.path.exists(testdir) |
101 | + assert path_exists(testdir) |
102 | remove_dir(testdir) |
103 | self.assertFalse(path_exists(testdir)) |
104 | |
105 | def test_make_dir_one(self): |
106 | """Test the make dir with one dir.""" |
107 | testdir = os.path.join(self.basedir, 'foodir') |
108 | - assert not os.path.exists(testdir) |
109 | + assert not path_exists(testdir) |
110 | make_dir(testdir) |
111 | - self.assertTrue(os.path.exists(testdir)) |
112 | + self.assertTrue(path_exists(testdir)) |
113 | |
114 | def test_make_dir_already_there(self): |
115 | """Test the make dir with one dir that exists.""" |
116 | @@ -153,15 +153,15 @@ |
117 | def test_make_dir_recursive_no(self): |
118 | """Test the make dir with some dirs, not recursive explicit.""" |
119 | testdir = os.path.join(self.basedir, 'foo', 'bar') |
120 | - assert not os.path.exists(testdir) |
121 | + assert not path_exists(testdir) |
122 | self.assertRaises(OSError, make_dir, testdir) |
123 | |
124 | def test_make_dir_recursive_yes(self): |
125 | """Test the make dir with some dirs, recursive.""" |
126 | testdir = os.path.join(self.basedir, 'foo', 'bar') |
127 | - assert not os.path.exists(testdir) |
128 | + assert not path_exists(testdir) |
129 | make_dir(testdir, recursive=True) |
130 | - self.assertTrue(os.path.exists(testdir)) |
131 | + self.assertTrue(path_exists(testdir)) |
132 | |
133 | def test_open_file_not_there(self): |
134 | """Open a file that does not exist.""" |
135 | |
136 | === modified file 'tests/syncdaemon/test_action_queue.py' |
137 | --- tests/syncdaemon/test_action_queue.py 2011-08-08 19:54:46 +0000 |
138 | +++ tests/syncdaemon/test_action_queue.py 2011-08-09 16:37:30 +0000 |
139 | @@ -31,9 +31,9 @@ |
140 | import uuid |
141 | |
142 | from functools import wraps |
143 | +from StringIO import StringIO |
144 | |
145 | from mocker import Mocker, MockerTestCase, ANY, expect |
146 | -from StringIO import StringIO |
147 | from oauth import oauth |
148 | from twisted.internet import defer, threads, reactor |
149 | from twisted.internet import error as twisted_error |
150 | @@ -47,7 +47,7 @@ |
151 | ) |
152 | from ubuntuone.devtools import handlers |
153 | from ubuntuone import logger, clientdefs |
154 | -from ubuntuone.platform import platform |
155 | +from ubuntuone.platform import platform, path_exists |
156 | from ubuntuone.storageprotocol import ( |
157 | client, |
158 | content_hash, |
159 | @@ -3316,12 +3316,12 @@ |
160 | self.command.tempfile = TempFile() |
161 | self.command.tempfile.name = os.path.join(self.tmpdir, 'remove-me.zip') |
162 | open(self.command.tempfile.name, 'w').close() |
163 | - assert os.path.exists(self.command.tempfile.name) |
164 | + assert path_exists(self.command.tempfile.name) |
165 | |
166 | msg = 'Something went wrong' |
167 | failure = Failure(DefaultException(msg)) |
168 | self.command.handle_failure(failure=failure) |
169 | - self.assertFalse(os.path.exists(self.command.tempfile.name)) |
170 | + self.assertFalse(path_exists(self.command.tempfile.name)) |
171 | |
172 | def test_retryable_failure_push_quota_exceeded_if_that_error(self): |
173 | """Test SYS_QUOTA_EXCEEDED is pushed on QuotaExceededError.""" |
174 | |
175 | === modified file 'tests/syncdaemon/test_config.py' |
176 | --- tests/syncdaemon/test_config.py 2011-07-29 12:51:04 +0000 |
177 | +++ tests/syncdaemon/test_config.py 2011-08-09 16:37:30 +0000 |
178 | @@ -23,6 +23,7 @@ |
179 | from ConfigParser import ConfigParser |
180 | from twisted.internet import defer |
181 | |
182 | +from ubuntuone.platform import path_exists |
183 | from ubuntuone.platform.xdg_base_directory import ( |
184 | xdg_data_home, |
185 | xdg_cache_home, |
186 | @@ -103,7 +104,7 @@ |
187 | def test_write_new(self): |
188 | """test writing the throttling section to a new config file""" |
189 | conf_file = os.path.join(self.test_root, 'test_write_new_config.conf') |
190 | - self.assertFalse(os.path.exists(conf_file)) |
191 | + self.assertFalse(path_exists(conf_file)) |
192 | conf = config._Config(conf_file) |
193 | conf.set_throttling(True) |
194 | conf.set_throttling_read_limit(1000) |
195 | @@ -124,7 +125,7 @@ |
196 | fp.write('on = False\n') |
197 | fp.write('read_limit = 1000\n') |
198 | fp.write('write_limit = 100\n') |
199 | - self.assertTrue(os.path.exists(conf_file)) |
200 | + self.assertTrue(path_exists(conf_file)) |
201 | conf = config._Config(conf_file) |
202 | conf.set_throttling(True) |
203 | conf.set_throttling_read_limit(2000) |
204 | @@ -150,7 +151,7 @@ |
205 | fp.write('on = False\n') |
206 | fp.write('read_limit = 2000\n') |
207 | fp.write('write_limit = 200\n') |
208 | - self.assertTrue(os.path.exists(conf_file)) |
209 | + self.assertTrue(path_exists(conf_file)) |
210 | conf = config._Config(conf_file) |
211 | conf.set_throttling(True) |
212 | conf.set_throttling_read_limit(3000) |
213 | @@ -177,7 +178,7 @@ |
214 | fp.write('on = True\n') |
215 | fp.write('read_limit = 1000\n') |
216 | fp.write('write_limit = 100\n') |
217 | - self.assertTrue(os.path.exists(conf_file)) |
218 | + self.assertTrue(path_exists(conf_file)) |
219 | conf = config._Config(conf_file) |
220 | conf.set_throttling(False) |
221 | conf.save() |
222 | @@ -570,7 +571,7 @@ |
223 | with open(conf_file, 'w') as fp: |
224 | fp.write('[__main__]\n') |
225 | fp.write('log_level = DEBUG\n') |
226 | - self.assertTrue(os.path.exists(conf_file)) |
227 | + self.assertTrue(path_exists(conf_file)) |
228 | self.cp.read([conf_file]) |
229 | self.cp.parse_all() |
230 | self.assertEquals(self.cp.get('logging', 'level').value, 10) |
231 | @@ -582,7 +583,7 @@ |
232 | with open(conf_file, 'w') as fp: |
233 | fp.write('[logging]\n') |
234 | fp.write('level = DEBUG\n') |
235 | - self.assertTrue(os.path.exists(conf_file)) |
236 | + self.assertTrue(path_exists(conf_file)) |
237 | self.cp.read([conf_file]) |
238 | self.cp.parse_all() |
239 | self.assertEquals(self.cp.get('logging', 'level').value, 10) |
240 | @@ -597,7 +598,7 @@ |
241 | fp.write('log_level = NOTE\n') |
242 | fp.write('[logging]\n') |
243 | fp.write('level = ERROR\n') |
244 | - self.assertTrue(os.path.exists(conf_file)) |
245 | + self.assertTrue(path_exists(conf_file)) |
246 | self.cp.read([conf_file]) |
247 | self.cp.parse_all() |
248 | self.assertEquals(self.cp.get('logging', 'level').value, logging.ERROR) |
249 | @@ -634,7 +635,7 @@ |
250 | with open(conf_file, 'w') as fp: |
251 | fp.write('[__main__]\n') |
252 | fp.write('ignore = .*\\.pyc\n') # all .pyc files |
253 | - self.assertTrue(os.path.exists(conf_file)) |
254 | + self.assertTrue(path_exists(conf_file)) |
255 | self.cp.read([conf_file]) |
256 | self.cp.parse_all() |
257 | self.assertEquals(self.cp.get('__main__', 'ignore').value, |
258 | @@ -647,7 +648,7 @@ |
259 | fp.write('[__main__]\n') |
260 | fp.write('ignore = .*\\.pyc\n') # all .pyc files |
261 | fp.write(' .*\\.sw[opnx]\n') # all gvim temp files |
262 | - self.assertTrue(os.path.exists(conf_file)) |
263 | + self.assertTrue(path_exists(conf_file)) |
264 | self.cp.read([conf_file]) |
265 | self.cp.parse_all() |
266 | self.assertEquals(self.cp.get('__main__', 'ignore').value, |
267 | |
268 | === modified file 'tests/syncdaemon/test_eq_inotify.py' |
269 | --- tests/syncdaemon/test_eq_inotify.py 2011-08-04 16:30:54 +0000 |
270 | +++ tests/syncdaemon/test_eq_inotify.py 2011-08-09 16:37:30 +0000 |
271 | @@ -28,7 +28,18 @@ |
272 | |
273 | from contrib.testing.testcase import BaseTwistedTestCase, FakeMain, Listener |
274 | from tests.syncdaemon.test_eventqueue import BaseEQTestCase |
275 | -from ubuntuone.platform import make_dir, make_link, open_file, path_exists |
276 | +from ubuntuone.platform import ( |
277 | + make_link, |
278 | + make_dir, |
279 | + open_file, |
280 | + path_exists, |
281 | + remove_file, |
282 | + remove_dir, |
283 | + rename, |
284 | + set_no_rights, |
285 | + set_file_readwrite, |
286 | + set_dir_readwrite, |
287 | +) |
288 | from ubuntuone.syncdaemon import volume_manager |
289 | |
290 | # our logging level |
291 | @@ -348,7 +359,7 @@ |
292 | self.finished_error("received a wrong path") |
293 | else: |
294 | if innerself.hist == ["create"]: |
295 | - os.remove(testfile) |
296 | + remove_file(testfile) |
297 | self.finished_ok() |
298 | else: |
299 | msg = "Finished in bad condition: %s" % innerself.hist |
300 | @@ -448,7 +459,7 @@ |
301 | self.eq.subscribe(DontHitMe(self)) |
302 | |
303 | # generate the event |
304 | - os.remove(testfile) |
305 | + remove_file(testfile) |
306 | reactor.callLater(.1, self._deferred.callback, True) |
307 | yield self._deferred |
308 | |
309 | @@ -463,7 +474,7 @@ |
310 | self.eq.subscribe(DontHitMe(self)) |
311 | |
312 | # generate the event |
313 | - os.rmdir(testdir) |
314 | + remove_dir(testdir) |
315 | reactor.callLater(.1, self._deferred.callback, True) |
316 | yield self._deferred |
317 | |
318 | @@ -484,7 +495,7 @@ |
319 | self.eq.subscribe(DontHitMe(self)) |
320 | |
321 | # generate the event |
322 | - os.rename(fromfile, tofile) |
323 | + rename(fromfile, tofile) |
324 | reactor.callLater(.1, self._deferred.callback, True) |
325 | yield self._deferred |
326 | |
327 | @@ -505,7 +516,7 @@ |
328 | self.eq.subscribe(DontHitMe(self)) |
329 | |
330 | # generate the event |
331 | - os.rename(fromdir, todir) |
332 | + rename(fromdir, todir) |
333 | reactor.callLater(.1, self._deferred.callback, True) |
334 | yield self._deferred |
335 | |
336 | @@ -525,7 +536,7 @@ |
337 | self.eq.subscribe(DontHitMe(self)) |
338 | |
339 | # generate the event |
340 | - os.rename(fromfile, tofile) |
341 | + rename(fromfile, tofile) |
342 | reactor.callLater(.1, self._deferred.callback, True) |
343 | yield self._deferred |
344 | |
345 | @@ -544,7 +555,7 @@ |
346 | self.eq.subscribe(DontHitMe(self)) |
347 | |
348 | # generate the event |
349 | - os.rename(fromfile, tofile) |
350 | + rename(fromfile, tofile) |
351 | reactor.callLater(.1, self._deferred.callback, True) |
352 | yield self._deferred |
353 | |
354 | @@ -652,13 +663,13 @@ |
355 | f.read() |
356 | f.close() |
357 | # generate FS_FILE_DELETE |
358 | - os.remove(fname) |
359 | + remove_file(fname) |
360 | |
361 | fnamedir = os.path.join(path, 'testit.dir') |
362 | # generate FS_DIR_CREATE |
363 | os.mkdir(fnamedir) |
364 | # generate FS_DIR_DELETE |
365 | - os.rmdir(fnamedir) |
366 | + remove_dir(fnamedir) |
367 | |
368 | def check(): |
369 | """Check.""" |
370 | @@ -682,13 +693,13 @@ |
371 | f.read() |
372 | f.close() |
373 | # generate FS_FILE_DELETE |
374 | - os.remove(fname) |
375 | + remove_file(fname) |
376 | |
377 | fnamedir = os.path.join(path, 'testit.dir') |
378 | # generate FS_DIR_CREATE |
379 | os.mkdir(fnamedir) |
380 | # generate FS_DIR_DELETE |
381 | - os.rmdir(fnamedir) |
382 | + remove_dir(fnamedir) |
383 | |
384 | expected = [('FS_FILE_CREATE', {'path': fname}), |
385 | ('FS_FILE_OPEN', {'path': fname}), |
386 | @@ -739,7 +750,7 @@ |
387 | path = self.udf.ancestors[-2] # an ancestor common to both UDFs |
388 | # generate IN_MOVED_FROM and IN_MOVED_TO |
389 | newpath = path + u'.old' |
390 | - os.rename(path, newpath) |
391 | + rename(path, newpath) |
392 | assert path_exists(newpath) |
393 | |
394 | unsubscribed = [] |
395 | @@ -774,7 +785,7 @@ |
396 | """UDF is unsubscribed if renamed.""" |
397 | original = self.eq.fs.vm.unsubscribe_udf |
398 | newpath = self.udf.path + u'.old' |
399 | - os.rename(self.udf.path, newpath) |
400 | + rename(self.udf.path, newpath) |
401 | assert path_exists(newpath) |
402 | |
403 | unsubscribed = [] |
404 | @@ -816,7 +827,7 @@ |
405 | |
406 | uid = self.udf.volume_id |
407 | fnamedir = self.udf.path |
408 | - os.rmdir(fnamedir) |
409 | + remove_dir(fnamedir) |
410 | |
411 | def check(): |
412 | """Check.""" |
413 | @@ -844,7 +855,7 @@ |
414 | self.listener.events = [] |
415 | |
416 | fnamedir = self.udf.path |
417 | - os.rmdir(fnamedir) |
418 | + remove_dir(fnamedir) |
419 | |
420 | def check(): |
421 | """Check.""" |
422 | @@ -878,7 +889,7 @@ |
423 | "Removed watches don't match the expected") |
424 | self._deferred.callback(True) |
425 | |
426 | - os.rmdir(self.udf.path) |
427 | + remove_dir(self.udf.path) |
428 | reactor.callLater(.1, check) |
429 | return self._deferred |
430 | |
431 | @@ -906,7 +917,7 @@ |
432 | "Removed watches don't match the expected") |
433 | self._deferred.callback(True) |
434 | |
435 | - os.rename(self.udf.path, self.udf.path + ".old") |
436 | + rename(self.udf.path, self.udf.path + ".old") |
437 | reactor.callLater(.1, check) |
438 | return self._deferred |
439 | |
440 | @@ -936,8 +947,8 @@ |
441 | |
442 | path = self.udf.ancestors[-2] # an ancestor common to both UDFs |
443 | |
444 | - os.rename(self.udf.path, self.udf.path + ".old") |
445 | - os.rename(path, path + ".old") |
446 | + rename(self.udf.path, self.udf.path + ".old") |
447 | + rename(path, path + ".old") |
448 | reactor.callLater(.1, check) |
449 | return self._deferred |
450 | |
451 | @@ -957,7 +968,7 @@ |
452 | def test_file_open(self): |
453 | """Test invalid_filename after open a file.""" |
454 | open_file(self.invalid_path, "w").close() |
455 | - self.addCleanup(os.remove, self.invalid_path) |
456 | + self.addCleanup(remove_file, self.invalid_path) |
457 | |
458 | yield self.eq.add_watch(self.root_dir) |
459 | should_events = [ |
460 | @@ -976,7 +987,7 @@ |
461 | def test_file_close_nowrite(self): |
462 | """Test invalid_filename after a close no write.""" |
463 | open_file(self.invalid_path, "w").close() |
464 | - self.addCleanup(os.remove, self.invalid_path) |
465 | + self.addCleanup(remove_file, self.invalid_path) |
466 | fh = open_file(self.invalid_path) |
467 | |
468 | yield self.eq.add_watch(self.root_dir) |
469 | @@ -1006,7 +1017,7 @@ |
470 | |
471 | # generate the event |
472 | open_file(self.invalid_path, "w").close() |
473 | - self.addCleanup(os.remove, self.invalid_path) |
474 | + self.addCleanup(remove_file, self.invalid_path) |
475 | yield self._deferred |
476 | |
477 | @defer.inlineCallbacks |
478 | @@ -1021,7 +1032,7 @@ |
479 | |
480 | # generate the event |
481 | os.mkdir(self.invalid_path) |
482 | - self.addCleanup(os.rmdir, self.invalid_path) |
483 | + self.addCleanup(remove_dir, self.invalid_path) |
484 | yield self._deferred |
485 | |
486 | @defer.inlineCallbacks |
487 | @@ -1037,7 +1048,7 @@ |
488 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
489 | |
490 | # generate the event |
491 | - os.remove(self.invalid_path) |
492 | + remove_file(self.invalid_path) |
493 | yield self._deferred |
494 | |
495 | @defer.inlineCallbacks |
496 | @@ -1053,7 +1064,7 @@ |
497 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
498 | |
499 | # generate the event |
500 | - os.rmdir(self.invalid_path) |
501 | + remove_dir(self.invalid_path) |
502 | yield self._deferred |
503 | |
504 | @defer.inlineCallbacks |
505 | @@ -1072,8 +1083,8 @@ |
506 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
507 | |
508 | # generate the event |
509 | - os.rename(self.invalid_path, destfile) |
510 | - self.addCleanup(os.remove, destfile) |
511 | + rename(self.invalid_path, destfile) |
512 | + self.addCleanup(remove_file, destfile) |
513 | yield self._deferred |
514 | |
515 | @defer.inlineCallbacks |
516 | @@ -1093,8 +1104,8 @@ |
517 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
518 | |
519 | # generate the event |
520 | - os.rename(fromfile, destfile) |
521 | - self.addCleanup(os.remove, destfile) |
522 | + rename(fromfile, destfile) |
523 | + self.addCleanup(remove_file, destfile) |
524 | yield self._deferred |
525 | |
526 | |
527 | @@ -1113,7 +1124,7 @@ |
528 | if path != testfile: |
529 | self.finished_error("received a wrong path") |
530 | else: |
531 | - os.remove(testfile) |
532 | + remove_file(testfile) |
533 | self.finished_ok() |
534 | |
535 | yield self.eq.add_watch(self.root_dir) |
536 | @@ -1137,7 +1148,7 @@ |
537 | if path != testfile: |
538 | self.finished_error("received a wrong path") |
539 | else: |
540 | - os.remove(testfile) |
541 | + remove_file(testfile) |
542 | self.finished_ok() |
543 | |
544 | yield self.eq.add_watch(self.root_dir) |
545 | @@ -1169,7 +1180,7 @@ |
546 | self.finished_error("received a wrong path") |
547 | else: |
548 | if innerself.hist == ["create"]: |
549 | - os.remove(testfile) |
550 | + remove_file(testfile) |
551 | self.finished_ok() |
552 | else: |
553 | msg = "Finished in bad condition: %s" % innerself.hist |
554 | @@ -1194,7 +1205,7 @@ |
555 | if path != testdir: |
556 | self.finished_error("received a wrong path") |
557 | else: |
558 | - os.rmdir(testdir) |
559 | + remove_dir(testdir) |
560 | self.finished_ok() |
561 | |
562 | yield self.eq.add_watch(self.root_dir) |
563 | @@ -1228,7 +1239,7 @@ |
564 | self.eq.subscribe(HitMe()) |
565 | |
566 | # generate the event |
567 | - os.remove(testfile) |
568 | + remove_file(testfile) |
569 | yield self._deferred |
570 | |
571 | @defer.inlineCallbacks |
572 | @@ -1258,7 +1269,7 @@ |
573 | self.eq.subscribe(HitMe()) |
574 | |
575 | # generate the event |
576 | - os.rmdir(testdir) |
577 | + remove_dir(testdir) |
578 | yield self._deferred |
579 | |
580 | @defer.inlineCallbacks |
581 | @@ -1298,15 +1309,15 @@ |
582 | if path != fromfile: |
583 | self.finished_error("received a wrong path") |
584 | else: |
585 | - os.remove(tofile) |
586 | - os.rmdir(helpdir) |
587 | + remove_file(tofile) |
588 | + remove_dir(helpdir) |
589 | self.finished_ok() |
590 | |
591 | yield self.eq.add_watch(self.root_dir) |
592 | self.eq.subscribe(HitMe()) |
593 | |
594 | # generate the event |
595 | - os.rename(fromfile, tofile) |
596 | + rename(fromfile, tofile) |
597 | yield self._deferred |
598 | |
599 | @defer.inlineCallbacks |
600 | @@ -1325,15 +1336,15 @@ |
601 | if path != fromdir: |
602 | self.finished_error("received a wrong path") |
603 | else: |
604 | - os.rmdir(todir) |
605 | - os.rmdir(helpdir) |
606 | + remove_dir(todir) |
607 | + remove_dir(helpdir) |
608 | self.finished_ok() |
609 | |
610 | yield self.eq.add_watch(self.root_dir) |
611 | self.eq.subscribe(HitMe()) |
612 | |
613 | # generate the event |
614 | - os.rename(fromdir, todir) |
615 | + rename(fromdir, todir) |
616 | yield self._deferred |
617 | |
618 | @defer.inlineCallbacks |
619 | @@ -1352,15 +1363,15 @@ |
620 | if path != tofile: |
621 | self.finished_error("received a wrong path") |
622 | else: |
623 | - os.remove(tofile) |
624 | - os.rmdir(helpdir) |
625 | + remove_file(tofile) |
626 | + remove_dir(helpdir) |
627 | self.finished_ok() |
628 | |
629 | yield self.eq.add_watch(self.root_dir) |
630 | self.eq.subscribe(HitMe()) |
631 | |
632 | # generate the event |
633 | - os.rename(fromfile, tofile) |
634 | + rename(fromfile, tofile) |
635 | yield self._deferred |
636 | |
637 | @defer.inlineCallbacks |
638 | @@ -1379,15 +1390,15 @@ |
639 | if path != todir: |
640 | self.finished_error("received a wrong path") |
641 | else: |
642 | - os.rmdir(todir) |
643 | - os.rmdir(helpdir) |
644 | + remove_dir(todir) |
645 | + remove_dir(helpdir) |
646 | self.finished_ok() |
647 | |
648 | yield self.eq.add_watch(self.root_dir) |
649 | self.eq.subscribe(HitMe()) |
650 | |
651 | # generate the event |
652 | - os.rename(fromdir, todir) |
653 | + rename(fromdir, todir) |
654 | yield self._deferred |
655 | |
656 | @defer.inlineCallbacks |
657 | @@ -1407,7 +1418,7 @@ |
658 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
659 | |
660 | # generate the event |
661 | - os.rename(fromdir, todir) |
662 | + rename(fromdir, todir) |
663 | yield self._deferred |
664 | |
665 | @defer.inlineCallbacks |
666 | @@ -1427,7 +1438,7 @@ |
667 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
668 | |
669 | # generate the event |
670 | - os.rename(fromdir, todir) |
671 | + rename(fromdir, todir) |
672 | yield self._deferred |
673 | |
674 | @defer.inlineCallbacks |
675 | @@ -1449,7 +1460,7 @@ |
676 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
677 | |
678 | # generate the event |
679 | - os.rename(fromfile, tofile) |
680 | + rename(fromfile, tofile) |
681 | yield self._deferred |
682 | |
683 | @defer.inlineCallbacks |
684 | @@ -1469,7 +1480,7 @@ |
685 | self.eq.subscribe(DynamicHitMe(should_events, self)) |
686 | |
687 | # generate the event |
688 | - os.rename(fromfile, tofile) |
689 | + rename(fromfile, tofile) |
690 | yield self._deferred |
691 | |
692 | @defer.inlineCallbacks |
693 | @@ -1501,13 +1512,13 @@ |
694 | |
695 | # generate the events |
696 | open_file(mypath("foo"), "w").close() |
697 | - os.rename(mypath("foo"), mypath("dir", "foo")) |
698 | + rename(mypath("foo"), mypath("dir", "foo")) |
699 | open_file(mypath("bar"), "w").close() |
700 | - os.rename(mypath("dir", "foo"), mypath("foo")) |
701 | - os.rename(mypath("bar"), mypath("dir", "bar")) |
702 | - os.remove(mypath("foo")) |
703 | - os.rename(mypath("dir", "bar"), mypath("bar")) |
704 | - os.remove(mypath("bar")) |
705 | + rename(mypath("dir", "foo"), mypath("foo")) |
706 | + rename(mypath("bar"), mypath("dir", "bar")) |
707 | + remove_file(mypath("foo")) |
708 | + rename(mypath("dir", "bar"), mypath("bar")) |
709 | + remove_file(mypath("bar")) |
710 | yield self._deferred |
711 | |
712 | @defer.inlineCallbacks |
713 | @@ -1530,14 +1541,14 @@ |
714 | elif path_to != tofile: |
715 | self.finished_error("received a wrong path in to") |
716 | else: |
717 | - os.remove(tofile) |
718 | + remove_file(tofile) |
719 | self.finished_ok() |
720 | |
721 | yield self.eq.add_watch(self.root_dir) |
722 | self.eq.subscribe(HitMe()) |
723 | |
724 | # generate the event |
725 | - os.rename(fromfile, tofile) |
726 | + rename(fromfile, tofile) |
727 | yield self._deferred |
728 | |
729 | @defer.inlineCallbacks |
730 | @@ -1560,14 +1571,14 @@ |
731 | elif path_to != todir: |
732 | self.finished_error("received a wrong path in to") |
733 | else: |
734 | - os.rmdir(todir) |
735 | + remove_dir(todir) |
736 | self.finished_ok() |
737 | |
738 | yield self.eq.add_watch(self.root_dir) |
739 | self.eq.subscribe(HitMe()) |
740 | |
741 | # generate the event |
742 | - os.rename(fromdir, todir) |
743 | + rename(fromdir, todir) |
744 | yield self._deferred |
745 | |
746 | @defer.inlineCallbacks |
747 | @@ -1603,11 +1614,11 @@ |
748 | # generate the events |
749 | open_file(mypath("foo"), "w").close() |
750 | open_file(mypath("bar"), "w").close() |
751 | - os.rename(mypath("foo"), mypath("dir", "foo")) |
752 | - os.rename(mypath("dir", "foo"), mypath("foo")) |
753 | - os.rename(mypath("bar"), mypath("baz")) |
754 | - os.remove(mypath("foo")) |
755 | - os.remove(mypath("baz")) |
756 | + rename(mypath("foo"), mypath("dir", "foo")) |
757 | + rename(mypath("dir", "foo"), mypath("foo")) |
758 | + rename(mypath("bar"), mypath("baz")) |
759 | + remove_file(mypath("foo")) |
760 | + remove_file(mypath("baz")) |
761 | yield self._deferred |
762 | |
763 | @defer.inlineCallbacks |
764 | @@ -1646,7 +1657,7 @@ |
765 | self.eq.subscribe(HitMe()) |
766 | |
767 | # generate the event |
768 | - os.rename(testdir, os.path.join(trash, os.path.basename(testdir))) |
769 | + rename(testdir, os.path.join(trash, os.path.basename(testdir))) |
770 | yield self._deferred |
771 | |
772 | @defer.inlineCallbacks |
773 | @@ -1665,8 +1676,8 @@ |
774 | if path != newfilepath: |
775 | self.finished_error("received a wrong path") |
776 | else: |
777 | - os.remove(newfilepath) |
778 | - os.rmdir(newdirname) |
779 | + remove_file(newfilepath) |
780 | + remove_dir(newdirname) |
781 | self.finished_ok() |
782 | |
783 | yield self.eq.add_watch(self.root_dir) |
784 | @@ -1674,7 +1685,7 @@ |
785 | self.eq.subscribe(HitMe()) |
786 | |
787 | # rename the dir |
788 | - os.rename(testdir, newdirname) |
789 | + rename(testdir, newdirname) |
790 | |
791 | # generate the event |
792 | newfilepath = os.path.join(newdirname, "afile") |
793 | @@ -1699,7 +1710,7 @@ |
794 | yield self.eq.add_watch(root_dir) |
795 | |
796 | # generate the event |
797 | - os.rename(fromfile, tofile) |
798 | + rename(fromfile, tofile) |
799 | yield self._deferred |
800 | |
801 | @defer.inlineCallbacks |
802 | @@ -1721,7 +1732,7 @@ |
803 | yield self.eq.add_watch(root_dir) |
804 | |
805 | # generate the event |
806 | - os.rename(fromdir, todir) |
807 | + rename(fromdir, todir) |
808 | yield self._deferred |
809 | |
810 | @defer.inlineCallbacks |
811 | @@ -1750,8 +1761,8 @@ |
812 | yield self.eq.add_watch(dir1) |
813 | |
814 | # generate the event |
815 | - os.rename(dir1, dir2) |
816 | - os.remove(tofile) |
817 | + rename(dir1, dir2) |
818 | + remove_file(tofile) |
819 | yield self._deferred |
820 | |
821 | @defer.inlineCallbacks |
822 | @@ -1771,7 +1782,7 @@ |
823 | yield self.eq.add_watch(self.root_dir) |
824 | |
825 | # generate the event |
826 | - os.rename(testfile + ".u1conflict", destfile) |
827 | + rename(testfile + ".u1conflict", destfile) |
828 | yield self._deferred |
829 | |
830 | @defer.inlineCallbacks |
831 | @@ -1790,7 +1801,7 @@ |
832 | yield self.eq.add_watch(self.root_dir) |
833 | |
834 | # generate the event |
835 | - os.rename(testfile + ".u1conflict", testfile) |
836 | + rename(testfile + ".u1conflict", testfile) |
837 | yield self._deferred |
838 | |
839 | @defer.inlineCallbacks |
840 | @@ -1808,7 +1819,7 @@ |
841 | yield self.eq.add_watch(self.root_dir) |
842 | |
843 | # generate the event |
844 | - os.rename(testdir + ".u1conflict", testdir) |
845 | + rename(testdir + ".u1conflict", testdir) |
846 | yield self._deferred |
847 | |
848 | @defer.inlineCallbacks |
849 | @@ -1827,7 +1838,7 @@ |
850 | yield self.eq.add_watch(self.root_dir) |
851 | |
852 | # generate the event |
853 | - os.rename(testdir + ".u1conflict", destdir) |
854 | + rename(testdir + ".u1conflict", destdir) |
855 | yield self._deferred |
856 | |
857 | @defer.inlineCallbacks |
858 | @@ -1856,8 +1867,8 @@ |
859 | # generate the event |
860 | open_file(testfile, "w").close() |
861 | # and change the permissions so it's ignored |
862 | - os.chmod(testfile, 0000) |
863 | - self.addCleanup(os.chmod, testfile, 0644) |
864 | + set_no_rights(testfile) |
865 | + self.addCleanup(set_file_readwrite, testfile) |
866 | |
867 | def check(record): |
868 | self.assertIn(testfile, record.args) |
869 | @@ -1891,8 +1902,8 @@ |
870 | # generate the event |
871 | os.makedirs(testdir) |
872 | # and change the permissions so it's ignored |
873 | - os.chmod(testdir, 0000) |
874 | - self.addCleanup(os.chmod, testdir, 0755) |
875 | + set_no_rights(testdir) |
876 | + self.addCleanup(set_dir_readwrite, testdir) |
877 | |
878 | def check(record): |
879 | self.assertIn(testdir, record.args) |
880 | @@ -1935,7 +1946,7 @@ |
881 | yield self.eq.add_watch(base2) |
882 | |
883 | # generate the event |
884 | - os.rename(moving1, moving2) |
885 | + rename(moving1, moving2) |
886 | yield self._deferred |
887 | |
888 | @defer.inlineCallbacks |
889 | @@ -1966,5 +1977,5 @@ |
890 | yield self.eq.add_watch(base2) |
891 | |
892 | # generate the event |
893 | - os.rename(moving1, moving2) |
894 | + rename(moving1, moving2) |
895 | yield self._deferred |
896 | |
897 | === modified file 'tests/syncdaemon/test_fsm.py' |
898 | --- tests/syncdaemon/test_fsm.py 2011-08-04 16:30:54 +0000 |
899 | +++ tests/syncdaemon/test_fsm.py 2011-08-09 16:37:30 +0000 |
900 | @@ -37,7 +37,16 @@ |
901 | ) |
902 | |
903 | from ubuntuone.devtools.handlers import MementoHandler |
904 | -from ubuntuone.platform import make_dir, make_link, open_file, path_exists |
905 | +from ubuntuone.platform import ( |
906 | + make_dir, |
907 | + make_link, |
908 | + open_file, |
909 | + path_exists, |
910 | + remove_dir, |
911 | + remove_file, |
912 | + set_dir_readonly, |
913 | + set_dir_readwrite, |
914 | +) |
915 | from ubuntuone.syncdaemon.filesystem_manager import ( |
916 | DirectoryNotRemovable, |
917 | EnableShareWrite, |
918 | @@ -84,9 +93,11 @@ |
919 | self.tritcask_path = self.mktemp("tritcask") |
920 | |
921 | self.db = Tritcask(self.tritcask_path) |
922 | + self.addCleanup(self.db.shutdown) |
923 | self.fsm = FileSystemManager(self.fsmdir, self.partials_dir, |
924 | FakeVolumeManager(self.root_dir), self.db) |
925 | self.eq = EventQueue(self.fsm) |
926 | + self.addCleanup(self.eq.shutdown) |
927 | self.fsm.register_eq(self.eq) |
928 | self.share = yield self.create_share('share', 'share_name') |
929 | self.share_path = self.share.path |
930 | @@ -96,15 +107,7 @@ |
931 | self.handler = MementoHandler() |
932 | self.handler.setLevel(0) |
933 | logger.root_logger.addHandler(self.handler) |
934 | - |
935 | - @defer.inlineCallbacks |
936 | - def tearDown(self): |
937 | - """Clean up the tests.""" |
938 | - self.eq.shutdown() |
939 | - self.db.shutdown() |
940 | - # remove the handler |
941 | - logger.root_logger.removeHandler(self.handler) |
942 | - yield super(FSMTestCase, self).tearDown() |
943 | + self.addCleanup(logger.root_logger.removeHandler, self.handler) |
944 | |
945 | @defer.inlineCallbacks |
946 | def create_share(self, share_id, share_name, fsm=None, shares_dir=None, |
947 | @@ -144,7 +147,7 @@ |
948 | db = Tritcask(fsmdir) |
949 | FileSystemManager(fsmdir, partials_dir, |
950 | FakeVolumeManager(fsmdir), db) |
951 | - self.assertTrue(os.path.exists(fsmdir)) |
952 | + self.assertTrue(path_exists(fsmdir)) |
953 | db.shutdown() |
954 | |
955 | @defer.inlineCallbacks |
956 | @@ -319,7 +322,7 @@ |
957 | |
958 | # delete the version that should have left the previous fsm |
959 | version_file = os.path.join(self.fsmdir, "metadata_version") |
960 | - os.remove(version_file) |
961 | + remove_file(version_file) |
962 | |
963 | # create a old-style fs with the data: |
964 | old_fs = FileShelf(self.fsm.old_fs._path) |
965 | @@ -682,7 +685,7 @@ |
966 | |
967 | # delete the version that should have left the previous fsm |
968 | version_file = os.path.join(self.fsmdir, "metadata_version") |
969 | - os.remove(version_file) |
970 | + remove_file(version_file) |
971 | |
972 | # start up again, and check |
973 | db = Tritcask(self.tritcask_path+'.new') |
974 | @@ -838,7 +841,7 @@ |
975 | |
976 | # delete the version that should have left the previous fsm |
977 | version_file = os.path.join(self.fsmdir, "metadata_version") |
978 | - os.remove(version_file) |
979 | + remove_file(version_file) |
980 | |
981 | # start up again, and check |
982 | db = Tritcask(self.tritcask_path+'.new') |
983 | @@ -1063,6 +1066,7 @@ |
984 | mdid, mdid_1) |
985 | db.shutdown() |
986 | |
987 | + |
988 | class GetSetTests(FSMTestCase): |
989 | """Test the get/set interface.""" |
990 | |
991 | @@ -1491,14 +1495,18 @@ |
992 | |
993 | def test_no_tree(self): |
994 | """Test just receiving the dir and not the tree.""" |
995 | - expected = ['a/b', 'a/b1', 'a/b2', 'a/c', 'a/x.txt'] |
996 | + expected = [os.path.join('a', 'b'), |
997 | + os.path.join('a', 'b1'), |
998 | + os.path.join( 'a', 'b2'), |
999 | + os.path.join( 'a', 'c'), |
1000 | + os.path.join( 'a', 'x.txt')] |
1001 | actual = sorted([d.path for d in self.fsm.get_mdobjs_in_dir( |
1002 | os.path.join(self.share.path, 'a'))]) |
1003 | self.assertEqual(expected, actual) |
1004 | |
1005 | def test_similar_paths(self): |
1006 | """Test having similar paths (a/b, a/b1, a/b2).""" |
1007 | - expected = ['a/b/y.txt'] |
1008 | + expected = [os.path.join('a', 'b', 'y.txt')] |
1009 | actual = sorted([d.path for d in self.fsm.get_mdobjs_in_dir( |
1010 | os.path.join(self.share.path, 'a', 'b'))]) |
1011 | self.assertEqual(expected, actual) |
1012 | @@ -1639,7 +1647,7 @@ |
1013 | # create partial ok |
1014 | self.fsm.create_partial("uuid", "share") |
1015 | self.assertTrue(self.fsm.get_by_mdid(mdid).info.is_partial) |
1016 | - self.assertTrue(os.path.exists(partial_path)) |
1017 | + self.assertTrue(path_exists(partial_path)) |
1018 | mdobj = self.fsm.get_by_mdid(mdid) |
1019 | when = mdobj.info.last_partial_created |
1020 | now = time.time() |
1021 | @@ -1668,7 +1676,7 @@ |
1022 | |
1023 | # commit partial, and check that the file is moved, and metadata is ok |
1024 | self.fsm.commit_partial("uuid", "share", local_hash=9876) |
1025 | - self.assertFalse(os.path.exists(partial_path)) |
1026 | + self.assertFalse(path_exists(partial_path)) |
1027 | with open(testfile) as fh: |
1028 | in_file = fh.read() |
1029 | self.assertEqual(in_file, "test info!") |
1030 | @@ -1706,7 +1714,7 @@ |
1031 | |
1032 | # remove partial, and check that the file is gone, and metadata is ok |
1033 | self.fsm.remove_partial("uuid", "share") |
1034 | - self.assertFalse(os.path.exists(partial_path)) |
1035 | + self.assertFalse(path_exists(partial_path)) |
1036 | with open(testfile) as fh: |
1037 | in_file = fh.read() |
1038 | self.assertEqual(in_file, "previous stuff!") |
1039 | @@ -1735,7 +1743,7 @@ |
1040 | self.assertTrue(self.fsm.get_by_mdid(mdid).info.is_partial) |
1041 | partial_path = os.path.join(self.fsm.partials_dir, |
1042 | mdid + ".u1partial." + os.path.basename(testdir)) |
1043 | - self.assertTrue(os.path.exists(partial_path)) |
1044 | + self.assertTrue(path_exists(partial_path)) |
1045 | mdobj = self.fsm.get_by_mdid(mdid) |
1046 | when = mdobj.info.last_partial_created |
1047 | now = time.time() |
1048 | @@ -1756,10 +1764,10 @@ |
1049 | # create partial ok |
1050 | self.fsm.create_partial("uuid", "share") |
1051 | self.assertTrue(self.fsm.get_by_mdid(mdid).info.is_partial) |
1052 | - self.assertTrue(os.path.exists(testdir)) |
1053 | + self.assertTrue(path_exists(testdir)) |
1054 | partial_path = os.path.join(self.fsm.partials_dir, |
1055 | mdid + ".u1partial." + os.path.basename(testdir)) |
1056 | - self.assertTrue(os.path.exists(partial_path)) |
1057 | + self.assertTrue(path_exists(partial_path)) |
1058 | mdobj = self.fsm.get_by_mdid(mdid) |
1059 | when = mdobj.info.last_partial_created |
1060 | now = time.time() |
1061 | @@ -1799,7 +1807,7 @@ |
1062 | self.fsm.remove_partial("uuid", "share") |
1063 | partial_path = os.path.join(self.fsm.partials_dir, |
1064 | mdid + ".u1partial." + os.path.basename(testdir)) |
1065 | - self.assertFalse(os.path.exists(partial_path)) |
1066 | + self.assertFalse(path_exists(partial_path)) |
1067 | mdobj = self.fsm.get_by_mdid(mdid) |
1068 | self.assertFalse(mdobj.info.is_partial) |
1069 | when = mdobj.info.last_partial_removed |
1070 | @@ -1842,7 +1850,7 @@ |
1071 | self.fsm.set_node_id(testfile, "uuid") |
1072 | |
1073 | # ugly problem not handled |
1074 | - os.rmdir(self.partials_dir) |
1075 | + remove_dir(self.partials_dir) |
1076 | try: |
1077 | self.fsm.create_partial("uuid", "share") |
1078 | except IOError, e: |
1079 | @@ -1871,7 +1879,7 @@ |
1080 | repeat -= 10 |
1081 | else: |
1082 | fh.close() |
1083 | - os.unlink(testfile) |
1084 | + remove_file(testfile) |
1085 | break |
1086 | mdid = self.fsm.create(testfile, "share") |
1087 | self.fsm.set_node_id(testfile, "uuid") |
1088 | @@ -1978,7 +1986,7 @@ |
1089 | |
1090 | # move first time |
1091 | self.fsm.move_to_conflict(mdid) |
1092 | - self.assertFalse(os.path.exists(testfile)) |
1093 | + self.assertFalse(path_exists(testfile)) |
1094 | with open(testfile + self.fsm.CONFLICT_SUFFIX) as fh: |
1095 | in_file = fh.read() |
1096 | self.assertEqual(in_file, "test!") |
1097 | @@ -1991,7 +1999,7 @@ |
1098 | with open(testfile, "w") as fh: |
1099 | fh.write("test 1!") |
1100 | self.fsm.move_to_conflict(mdid) |
1101 | - self.assertFalse(os.path.exists(testfile)) |
1102 | + self.assertFalse(path_exists(testfile)) |
1103 | with open(testfile + ".u1conflict.1") as fh: |
1104 | in_file = fh.read() |
1105 | self.assertEqual(in_file, "test 1!") |
1106 | @@ -2004,7 +2012,7 @@ |
1107 | with open(testfile, "w") as fh: |
1108 | fh.write("test 6!") |
1109 | self.fsm.move_to_conflict(mdid) |
1110 | - self.assertFalse(os.path.exists(testfile)) |
1111 | + self.assertFalse(path_exists(testfile)) |
1112 | with open(testfile + ".u1conflict.6") as fh: |
1113 | in_file = fh.read() |
1114 | self.assertEqual(in_file, "test 6!") |
1115 | @@ -2079,7 +2087,7 @@ |
1116 | # move the file |
1117 | to_path = os.path.join(self.share_path, "path2") |
1118 | self.fsm.move_file("share", testfile, to_path) |
1119 | - self.assertFalse(os.path.exists(testfile)) |
1120 | + self.assertFalse(path_exists(testfile)) |
1121 | with open(to_path) as fh: |
1122 | in_file = fh.read() |
1123 | self.assertEqual(in_file, "test!") |
1124 | @@ -2094,7 +2102,7 @@ |
1125 | os.mkdir(os.path.join(self.share_path, "testdir")) |
1126 | to_path = os.path.join(self.share_path, "testdir", "path3") |
1127 | self.fsm.move_file("share", from_path, to_path) |
1128 | - self.assertFalse(os.path.exists(from_path)) |
1129 | + self.assertFalse(path_exists(from_path)) |
1130 | with open(to_path) as fh: |
1131 | in_file = fh.read() |
1132 | self.assertEqual(in_file, "test!") |
1133 | @@ -2128,7 +2136,7 @@ |
1134 | |
1135 | # move the file |
1136 | self.fsm.move_file("share", testfile1, testfile2) |
1137 | - self.assertFalse(os.path.exists(testfile1)) |
1138 | + self.assertFalse(path_exists(testfile1)) |
1139 | with open(testfile2) as fh: |
1140 | in_file = fh.read() |
1141 | self.assertEqual(in_file, "test 1") |
1142 | @@ -2152,8 +2160,8 @@ |
1143 | os.mkdir(from_path) |
1144 | to_path = os.path.join(self.share_path, "path2") |
1145 | self.fsm.move_file("share", from_path, to_path) |
1146 | - self.assertFalse(os.path.exists(from_path)) |
1147 | - self.assertTrue(os.path.exists(to_path)) |
1148 | + self.assertFalse(path_exists(from_path)) |
1149 | + self.assertTrue(path_exists(to_path)) |
1150 | mdobj = self.fsm.get_by_mdid(mdid) |
1151 | self.assertEqual(mdobj.info.last_moved_from, from_path) |
1152 | when = mdobj.info.last_moved_time |
1153 | @@ -2165,8 +2173,8 @@ |
1154 | os.mkdir(os.path.join(self.share_path, "testdir")) |
1155 | to_path = os.path.join(self.share_path, "testdir", "path3") |
1156 | self.fsm.move_file("share", from_path, to_path) |
1157 | - self.assertFalse(os.path.exists(from_path)) |
1158 | - self.assertTrue(os.path.exists(to_path)) |
1159 | + self.assertFalse(path_exists(from_path)) |
1160 | + self.assertTrue(path_exists(to_path)) |
1161 | mdobj = self.fsm.get_by_mdid(mdid) |
1162 | self.assertEqual(mdobj.info.last_moved_from, from_path) |
1163 | when = mdobj.info.last_moved_time |
1164 | @@ -2196,8 +2204,8 @@ |
1165 | # move the dir |
1166 | to_path = os.path.join(self.share_path, "path2") |
1167 | self.fsm.move_file("share", from_path, to_path) |
1168 | - self.assertFalse(os.path.exists(from_path)) |
1169 | - self.assertTrue(os.path.exists(to_path)) |
1170 | + self.assertFalse(path_exists(from_path)) |
1171 | + self.assertTrue(path_exists(to_path)) |
1172 | mdobj = self.fsm.get_by_mdid(mdid) |
1173 | self.assertEqual(mdobj.info.last_moved_from, from_path) |
1174 | when = mdobj.info.last_moved_time |
1175 | @@ -2206,14 +2214,14 @@ |
1176 | |
1177 | # check that file inside is ok |
1178 | newfilepath = os.path.join(to_path, "file.txt") |
1179 | - self.assertFalse(os.path.exists(filepath)) |
1180 | - self.assertTrue(os.path.exists(newfilepath)) |
1181 | + self.assertFalse(path_exists(filepath)) |
1182 | + self.assertTrue(path_exists(newfilepath)) |
1183 | mdobj = self.fsm.get_by_path(newfilepath) |
1184 | self.assertEqual(mdobj.mdid, fileid) |
1185 | - self.assertEqual(mdobj.path, "path2/file.txt") |
1186 | + self.assertEqual(mdobj.path, os.path.join('path2', 'file.txt')) |
1187 | |
1188 | # check the outer file |
1189 | - self.assertTrue(os.path.exists(otherfile)) |
1190 | + self.assertTrue(path_exists(otherfile)) |
1191 | mdobj = self.fsm.get_by_path(otherfile) |
1192 | self.assertEqual(mdobj.path, "pa") |
1193 | |
1194 | @@ -2226,7 +2234,7 @@ |
1195 | |
1196 | # delete the file |
1197 | self.fsm.delete_file(testfile) |
1198 | - self.assertFalse(os.path.exists(testfile)) |
1199 | + self.assertFalse(path_exists(testfile)) |
1200 | self.assert_no_metadata(mdid, testfile, "share", "uuid") |
1201 | |
1202 | def test_delete_file_directly(self): |
1203 | @@ -2267,12 +2275,12 @@ |
1204 | self.assertEqual(self.fsm.get_by_mdid(mdid).path, "path") |
1205 | self.assertEqual(self.fsm.get_by_path(testdir).path, "path") |
1206 | self.assertEqual(self.fsm.get_by_node_id("share", "uuid").path, "path") |
1207 | - os.remove(os.path.join(testdir, "foo")) |
1208 | + remove_file(os.path.join(testdir, "foo")) |
1209 | |
1210 | # really delete the dir |
1211 | self.fsm.delete_file(testdir) |
1212 | |
1213 | - self.assertFalse(os.path.exists(testdir)) |
1214 | + self.assertFalse(path_exists(testdir)) |
1215 | self.assert_no_metadata(mdid, testdir, "share", "uuid") |
1216 | |
1217 | def test_delete_dir_directly(self): |
1218 | @@ -2318,10 +2326,10 @@ |
1219 | |
1220 | self.fsm.delete_file(local_dir) |
1221 | |
1222 | - self.assertFalse(os.path.exists(local_file)) |
1223 | + self.assertFalse(path_exists(local_file)) |
1224 | self.assert_no_metadata(mdid_file, local_file, "", "uuid_file") |
1225 | |
1226 | - self.assertFalse(os.path.exists(local_dir)) |
1227 | + self.assertFalse(path_exists(local_dir)) |
1228 | self.assert_no_metadata(mdid, local_dir, "", "uuid") |
1229 | |
1230 | def test_delete_nonempty_cleanable_dir_directly(self): |
1231 | @@ -2459,11 +2467,11 @@ |
1232 | |
1233 | # move the dir to conflict, the file is still there, but with no MD |
1234 | self.fsm.move_to_conflict(mdid1) |
1235 | - self.assertFalse(os.path.exists(tdir)) |
1236 | - self.assertTrue(os.path.exists(tdir + self.fsm.CONFLICT_SUFFIX)) |
1237 | + self.assertFalse(path_exists(tdir)) |
1238 | + self.assertTrue(path_exists(tdir + self.fsm.CONFLICT_SUFFIX)) |
1239 | testfile = os.path.join(self.share_path, |
1240 | tdir + self.fsm.CONFLICT_SUFFIX, "path") |
1241 | - self.assertTrue(os.path.exists(testfile)) |
1242 | + self.assertTrue(path_exists(testfile)) |
1243 | self.assertTrue(self.fsm.get_by_mdid(mdid1)) |
1244 | self.assert_no_metadata(mdid2, testfile, "share", "uuid2") |
1245 | |
1246 | @@ -2487,16 +2495,16 @@ |
1247 | |
1248 | # move the dir2 to conflict, see dir2 and file inside it went ok |
1249 | self.fsm.move_to_conflict(mdid2) |
1250 | - self.assertFalse(os.path.exists(tdir2)) |
1251 | - self.assertTrue(os.path.exists(tdir2 + self.fsm.CONFLICT_SUFFIX)) |
1252 | + self.assertFalse(path_exists(tdir2)) |
1253 | + self.assertTrue(path_exists(tdir2 + self.fsm.CONFLICT_SUFFIX)) |
1254 | testfile = os.path.join(self.share_path, |
1255 | tdir2 + self.fsm.CONFLICT_SUFFIX, "path") |
1256 | - self.assertTrue(os.path.exists(testfile)) |
1257 | + self.assertTrue(path_exists(testfile)) |
1258 | self.assertTrue(self.fsm.get_by_mdid(mdid2)) |
1259 | self.assertRaises(KeyError, self.fsm.get_by_mdid, mdid3) |
1260 | |
1261 | # and check that the one with similar path is untouched |
1262 | - self.assertTrue(os.path.exists(tdir1)) |
1263 | + self.assertTrue(path_exists(tdir1)) |
1264 | self.assertTrue(self.fsm.get_by_mdid(mdid1)) |
1265 | |
1266 | |
1267 | @@ -2815,7 +2823,7 @@ |
1268 | mdid = self.fsm.create(local_dir, "", is_dir=True) |
1269 | os.mkdir(local_dir) |
1270 | self.fsm.make_dir(mdid) |
1271 | - self.assertTrue(os.path.exists(local_dir)) |
1272 | + self.assertTrue(path_exists(local_dir)) |
1273 | |
1274 | @defer.inlineCallbacks |
1275 | def test_make_dir_in_ro_share(self): |
1276 | @@ -2825,7 +2833,7 @@ |
1277 | testdir = os.path.join(share.path, "foo") |
1278 | mdid = self.fsm.create(testdir, 'ro_share_id', is_dir=True) |
1279 | self.fsm.make_dir(mdid) |
1280 | - self.assertTrue(os.path.exists(testdir)) |
1281 | + self.assertTrue(path_exists(testdir)) |
1282 | |
1283 | @defer.inlineCallbacks |
1284 | def test_make_dir_ro_watch(self): |
1285 | @@ -2915,7 +2923,7 @@ |
1286 | self.fsm.CHANGED_SERVER) |
1287 | |
1288 | # remove the .partial by hand, to see it crash |
1289 | - os.remove(partial_path) |
1290 | + remove_file(partial_path) |
1291 | # pylint: disable-msg=W0212 |
1292 | self.assertRaises(InconsistencyError, |
1293 | self.fsm._check_partial, mdid=mdid) |
1294 | @@ -3060,7 +3068,7 @@ |
1295 | fd = self.fsm.get_partial_for_writing('uuid2', share.volume_id) |
1296 | fd.flush() |
1297 | fd.close() |
1298 | - self.assertTrue(os.path.exists(testdir)) |
1299 | + self.assertTrue(path_exists(testdir)) |
1300 | |
1301 | @defer.inlineCallbacks |
1302 | def test_file_ro_share(self): |
1303 | @@ -3075,7 +3083,7 @@ |
1304 | fd.flush() |
1305 | fd.close() |
1306 | self.fsm.commit_partial('uuid3', self.share.volume_id, None) |
1307 | - self.assertTrue(os.path.exists(testfile)) |
1308 | + self.assertTrue(path_exists(testfile)) |
1309 | |
1310 | @defer.inlineCallbacks |
1311 | def test_delete_dir_ro_share(self): |
1312 | @@ -3090,9 +3098,9 @@ |
1313 | fd.flush() |
1314 | fd.close() |
1315 | self.fsm.remove_partial('uuid2', share.volume_id) |
1316 | - self.assertTrue(os.path.exists(testdir)) |
1317 | + self.assertTrue(path_exists(testdir)) |
1318 | self.fsm.delete_file(testdir) |
1319 | - self.assertFalse(os.path.exists(testdir)) |
1320 | + self.assertFalse(path_exists(testdir)) |
1321 | |
1322 | @defer.inlineCallbacks |
1323 | def test_delete_non_empty_dir_ro_share(self): |
1324 | @@ -3118,11 +3126,11 @@ |
1325 | fd.close() |
1326 | self.fsm.commit_partial('uuid3', share.volume_id, None) |
1327 | self.fsm.upload_finished(mdid, self.fsm.get_by_mdid(mdid).local_hash) |
1328 | - self.assertTrue(os.path.exists(testdir)) |
1329 | - self.assertTrue(os.path.exists(testfile)) |
1330 | + self.assertTrue(path_exists(testdir)) |
1331 | + self.assertTrue(path_exists(testfile)) |
1332 | self.fsm.delete_file(testdir) |
1333 | - self.assertFalse(os.path.exists(testdir)) |
1334 | - self.assertFalse(os.path.exists(testfile)) |
1335 | + self.assertFalse(path_exists(testdir)) |
1336 | + self.assertFalse(path_exists(testfile)) |
1337 | |
1338 | @defer.inlineCallbacks |
1339 | def test_delete_non_empty_dir_rw_share(self): |
1340 | @@ -3148,11 +3156,11 @@ |
1341 | fd.close() |
1342 | self.fsm.commit_partial('uuid3', share.volume_id, None) |
1343 | self.fsm.upload_finished(mdid, self.fsm.get_by_mdid(mdid).local_hash) |
1344 | - self.assertTrue(os.path.exists(testdir)) |
1345 | - self.assertTrue(os.path.exists(testfile)) |
1346 | + self.assertTrue(path_exists(testdir)) |
1347 | + self.assertTrue(path_exists(testfile)) |
1348 | self.fsm.delete_file(testdir) |
1349 | - self.assertFalse(os.path.exists(testdir)) |
1350 | - self.assertFalse(os.path.exists(testfile)) |
1351 | + self.assertFalse(path_exists(testdir)) |
1352 | + self.assertFalse(path_exists(testfile)) |
1353 | |
1354 | @defer.inlineCallbacks |
1355 | def test_delete_non_empty_dir_bad_perms_rw_share(self): |
1356 | @@ -3178,16 +3186,18 @@ |
1357 | fd.close() |
1358 | self.fsm.commit_partial('uuid3', share.volume_id, None) |
1359 | self.fsm.upload_finished(mdid, self.fsm.get_by_mdid(mdid).local_hash) |
1360 | - self.assertTrue(os.path.exists(testdir)) |
1361 | - self.assertTrue(os.path.exists(testfile)) |
1362 | + self.assertTrue(path_exists(testdir)) |
1363 | + self.assertTrue(path_exists(testfile)) |
1364 | |
1365 | # make the dir read-only, the error should be logged |
1366 | - os.chmod(testdir, 0555) |
1367 | + set_dir_readonly(testdir) |
1368 | + self.addCleanup(set_dir_readwrite, testdir) |
1369 | + |
1370 | self.fsm.delete_file(testdir) |
1371 | self.assertTrue(self.handler.check_warning("OSError", testdir, |
1372 | "when trying to remove")) |
1373 | - self.assertTrue(os.path.exists(testdir)) |
1374 | - self.assertTrue(os.path.exists(testfile)) |
1375 | + self.assertTrue(path_exists(testdir)) |
1376 | + self.assertTrue(path_exists(testfile)) |
1377 | |
1378 | @defer.inlineCallbacks |
1379 | def test_delete_file_ro_share(self): |
1380 | @@ -3202,9 +3212,9 @@ |
1381 | fd.flush() |
1382 | fd.close() |
1383 | self.fsm.commit_partial('uuid3', self.share.volume_id, None) |
1384 | - self.assertTrue(os.path.exists(testfile)) |
1385 | + self.assertTrue(path_exists(testfile)) |
1386 | self.fsm.delete_file(testfile) |
1387 | - self.assertFalse(os.path.exists(testfile)) |
1388 | + self.assertFalse(path_exists(testfile)) |
1389 | |
1390 | @defer.inlineCallbacks |
1391 | def test_move_to_conflict_ro_share(self): |
1392 | @@ -3220,9 +3230,9 @@ |
1393 | fd.flush() |
1394 | fd.close() |
1395 | self.fsm.commit_partial('uuid3', self.share.volume_id, None) |
1396 | - self.assertTrue(os.path.exists(testfile)) |
1397 | + self.assertTrue(path_exists(testfile)) |
1398 | self.fsm.move_to_conflict(file_mdid) |
1399 | - self.assertTrue(os.path.exists(testfile + self.fsm.CONFLICT_SUFFIX)) |
1400 | + self.assertTrue(path_exists(testfile + self.fsm.CONFLICT_SUFFIX)) |
1401 | |
1402 | @defer.inlineCallbacks |
1403 | def test_file_rw_share_no_fail(self): |
1404 | @@ -3230,7 +3240,7 @@ |
1405 | share = yield self.create_share('ro_share', 'ro_share_name') |
1406 | testfile = os.path.join(share.path, "a_file") |
1407 | open(testfile, 'w').close() |
1408 | - self.assertTrue(os.path.exists(testfile)) |
1409 | + self.assertTrue(path_exists(testfile)) |
1410 | |
1411 | @defer.inlineCallbacks |
1412 | def test_dir_rw_share(self): |
1413 | @@ -3243,7 +3253,7 @@ |
1414 | fd = self.fsm.get_partial_for_writing('uuid2', share.volume_id) |
1415 | fd.flush() |
1416 | fd.close() |
1417 | - self.assertTrue(os.path.exists(testdir)) |
1418 | + self.assertTrue(path_exists(testdir)) |
1419 | |
1420 | @defer.inlineCallbacks |
1421 | def test_file_rw_share(self): |
1422 | @@ -3257,7 +3267,7 @@ |
1423 | fd.flush() |
1424 | fd.close() |
1425 | self.fsm.commit_partial('uuid3', self.share.volume_id, None) |
1426 | - self.assertTrue(os.path.exists(testfile)) |
1427 | + self.assertTrue(path_exists(testfile)) |
1428 | |
1429 | def test_share_and_root(self): |
1430 | """ Test the creation of a file with the same relative path in a share |
1431 | @@ -3277,8 +3287,8 @@ |
1432 | fd = self.fsm.get_partial_for_writing('uuid2', self.share.volume_id) |
1433 | fd.flush() |
1434 | fd.close() |
1435 | - self.assertTrue(os.path.exists(self.fsm.get_abspath("", a_dir_root))) |
1436 | - self.assertTrue(os.path.exists(a_dir_share)) |
1437 | + self.assertTrue(path_exists(self.fsm.get_abspath("", a_dir_root))) |
1438 | + self.assertTrue(path_exists(a_dir_share)) |
1439 | |
1440 | |
1441 | class TestEnableShareWrite(FSMTestCase): |
1442 | @@ -3388,7 +3398,7 @@ |
1443 | |
1444 | # delete the version that should have left the previous fsm |
1445 | version_file = os.path.join(self.data_dir, "metadata_version") |
1446 | - os.remove(version_file) |
1447 | + remove_file(version_file) |
1448 | |
1449 | # create a old-style fs with the data: |
1450 | old_fs = FileShelf(self.fsm.old_fs._path) |
1451 | |
1452 | === modified file 'tests/syncdaemon/test_localrescan.py' |
1453 | --- tests/syncdaemon/test_localrescan.py 2011-08-08 20:22:25 +0000 |
1454 | +++ tests/syncdaemon/test_localrescan.py 2011-08-09 16:37:30 +0000 |
1455 | @@ -28,7 +28,7 @@ |
1456 | |
1457 | from contrib.testing import testcase |
1458 | from ubuntuone.devtools.handlers import MementoHandler |
1459 | -from ubuntuone.platform import make_link |
1460 | +from ubuntuone.platform import make_link, remove_file, remove_dir, rename |
1461 | from ubuntuone.syncdaemon import local_rescan |
1462 | from ubuntuone.syncdaemon.marker import MDMarker |
1463 | from ubuntuone.syncdaemon.tritcask import Tritcask |
1464 | @@ -1019,7 +1019,7 @@ |
1465 | self.create_node("x", is_dir=False) |
1466 | |
1467 | # move the second into the first one |
1468 | - os.rename(pathy, pathx) |
1469 | + rename(pathy, pathx) |
1470 | |
1471 | # a & m times will be the same, but not the inode or change time |
1472 | def check(_): |
1473 | @@ -1117,9 +1117,9 @@ |
1474 | |
1475 | # remove a couple, create some new |
1476 | sh1 = os.path.join(self.share.path, "d") |
1477 | - os.remove(sh1) |
1478 | + remove_file(sh1) |
1479 | sh2 = os.path.join(self.share.path, "f") |
1480 | - os.remove(sh2) |
1481 | + remove_file(sh2) |
1482 | sh3 = os.path.join(self.share.path, "jj") |
1483 | open(sh3, "w").close() |
1484 | sh4 = os.path.join(self.share.path, "kk") |
1485 | @@ -1243,7 +1243,7 @@ |
1486 | for c in "abcdefgh": |
1487 | self.create_node(c, is_dir=False, which_share=self.share1) |
1488 | sh1 = os.path.join(self.share1.path, "d") |
1489 | - os.remove(sh1) |
1490 | + remove_file(sh1) |
1491 | sh2 = os.path.join(self.share1.path, "jj") |
1492 | open(sh2, "w").close() |
1493 | |
1494 | @@ -1251,7 +1251,7 @@ |
1495 | for c in "abcdefgh": |
1496 | self.create_node(c, is_dir=False, which_share=self.share2) |
1497 | sh3 = os.path.join(self.share2.path, "e") |
1498 | - os.remove(sh3) |
1499 | + remove_file(sh3) |
1500 | sh4 = os.path.join(self.share2.path, "kk") |
1501 | open(sh4, "w").close() |
1502 | |
1503 | @@ -1765,7 +1765,7 @@ |
1504 | self.fsm.create_partial("uuid", self.share.volume_id) |
1505 | |
1506 | # now, for some reason, we lose the partial file |
1507 | - os.remove(partial_path) |
1508 | + remove_file(partial_path) |
1509 | |
1510 | def check(_): |
1511 | """Compare predictable args, and check fh factory.""" |
1512 | @@ -1921,7 +1921,7 @@ |
1513 | |
1514 | |
1515 | # now change the dir for a file, for LR to find it |
1516 | - os.rmdir(path) |
1517 | + remove_dir(path) |
1518 | open(path, "w").close() |
1519 | |
1520 | def check(_): |
1521 | |
1522 | === modified file 'tests/syncdaemon/test_main.py' |
1523 | --- tests/syncdaemon/test_main.py 2011-08-03 21:41:45 +0000 |
1524 | +++ tests/syncdaemon/test_main.py 2011-08-09 16:37:30 +0000 |
1525 | @@ -28,7 +28,12 @@ |
1526 | ) |
1527 | from tests.platform import setup_main_test, get_main_params |
1528 | from ubuntuone.clientdefs import VERSION |
1529 | -from ubuntuone.platform import make_link |
1530 | +from ubuntuone.platform import ( |
1531 | + is_link, |
1532 | + make_link, |
1533 | + path_exists, |
1534 | + remove_dir, |
1535 | +) |
1536 | from ubuntuone.syncdaemon import main as main_mod |
1537 | |
1538 | |
1539 | @@ -148,13 +153,13 @@ |
1540 | def test_create_dirs_already_exists_dirs(self): |
1541 | """test that creating a Main instance works as expected.""" |
1542 | link = os.path.join(self.root, 'Shared With Me') |
1543 | - self.assertFalse(os.path.exists(link)) |
1544 | - self.assertTrue(os.path.exists(self.shares)) |
1545 | - self.assertTrue(os.path.exists(self.root)) |
1546 | + self.assertFalse(path_exists(link)) |
1547 | + self.assertTrue(path_exists(self.shares)) |
1548 | + self.assertTrue(path_exists(self.root)) |
1549 | main = self.build_main() |
1550 | - self.assertTrue(os.path.exists(main.shares_dir_link)) |
1551 | + self.assertTrue(path_exists(main.shares_dir_link)) |
1552 | # check that the shares link is actually a link |
1553 | - self.assertTrue(os.path.islink(main.shares_dir_link)) |
1554 | + self.assertTrue(is_link(main.shares_dir_link)) |
1555 | self.assertEquals(link, main.shares_dir_link) |
1556 | main.shutdown() |
1557 | |
1558 | @@ -162,41 +167,41 @@ |
1559 | """test that creating a Main instance works as expected.""" |
1560 | link = os.path.join(self.root, 'Shared With Me') |
1561 | make_link(self.shares, link) |
1562 | - self.assertTrue(os.path.exists(link)) |
1563 | - self.assertTrue(os.path.islink(link)) |
1564 | - self.assertTrue(os.path.exists(self.shares)) |
1565 | - self.assertTrue(os.path.exists(self.root)) |
1566 | + self.assertTrue(path_exists(link)) |
1567 | + self.assertTrue(is_link(link)) |
1568 | + self.assertTrue(path_exists(self.shares)) |
1569 | + self.assertTrue(path_exists(self.root)) |
1570 | main = self.build_main() |
1571 | # check that the shares link is actually a link |
1572 | - self.assertTrue(os.path.islink(main.shares_dir_link)) |
1573 | + self.assertTrue(is_link(main.shares_dir_link)) |
1574 | main.shutdown() |
1575 | |
1576 | def test_create_dirs_already_exists_but_not_symlink(self): |
1577 | """test that creating a Main instance works as expected.""" |
1578 | link = os.path.join(self.root, 'Shared With Me') |
1579 | os.makedirs(link) |
1580 | - self.assertTrue(os.path.exists(link)) |
1581 | - self.assertFalse(os.path.islink(link)) |
1582 | - self.assertTrue(os.path.exists(self.shares)) |
1583 | - self.assertTrue(os.path.exists(self.root)) |
1584 | + self.assertTrue(path_exists(link)) |
1585 | + self.assertFalse(is_link(link)) |
1586 | + self.assertTrue(path_exists(self.shares)) |
1587 | + self.assertTrue(path_exists(self.root)) |
1588 | main = self.build_main() |
1589 | # check that the shares link is actually a link |
1590 | self.assertEquals(main.shares_dir_link, link) |
1591 | - self.assertFalse(os.path.islink(main.shares_dir_link)) |
1592 | + self.assertFalse(is_link(main.shares_dir_link)) |
1593 | main.shutdown() |
1594 | |
1595 | def test_create_dirs_none_exists(self): |
1596 | """test that creating a Main instance works as expected.""" |
1597 | link = os.path.join(self.root, 'Shared With Me') |
1598 | # remove the existing dirs |
1599 | - os.rmdir(self.root) |
1600 | - os.rmdir(self.shares) |
1601 | + remove_dir(self.root) |
1602 | + remove_dir(self.shares) |
1603 | main = self.build_main() |
1604 | # check that the shares link is actually a link |
1605 | - self.assertTrue(os.path.exists(link)) |
1606 | - self.assertTrue(os.path.islink(main.shares_dir_link)) |
1607 | - self.assertTrue(os.path.exists(self.shares)) |
1608 | - self.assertTrue(os.path.exists(self.root)) |
1609 | + self.assertTrue(path_exists(link)) |
1610 | + self.assertTrue(is_link(main.shares_dir_link)) |
1611 | + self.assertTrue(path_exists(self.shares)) |
1612 | + self.assertTrue(path_exists(self.root)) |
1613 | main.shutdown() |
1614 | |
1615 | def test_connect_if_autoconnect_is_enabled(self): |
1616 | |
1617 | === modified file 'tests/syncdaemon/test_sync.py' |
1618 | --- tests/syncdaemon/test_sync.py 2011-08-03 20:59:59 +0000 |
1619 | +++ tests/syncdaemon/test_sync.py 2011-08-09 16:37:30 +0000 |
1620 | @@ -43,6 +43,7 @@ |
1621 | from ubuntuone.platform import ( |
1622 | make_dir, |
1623 | open_file, |
1624 | + remove_file, |
1625 | stat_path, |
1626 | ) |
1627 | from ubuntuone.syncdaemon.filesystem_manager import FileSystemManager |
1628 | @@ -228,14 +229,14 @@ |
1629 | self.main = FakeMain(root_dir=self.root, shares_dir=self.shares, |
1630 | data_dir=self.data, |
1631 | partials_dir=self.partials_dir) |
1632 | + self.addCleanup(self.main.shutdown) |
1633 | self._logger = logging.getLogger('ubuntuone.SyncDaemon') |
1634 | self._logger.addHandler(self.handler) |
1635 | + self.addCleanup(self._logger.removeHandler, self.handler) |
1636 | |
1637 | @defer.inlineCallbacks |
1638 | def tearDown(self): |
1639 | """Clean up.""" |
1640 | - self._logger.removeHandler(self.handler) |
1641 | - self.main.shutdown() |
1642 | FakeMain._sync_class = None |
1643 | for record in self.handler.records: |
1644 | exc_info = getattr(record, 'exc_info', None) |
1645 | @@ -811,7 +812,7 @@ |
1646 | # create the partial correctly, and break it! |
1647 | self.fsm.create_partial('node_id', '') |
1648 | partial_path = self.fsm._get_partial_path(self.fsm.fs[self.mdid]) |
1649 | - os.remove(partial_path) |
1650 | + remove_file(partial_path) |
1651 | |
1652 | # event! |
1653 | self.ssmr.commit_file('AQ_DOWNLOAD_COMMIT', None, 'hash') |
1654 | |
1655 | === modified file 'tests/syncdaemon/test_vm.py' |
1656 | --- tests/syncdaemon/test_vm.py 2011-08-05 10:56:06 +0000 |
1657 | +++ tests/syncdaemon/test_vm.py 2011-08-09 16:37:30 +0000 |
1658 | @@ -63,6 +63,9 @@ |
1659 | make_dir, |
1660 | path_exists, |
1661 | remove_link, |
1662 | + rename, |
1663 | + set_dir_readonly, |
1664 | + set_dir_readwrite, |
1665 | ) |
1666 | |
1667 | # grab the metadata version before tests fiddle with it |
1668 | @@ -918,7 +921,7 @@ |
1669 | self.main.fs.set_node_id(path, 'dir_node_id') |
1670 | yield self.vm._add_watch(path) |
1671 | |
1672 | - os.rename(path, path + '.old') |
1673 | + rename(path, path + '.old') |
1674 | # remove the watches |
1675 | self.vm._remove_watches(self.root_dir) |
1676 | |
1677 | @@ -3774,8 +3777,10 @@ |
1678 | make_dir(os.path.join(self.root_dir, 'My Files'),recursive=True) |
1679 | shares_dir = os.path.join(self.root_dir, 'Shared With Me') |
1680 | make_dir(shares_dir, recursive=True) |
1681 | - os.chmod(self.root_dir, 0500) |
1682 | - os.chmod(shares_dir, 0500) |
1683 | + set_dir_readonly(self.root_dir) |
1684 | + self.addCleanup(set_dir_readwrite, self.root_dir) |
1685 | + set_dir_readonly(shares_dir) |
1686 | + self.addCleanup(set_dir_readwrite, shares_dir) |
1687 | version = self.md_upgrader._guess_metadata_version() |
1688 | self.assertEquals(None, version) |
1689 | |
1690 | @@ -3789,8 +3794,10 @@ |
1691 | shares_dir = os.path.join(self.root_dir, 'Shared With Me') |
1692 | remove_link(shares_dir) |
1693 | make_dir(shares_dir, recursive=True) |
1694 | - os.chmod(self.root_dir, 0500) |
1695 | - os.chmod(shares_dir, 0500) |
1696 | + set_dir_readonly(self.root_dir) |
1697 | + self.addCleanup(set_dir_readwrite, self.root_dir) |
1698 | + set_dir_readonly(shares_dir) |
1699 | + self.addCleanup(set_dir_readwrite, shares_dir) |
1700 | self.rmtree(self.shares_dir) |
1701 | version = self.md_upgrader._guess_metadata_version() |
1702 | self.assertIn(version, ['1', '2']) |
1703 | @@ -3839,8 +3846,7 @@ |
1704 | dirpath = os.path.join('path', 'to', 'metadata') |
1705 | files = ['not_yet.partial', ] |
1706 | mocker = Mocker() |
1707 | - # ensure that we do use the platform method and not the |
1708 | - # os.rename one |
1709 | + # ensure that we do use the platform method and not the renamed one |
1710 | os_helper_rename = mocker.replace('ubuntuone.platform.rename') |
1711 | is_string = lambda x: isinstance(x, str) |
1712 | os_helper_rename(MATCH(is_string), MATCH(is_string)) |
1713 | @@ -3853,8 +3859,7 @@ |
1714 | shelf['foobar'] = _Share(path=os.path.join('foo','bar'), |
1715 | share_id='foobar') |
1716 | mocker = Mocker() |
1717 | - # ensure that we do use the platform method and not the |
1718 | - # os.rename one |
1719 | + # ensure that we do use the platform method and not the renamed one |
1720 | self.md_upgrader._upgrade_metadata_6 = mocker.mock() |
1721 | os_helper_rename = mocker.replace('ubuntuone.platform.rename') |
1722 | is_string = lambda x: isinstance(x, str) |
1723 | |
1724 | === modified file 'ubuntuone/platform/linux/filesystem_notifications.py' |
1725 | --- ubuntuone/platform/linux/filesystem_notifications.py 2011-07-28 22:21:07 +0000 |
1726 | +++ ubuntuone/platform/linux/filesystem_notifications.py 2011-08-09 16:37:30 +0000 |
1727 | @@ -24,9 +24,6 @@ |
1728 | import pyinotify |
1729 | from twisted.internet import abstract, reactor, error, defer |
1730 | |
1731 | -from ubuntuone.syncdaemon.filesystem_notifications import ( |
1732 | - GeneralINotifyProcessor |
1733 | -) |
1734 | |
1735 | # translates quickly the event and it's is_dir state to our standard events |
1736 | NAME_TRANSLATIONS = { |
1737 | @@ -152,6 +149,10 @@ |
1738 | FS_(DIR|FILE)_MOVE event when possible. |
1739 | """ |
1740 | def __init__(self, monitor, ignore_config=None): |
1741 | + # XXX: avoid circular imports |
1742 | + from ubuntuone.syncdaemon.filesystem_notifications import ( |
1743 | + GeneralINotifyProcessor |
1744 | + ) |
1745 | self.general_processor = GeneralINotifyProcessor(monitor, |
1746 | self.handle_dir_delete, NAME_TRANSLATIONS, |
1747 | self.platform_is_ignored, pyinotify.IN_IGNORED, |
1748 | |
1749 | === modified file 'ubuntuone/platform/windows/filesystem_notifications.py' |
1750 | --- ubuntuone/platform/windows/filesystem_notifications.py 2011-08-04 21:45:04 +0000 |
1751 | +++ ubuntuone/platform/windows/filesystem_notifications.py 2011-08-09 16:37:30 +0000 |
1752 | @@ -63,8 +63,6 @@ |
1753 | IN_MOVED_FROM, |
1754 | IN_MOVED_TO, |
1755 | IN_MODIFY) |
1756 | -from ubuntuone.syncdaemon.filesystem_notifications import ( |
1757 | - GeneralINotifyProcessor) |
1758 | from ubuntuone.platform.windows.os_helper import ( |
1759 | is_valid_syncdaemon_path, |
1760 | is_valid_windows_path, |
1761 | @@ -471,6 +469,10 @@ |
1762 | """ |
1763 | |
1764 | def __init__(self, monitor, ignore_config=None): |
1765 | + # XXX: avoid circular imports. |
1766 | + from ubuntuone.syncdaemon.filesystem_notifications import ( |
1767 | + GeneralINotifyProcessor |
1768 | + ) |
1769 | self.general_processor = GeneralINotifyProcessor(monitor, |
1770 | self.handle_dir_delete, NAME_TRANSLATIONS, |
1771 | self.platform_is_ignored, IN_IGNORED, ignore_config=ignore_config) |
1772 | |
1773 | === modified file 'ubuntuone/syncdaemon/file_shelf.py' |
1774 | --- ubuntuone/syncdaemon/file_shelf.py 2011-08-05 15:17:28 +0000 |
1775 | +++ ubuntuone/syncdaemon/file_shelf.py 2011-08-09 16:37:30 +0000 |
1776 | @@ -19,14 +19,23 @@ |
1777 | """storage shelf using a files tree.""" |
1778 | |
1779 | from __future__ import with_statement |
1780 | -from UserDict import DictMixin |
1781 | + |
1782 | import cPickle |
1783 | import os |
1784 | import stat |
1785 | import errno |
1786 | + |
1787 | from collections import deque |
1788 | - |
1789 | -from ubuntuone.platform import make_dir, open_file, remove_file, rename, stat_path |
1790 | +from UserDict import DictMixin |
1791 | + |
1792 | +from ubuntuone.platform import ( |
1793 | + make_dir, |
1794 | + open_file, |
1795 | + remove_file, |
1796 | + rename, |
1797 | + stat_path, |
1798 | +) |
1799 | + |
1800 | |
1801 | class FileShelf(object, DictMixin): |
1802 | """ File based shelf. |
1803 | |
1804 | === modified file 'ubuntuone/syncdaemon/filesystem_manager.py' |
1805 | --- ubuntuone/syncdaemon/filesystem_manager.py 2011-07-28 15:43:05 +0000 |
1806 | +++ ubuntuone/syncdaemon/filesystem_manager.py 2011-08-09 16:37:30 +0000 |
1807 | @@ -1558,7 +1558,7 @@ |
1808 | set_file_readonly(self.path) |
1809 | |
1810 | # restore all saved ones |
1811 | - exists = os.path.exists |
1812 | + exists = path_exists |
1813 | for path, isdir in self._changed_nodes[::-1]: |
1814 | if exists(path): |
1815 | if isdir: |
1816 | |
1817 | === modified file 'ubuntuone/syncdaemon/filesystem_notifications.py' |
1818 | --- ubuntuone/syncdaemon/filesystem_notifications.py 2011-04-20 09:13:43 +0000 |
1819 | +++ ubuntuone/syncdaemon/filesystem_notifications.py 2011-08-09 16:37:30 +0000 |
1820 | @@ -19,6 +19,7 @@ |
1821 | import os |
1822 | import re |
1823 | |
1824 | +from ubuntuone.platform import path_exists |
1825 | from ubuntuone.syncdaemon.mute_filter import MuteFilter |
1826 | from ubuntuone import logger |
1827 | # our logging level |
1828 | @@ -96,7 +97,7 @@ |
1829 | # check first if the platform code knows hat to do with it |
1830 | if not self.platform_is_ignored(path): |
1831 | # check if we can read |
1832 | - if os.path.exists(path) and not os.access(path, os.R_OK): |
1833 | + if path_exists(path) and not os.access(path, os.R_OK): |
1834 | self.log.warning("Ignoring path as we don't have enough " |
1835 | "permissions to track it: %r", path) |
1836 | return True |
1837 | |
1838 | === modified file 'ubuntuone/syncdaemon/local_rescan.py' |
1839 | --- ubuntuone/syncdaemon/local_rescan.py 2011-06-24 20:24:51 +0000 |
1840 | +++ ubuntuone/syncdaemon/local_rescan.py 2011-08-09 16:37:30 +0000 |
1841 | @@ -205,7 +205,7 @@ |
1842 | log_error("The received path is not in any share!") |
1843 | raise ValueError("The received path is not in any share!") |
1844 | |
1845 | - # uglier than os.path.exists and isdir, but only hit the disk once |
1846 | + # uglier than path_exists and isdir, but only hit the disk once |
1847 | stat_result = get_stat(direct) |
1848 | if stat_result is None: |
1849 | m = "The received path is not in disk: path %r mdid %s" |
1850 | |
1851 | === modified file 'ubuntuone/syncdaemon/vm_helper.py' |
1852 | --- ubuntuone/syncdaemon/vm_helper.py 2011-08-03 20:44:10 +0000 |
1853 | +++ ubuntuone/syncdaemon/vm_helper.py 2011-08-09 16:37:30 +0000 |
1854 | @@ -27,6 +27,7 @@ |
1855 | make_link, |
1856 | path_exists, |
1857 | read_link, |
1858 | + remove_file, |
1859 | ) |
1860 | |
1861 | |
1862 | @@ -70,7 +71,7 @@ |
1863 | if not path_exists(dest): |
1864 | # remove the symlink if it's broken |
1865 | if is_link(dest) and read_link(dest) != source: |
1866 | - os.remove(dest) |
1867 | + remove_file(dest) |
1868 | make_link(source, dest) |
1869 | return True |
1870 | else: |
1871 | |
1872 | === modified file 'ubuntuone/syncdaemon/volume_manager.py' |
1873 | --- ubuntuone/syncdaemon/volume_manager.py 2011-08-03 20:20:02 +0000 |
1874 | +++ ubuntuone/syncdaemon/volume_manager.py 2011-08-09 16:37:30 +0000 |
1875 | @@ -57,6 +57,8 @@ |
1876 | normpath, |
1877 | path_exists, |
1878 | read_link, |
1879 | + remove_file, |
1880 | + remove_dir, |
1881 | rename, |
1882 | set_dir_readonly, |
1883 | set_dir_readwrite, |
1884 | @@ -68,8 +70,6 @@ |
1885 | UDF_ROW_TYPE = 5 |
1886 | |
1887 | |
1888 | - |
1889 | - |
1890 | class _Share(object): |
1891 | """Represents a share or mount point""" |
1892 | |
1893 | @@ -1434,12 +1434,12 @@ |
1894 | |
1895 | def _get_md_version(self): |
1896 | """Returns the current md_version""" |
1897 | - if not os.path.exists(self._data_dir): |
1898 | + if not path_exists(self._data_dir): |
1899 | # first run, the data dir don't exist. No metadata to upgrade |
1900 | md_version = VolumeManager.METADATA_VERSION |
1901 | os.makedirs(self._data_dir) |
1902 | self.update_metadata_version() |
1903 | - elif os.path.exists(self._version_file): |
1904 | + elif path_exists(self._version_file): |
1905 | with open(self._version_file) as fh: |
1906 | md_version = fh.read().strip() |
1907 | if not md_version: |
1908 | @@ -1454,7 +1454,7 @@ |
1909 | |
1910 | def update_metadata_version(self): |
1911 | """Write the version of the metadata.""" |
1912 | - if not os.path.exists(os.path.dirname(self._version_file)): |
1913 | + if not path_exists(os.path.dirname(self._version_file)): |
1914 | os.makedirs(os.path.dirname(self._version_file)) |
1915 | with open(self._version_file, 'w') as fd: |
1916 | fd.write(VolumeManager.METADATA_VERSION) |
1917 | @@ -1468,14 +1468,14 @@ |
1918 | |
1919 | """ |
1920 | md_version = None |
1921 | - if os.path.exists(self._shares_md_dir) \ |
1922 | - and os.path.exists(self._shared_md_dir): |
1923 | + if path_exists(self._shares_md_dir) \ |
1924 | + and path_exists(self._shared_md_dir): |
1925 | # we have shares and shared dirs |
1926 | # md_version >= 1 |
1927 | old_root_dir = os.path.abspath(os.path.join(self._root_dir, 'My Files')) |
1928 | old_share_dir = os.path.abspath(os.path.join(self._root_dir, |
1929 | 'Shared With Me')) |
1930 | - if os.path.exists(old_share_dir) and os.path.exists(old_root_dir) \ |
1931 | + if path_exists(old_share_dir) and path_exists(old_root_dir) \ |
1932 | and not is_link(old_share_dir): |
1933 | # md >= 1 and <= 3 |
1934 | # we have a My Files dir, 'Shared With Me' isn't a |
1935 | @@ -1524,7 +1524,7 @@ |
1936 | # the shelf already exists, and don't have a .version file |
1937 | # first backup the old data |
1938 | backup = os.path.join(self._data_dir, '0.bkp') |
1939 | - if not os.path.exists(backup): |
1940 | + if not path_exists(backup): |
1941 | os.makedirs(backup) |
1942 | # pylint: disable-msg=W0612 |
1943 | # filter 'shares' and 'shared' dirs, in case we are in the case of |
1944 | @@ -1539,7 +1539,7 @@ |
1945 | os.path.join(backup, dir)) |
1946 | # regenerate the shelf using the new layout using the backup as src |
1947 | old_shelf = LegacyShareFileShelf(backup) |
1948 | - if not os.path.exists(self._shares_dir): |
1949 | + if not path_exists(self._shares_dir): |
1950 | os.makedirs(self._shares_dir) |
1951 | new_shelf = LegacyShareFileShelf(self._shares_md_dir) |
1952 | for key, share in old_shelf.iteritems(): |
1953 | @@ -1629,19 +1629,19 @@ |
1954 | old_share_dir = os.path.join(self._root_dir, 'Shared With Me') |
1955 | old_root_dir = os.path.join(self._root_dir, 'My Files') |
1956 | # change permissions |
1957 | - os.chmod(self._root_dir, 0775) |
1958 | + set_dir_readwrite(self._root_dir) |
1959 | |
1960 | def move(src, dst): |
1961 | """Move a file/dir taking care if it's read-only.""" |
1962 | prev_mode = stat.S_IMODE(os.stat(src).st_mode) |
1963 | - os.chmod(src, 0755) |
1964 | + set_dir_readwrite(src) |
1965 | shutil.move(src, dst) |
1966 | os.chmod(dst, prev_mode) |
1967 | |
1968 | # update the path's in metadata and move the folder |
1969 | - if os.path.exists(old_share_dir) and not is_link(old_share_dir): |
1970 | - os.chmod(old_share_dir, 0775) |
1971 | - if not os.path.exists(os.path.dirname(self._shares_dir)): |
1972 | + if path_exists(old_share_dir) and not is_link(old_share_dir): |
1973 | + set_dir_readwrite(old_share_dir) |
1974 | + if not path_exists(os.path.dirname(self._shares_dir)): |
1975 | os.makedirs(os.path.dirname(self._shares_dir)) |
1976 | self.log.debug('moving shares dir from: %r to %r', |
1977 | old_share_dir, self._shares_dir) |
1978 | @@ -1649,7 +1649,7 @@ |
1979 | src = os.path.join(old_share_dir, path) |
1980 | dst = os.path.join(self._shares_dir, path) |
1981 | move(src, dst) |
1982 | - os.rmdir(old_share_dir) |
1983 | + remove_dir(old_share_dir) |
1984 | |
1985 | # update the shares metadata |
1986 | shares = LegacyShareFileShelf(self._shares_md_dir) |
1987 | @@ -1670,25 +1670,25 @@ |
1988 | shared[key] = share |
1989 | # move the My Files contents, taking care of dir/files with the same |
1990 | # name in the new root |
1991 | - if os.path.exists(old_root_dir): |
1992 | + if path_exists(old_root_dir): |
1993 | self.log.debug('moving My Files contents to the root') |
1994 | # make My Files rw |
1995 | - os.chmod(old_root_dir, 0775) |
1996 | + set_dir_readwrite(old_root_dir) |
1997 | path_join = os.path.join |
1998 | for relpath in listdir(old_root_dir): |
1999 | old_path = path_join(old_root_dir, relpath) |
2000 | new_path = path_join(self._root_dir, relpath) |
2001 | - if os.path.exists(new_path): |
2002 | + if path_exists(new_path): |
2003 | shutil.move(new_path, new_path+'.u1conflict') |
2004 | if relpath == 'Shared With Me': |
2005 | # remove the Shared with Me symlink inside My Files! |
2006 | self.log.debug('removing shares symlink from old root') |
2007 | - os.remove(old_path) |
2008 | + remove_file(old_path) |
2009 | else: |
2010 | self.log.debug('moving %r to %r', old_path, new_path) |
2011 | move(old_path, new_path) |
2012 | self.log.debug('removing old root: %r', old_root_dir) |
2013 | - os.rmdir(old_root_dir) |
2014 | + remove_dir(old_root_dir) |
2015 | |
2016 | # fix broken symlink (md_version 4) |
2017 | self._upgrade_metadata_4(md_version) |
2018 | @@ -1702,7 +1702,7 @@ |
2019 | # the symnlink points to itself |
2020 | self.log.debug('removing broken shares symlink: %r -> %r', |
2021 | self._shares_dir_link, target) |
2022 | - os.remove(self._shares_dir_link) |
2023 | + remove_file(self._shares_dir_link) |
2024 | self._upgrade_metadata_5(md_version) |
2025 | |
2026 | def _upgrade_metadata_5(self, md_version): |
Great branch