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