Merge lp:~diegosarmentero/ubuntuone-client/fix-links into lp:ubuntuone-client

Proposed by Diego Sarmentero
Status: Merged
Approved by: Diego Sarmentero
Approved revision: 1185
Merged at revision: 1179
Proposed branch: lp:~diegosarmentero/ubuntuone-client/fix-links
Merge into: lp:ubuntuone-client
Diff against target: 467 lines (+140/-20)
14 files modified
tests/platform/test_external_interface.py (+8/-0)
tests/platform/test_os_helper.py (+27/-0)
tests/platform/test_tools.py (+6/-0)
tests/platform/test_u1sdtool.py (+15/-5)
tests/syncdaemon/test_interaction_interfaces.py (+5/-0)
tests/syncdaemon/test_main.py (+6/-0)
tests/syncdaemon/test_vm_helper.py (+17/-0)
ubuntuone/platform/linux/dbus_interface.py (+6/-0)
ubuntuone/platform/tools/__init__.py (+5/-0)
ubuntuone/platform/windows/ipc.py (+5/-1)
ubuntuone/platform/windows/ipc_client.py (+4/-0)
ubuntuone/platform/windows/os_helper.py (+26/-13)
ubuntuone/syncdaemon/interaction_interfaces.py (+5/-0)
ubuntuone/syncdaemon/main.py (+5/-1)
To merge this branch: bzr merge lp:~diegosarmentero/ubuntuone-client/fix-links
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+86605@code.launchpad.net

Commit message

- Provide a get_home_dir() method to get a proper home dir in unicode environments (LP: #898640).
- Handle link creation with unicode paths (LP: #891173).

Description of the change

Fix: Create get_home_dir() method to get a proper home dir in unicode environments (LP: #898640).
fIX: Handle link creation with unicode paths (LP: #891173).

To install the new dependency, download this file:

FOR WINDOWS:
http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe/download
and execute the file.

FOR LINUX:
http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.zip/download

Uncompress the file, go inside the folder, and execute in a console: "python setup.py install"

To post a comment you must log in.
1168. By Diego Sarmentero

merge

1169. By Diego Sarmentero

merge

1170. By Diego Sarmentero

Revert run-test.bat, fix tests

1171. By Diego Sarmentero

Reverting run-tests.bat

1172. By Diego Sarmentero

Reverting run-tests.bat

1173. By Diego Sarmentero

Fixed some docstrings

1174. By Diego Sarmentero

changing files permissions

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

* The test_show_folders_subscribed was buggy before this branch. The proper fix, besides adding the get_udf_path call, is to also have suggested_path be a "server" path, which always use the / slash.

So, the fix should include something like this:

        suggested_path = u'~/ñoño' # no os.path.join
        path = get_udf_path(suggested_path)

and the rest as how this branch propose it.

* The tests test_create_shares_link_exists_with_lnk and test_create_shares_link_existing_with_lnk are very similar in name and in code. Though I can see the difference, I'm not sure we need both, and we certainly need better names for each one to have future readers understanding the goal of each test. Can you please improve the naming a bit, and expand in the docstring what each test is checking?

* There is no need to have 2 if's f or this:

    if not exists:
        if not path.endswith(u'.lnk'):

it can be improved to:

    if not exists and not path.endswith(u'.lnk'):

* As per the comment on make_link in the except AttributeError block, shall we remove that now that we handle unicode paths?

* Can you please add tests to os_helper to reflect the changes you have made to path_exists, make_link and read_link?

Thanks!

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

One question, can the xdg from sso be replaced by dirspec.basedir?

review: Needs Information
1175. By Diego Sarmentero

Adding tests for make_link, read_link, path_exists

1176. By Diego Sarmentero

Changing path exist implementation

Revision history for this message
Manuel de la Peña (mandel) wrote :

A couple of comments:

* Merge test_links_target_without_lnk_extension and test_links_target_with_lnk_extension so that we have more code reuse.
* Instead of:
    exists = os.path.exists(path) or is_link(path)
    return exists

just do return os.path.exists(path) or is_link(path) :)

review: Needs Fixing
1177. By Diego Sarmentero

Improving some tests.

1178. By Diego Sarmentero

Removing unnecesary except

Revision history for this message
Natalia Bidart (nataliabidart) wrote :
Download full text (3.6 KiB)

The changes to run-tests.bat should be reverted since the directory with tests should be at the end of the test command line.

Also, when running the suite on an account with unicode-complex-username, I'm getting all these errors:

===============================================================================
[FAIL]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in _inlineCallbacks
    result = g.send(result)
  File "E:\client\review_fix-links\tests\platform\test_tools.py", line 964, in test_get_home_dir
    self.assertEqual(self.main.get_homedir(), result)
twisted.trial.unittest.FailTest: not equal:
a = 'C:\\Users\\\xe7\xba\xb3\xe5\xa1\x94\xe5\x88\xa9\xe5\xa8\x85 \xd7\xa8\xd7\x99\xd7\x90\xd7\x94'
b = u'C:\\Users\\\u7eb3\u5854\u5229\u5a05 \u05e8\u05d9\u05d0\u05d4'

tests.platform.test_tools.TestToolsSomeMore.test_get_home_dir
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\client\review_fix-links\tests\platform\test_os_helper.py", line 347, in test_links_target_with_lnk_extension
    self._assert_read_link(destination)
  File "E:\client\review_fix-links\tests\platform\test_os_helper.py", line 333, in _assert_read_link
    target = read_link(destination)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 334, in inner
    result = function(*args, **kwargs)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 381, in inner
    return function(*args, **kwargs)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 672, in read_link
    result = get_syncdaemon_valid_path(LONG_PATH_PREFIX + target_path)
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 126: ordinal not in range(128)

tests.platform.windows.test_os_helper.TestIllegalPaths.test_links_target_with_lnk_extension
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\client\review_fix-links\tests\platform\test_os_helper.py", line 342, in test_links_target_without_lnk_extension
    self._assert_read_link(destination)
  File "E:\client\review_fix-links\tests\platform\test_os_helper.py", line 333, in _assert_read_link
    target = read_link(destination)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 334, in inner
    result = function(*args, **kwargs)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 381, in inner
    return function(*args, **kwargs)
  File "E:\client\review_fix-links\ubuntuone\platform\windows\os_helper.py", line 672, in read_link
    result = get_syncdaemon_valid_path(LONG_PATH_PREFIX + target_path)
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 129: ordinal not in range(128)

tests.platform.windows.test_os_helper.TestIllegalPaths.test_links_target_without_lnk_extension
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\client\review_fix-links\tests...

Read more...

review: Needs Fixing
1179. By Diego Sarmentero

Reverted run-tests.bat

1180. By Diego Sarmentero

Fixed tests.xy

1181. By Diego Sarmentero

fixing pep8 issues.

1182. By Diego Sarmentero

merge

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

Test are still failing for me in windows, with unicode issues. See:

===============================================================================
[FAIL]
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1020, in _inlineCallbacks
    result = g.send(result)
  File "E:\client\review_fix-links\tests\platform\test_tools.py", line 964, in test_get_home_dir
    self.assertEqual(self.main.get_homedir(), result)
twisted.trial.unittest.FailTest: not equal:
a = 'C:\\Users\\\xe5\x8d\x97\xe6\xb8\xa1\xe6\xb1\x9f \xd7\xa0\xd7\x95\xd7\xa0\xd7\x95'
b = u'C:\\Users\\\u5357\u6e21\u6c5f \u05e0\u05d5\u05e0\u05d5'

tests.platform.test_tools.TestToolsSomeMore.test_get_home_dir
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "E:\client\review_fix-links\tests\syncdaemon\test_interaction_interfaces.py", line 2164, in test_get_homedir
    self.assertEqual(self.main.get_homedir(), str(result))
exceptions.UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-11: ordinal not in range(128)

tests.syncdaemon.test_interaction_interfaces.SyncdaemonServiceTestCase.test_get_homedir
-------------------------------------------------------------------------------
Ran 2545 tests in 271.941s

FAILED (skips=93, failures=1, errors=1, successes=2450)

review: Needs Fixing
1183. By Diego Sarmentero

Tests Fixed.

1184. By Diego Sarmentero

revert run-tests.bat

Revision history for this message
Manuel de la Peña (mandel) wrote :

From irc:

mandel> gatox, in _assert_read_link you could have done destination = os.path.join(self.basedir, target) and then pass the target as 'target' or 'target.lnk'
<mandel> gatox, also test_create_shares_link_existing_destiny_with_lnk_extension and test_create_shares_link_existing_source_with_lnk_extension can share a fair amount of code

review: Needs Fixing
1185. By Diego Sarmentero

Tests improved.

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

Looks good! Tested IRL.

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

Looks ok since we will clean the code later.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/test_external_interface.py'
2--- tests/platform/test_external_interface.py 2011-10-26 20:20:37 +0000
3+++ tests/platform/test_external_interface.py 2012-01-12 14:04:25 +0000
4@@ -165,6 +165,14 @@
5 self.assert_remote_method('disconnect')
6
7 @defer.inlineCallbacks
8+ def test_get_homedir(self):
9+ """Test get_homedir."""
10+ result = self.root_dir
11+ yield self.assert_method_called(self.service.sync,
12+ 'get_homedir', result)
13+ self.assert_remote_method('get_homedir', out_signature='s')
14+
15+ @defer.inlineCallbacks
16 def test_get_rootdir(self):
17 """Test get_rootdir."""
18 result = self.root_dir
19
20=== modified file 'tests/platform/test_os_helper.py'
21--- tests/platform/test_os_helper.py 2011-11-17 19:24:31 +0000
22+++ tests/platform/test_os_helper.py 2012-01-12 14:04:25 +0000
23@@ -311,6 +311,12 @@
24 """The dir is not there."""
25 self.assertFalse(path_exists(os.path.join(self.basedir, 'subdir')))
26
27+ def test_path_exist_for_link_without_lnk_extension(self):
28+ """Test if the path of a link exist without the lnk extension."""
29+ destination = os.path.join(self.basedir, 'destination')
30+ make_link(self.testfile, destination)
31+ self.assertTrue(path_exists(destination))
32+
33 def test_make_link(self):
34 """The link is properly made."""
35 destination = os.path.join(self.basedir, 'destination')
36@@ -320,6 +326,27 @@
37 self.assertEqual(os.path.normcase(self.testfile),
38 os.path.normcase(read_link(destination)))
39
40+ def _assert_read_link(self, target):
41+ """Assert if the target path of the link is correct."""
42+ destination = os.path.join(self.basedir, target)
43+ make_link(self.testfile, destination)
44+
45+ target = read_link(destination)
46+ self.assertEqual(self.testfile, target)
47+
48+ def test_links_target_without_lnk_extension(self):
49+ """Create a link to self.testfile and then retrieve the link target."""
50+ # In windows the .lnk extension should be added automatically
51+ # if the extension is not added by make_link, read_link will fail
52+ # because Windows is not going to recognize the file as a link
53+ target = 'target'
54+ self._assert_read_link(target)
55+
56+ def test_links_target_with_lnk_extension(self):
57+ """Create a link to self.testfile and then retrieve the link target."""
58+ target = 'target.lnk'
59+ self._assert_read_link(target)
60+
61 def test_movetotrash_file_ok(self):
62 """Move a file to trash ok.
63
64
65=== modified file 'tests/platform/test_tools.py'
66--- tests/platform/test_tools.py 2011-11-17 18:38:41 +0000
67+++ tests/platform/test_tools.py 2012-01-12 14:04:25 +0000
68@@ -958,6 +958,12 @@
69 repr(dirty_mdids[mdid2]['path'].encode('utf-8')))
70
71 @defer.inlineCallbacks
72+ def test_get_home_dir(self):
73+ """Test the get_home_dir method."""
74+ result = yield self.tool.get_home_dir()
75+ self.assertEqual(self.main.get_homedir().decode('utf-8'), result)
76+
77+ @defer.inlineCallbacks
78 def test_get_root_dir(self):
79 """Test the get_root_dir method."""
80 result = yield self.tool.get_root_dir()
81
82=== modified file 'tests/platform/test_u1sdtool.py'
83--- tests/platform/test_u1sdtool.py 2011-11-02 16:51:32 +0000
84+++ tests/platform/test_u1sdtool.py 2012-01-12 14:04:25 +0000
85@@ -28,6 +28,7 @@
86 FakeDownload,
87 FakeUpload,
88 )
89+from ubuntuone.syncdaemon.vm_helper import get_udf_path
90 from ubuntuone.syncdaemon.volume_manager import (
91 ACCESS_LEVEL_RO,
92 Share,
93@@ -58,6 +59,7 @@
94 out = StringIO()
95 d = self.tool.get_shares()
96 d.addCallback(lambda result: show_shares(result, out))
97+
98 def check(result):
99 """check the output"""
100 self.assertEqual('No shares\n', out.getvalue())
101@@ -86,6 +88,7 @@
102 out = StringIO()
103 d = self.tool.list_shared()
104 d.addCallback(lambda result: show_shared(result, out))
105+
106 def check(result):
107 """check the output"""
108 self.assertEqual('No shared\n', out.getvalue())
109@@ -98,6 +101,7 @@
110 self.fs.create(path, "")
111 self.fs.set_node_id(path, "node_id")
112 # helper function, pylint: disable-msg=C0111
113+
114 def fake_create_share(node_id, user, name, access_level, marker, path):
115 self.main.vm.handle_AQ_CREATE_SHARE_OK(share_id='share_id',
116 marker=marker)
117@@ -110,6 +114,7 @@
118 "path=%s\n" % path.decode('utf-8')
119 d = self.tool.list_shared()
120 d.addCallback(lambda result: show_shared(result, out))
121+
122 def check(result):
123 """check the output"""
124 self.assertEqual(out.getvalue(), expected)
125@@ -166,6 +171,7 @@
126 stat: %(stat)s
127 """
128 # the callback, pylint: disable-msg=C0111
129+
130 def callback(result):
131 if encoding is not None:
132 result.update(dict(path_info=path))
133@@ -176,6 +182,7 @@
134 value = expected % result
135 self.assertEqual(out.getvalue(), value)
136 # helper callback, pylint: disable-msg=C0111
137+
138 def show(result):
139 show_path_info(result, path, out)
140 return result
141@@ -191,6 +198,7 @@
142 d.addCallback(lambda _: self.tool.get_current_downloads())
143 d.addCallback(lambda result: show_downloads(result, out))
144 expected = u'Current uploads: 0\nCurrent downloads: 0\n'
145+
146 def check(result):
147 """check the output"""
148 self.assertEqual(out.getvalue(), expected)
149@@ -241,6 +249,7 @@
150 ]
151 d = self.tool.get_status()
152 d.addCallback(lambda result: show_state(result, out))
153+
154 def check(result):
155 """check the output"""
156 info = [x.strip() for x in out.getvalue().split("\n") if x.strip()]
157@@ -274,7 +283,7 @@
158 self.action_q.queue.waiting.extend([cmd1, cmd2])
159
160 out = StringIO()
161- expected = (
162+ expected = (
163 " FakeCommand(running=True, share_id='', "
164 "node_id='node1', path='foo', other='')\n"
165 " FakeCommand(running=False, share_id='', "
166@@ -294,7 +303,7 @@
167 self.action_q.queue.waiting.extend([cmd1, cmd2])
168
169 out = StringIO()
170- expected = (
171+ expected = (
172 "Warning: this option is deprecated! Use '--waiting' instead\n"
173 " FakeCommand(running=True, share_id='', node_id='node1', "
174 "path='p', other='')\n"
175@@ -344,6 +353,7 @@
176 out = StringIO()
177 d = self.tool.get_folders()
178 d.addCallback(lambda result: show_folders(result, out))
179+
180 def check(result):
181 """check the output"""
182 self.assertEqual('No folders\n', out.getvalue())
183@@ -354,14 +364,14 @@
184 def test_show_folders_subscribed(self):
185 """Test the output of --list-folders."""
186 out = StringIO()
187- path = u'ñoño'.encode('utf-8')
188- suggested_path = os.path.join("~", u'ñoño')
189+ suggested_path = u"~/ñoño"
190+ path = get_udf_path(suggested_path)
191
192 udf = UDF("folder_id", "node_id", suggested_path, path,
193 subscribed=True)
194 yield self.main.vm.add_udf(udf)
195 expected = u"Folder list:\n id=folder_id subscribed=True " + \
196- u"path=\xf1o\xf1o\n"
197+ u"path=%s\n" % path.decode('utf-8')
198 result = yield self.tool.get_folders()
199 show_folders(result, out)
200 self.assertEqual(out.getvalue(), expected)
201
202=== modified file 'tests/syncdaemon/test_interaction_interfaces.py'
203--- tests/syncdaemon/test_interaction_interfaces.py 2011-12-12 19:32:25 +0000
204+++ tests/syncdaemon/test_interaction_interfaces.py 2012-01-12 14:04:25 +0000
205@@ -2158,6 +2158,11 @@
206
207 self.assertEqual(self.events, [('SYS_USER_DISCONNECT', {})])
208
209+ def test_get_homedir(self):
210+ """Test the get_homedir method."""
211+ result = self.sd_obj.get_homedir()
212+ self.assertEqual(self.main.get_homedir().decode('utf-8'), result)
213+
214 def test_get_rootdir(self):
215 """Test the get_rootdir method."""
216 result = self.sd_obj.get_rootdir()
217
218=== modified file 'tests/syncdaemon/test_main.py'
219--- tests/syncdaemon/test_main.py 2011-11-09 20:03:15 +0000
220+++ tests/syncdaemon/test_main.py 2012-01-12 14:04:25 +0000
221@@ -262,6 +262,12 @@
222 main = self.build_main()
223 self.assertNotIn(main.status_listener, self._get_listeners(main))
224
225+ def test_get_homedir(self):
226+ """The get_homedir returns the root dir."""
227+ expected = expand_user('~')
228+ main = self.build_main()
229+ self.assertEqual(main.get_homedir(), expected)
230+
231 def test_get_rootdir(self):
232 """The get_rootdir returns the root dir."""
233 expected = expand_user(os.path.join('~', 'Ubuntu Test One'))
234
235=== modified file 'tests/syncdaemon/test_vm_helper.py'
236--- tests/syncdaemon/test_vm_helper.py 2011-11-09 20:03:15 +0000
237+++ tests/syncdaemon/test_vm_helper.py 2012-01-12 14:04:25 +0000
238@@ -93,6 +93,14 @@
239 os_helper.make_dir(dest_path)
240 self.assertFalse(create_shares_link(source_path, dest_path))
241
242+ def test_create_shares_link_existing_destiny_with_lnk_extension(self):
243+ """Add the lnk extension to the end of the file like windows needs."""
244+ base = self.mktemp("test_create_shares_link_exists")
245+ source_path = os.path.join(base, "source")
246+ dest_path = os.path.join(base, "dest.lnk")
247+ os_helper.make_dir(dest_path)
248+ self.assertFalse(create_shares_link(source_path, dest_path))
249+
250 def test_create_shares_link_makes_the_link(self):
251 """create_shares_link makes the link as expected."""
252 base = self.mktemp("test_create_shares_link_makes_the_link")
253@@ -111,6 +119,15 @@
254 self.assertTrue(create_shares_link(source_path, dest_path))
255 self.assertFalse(create_shares_link(source_path, dest_path))
256
257+ def test_create_shares_link_existing_source_with_lnk_extension(self):
258+ """Add the lnk extension to the end of the file like windows needs."""
259+ base = self.mktemp("test_create_shares_link_makes_the_link")
260+ source_path = os.path.join(base, "source")
261+ dest_path = os.path.join(base, "dest.lnk")
262+ os_helper.make_dir(source_path)
263+ self.assertTrue(create_shares_link(source_path, dest_path))
264+ self.assertFalse(create_shares_link(source_path, dest_path))
265+
266
267 class GetShareDirNameTests(BaseVolumeManagerTests):
268
269
270=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
271--- ubuntuone/platform/linux/dbus_interface.py 2011-10-21 21:01:56 +0000
272+++ ubuntuone/platform/linux/dbus_interface.py 2012-01-12 14:04:25 +0000
273@@ -287,6 +287,12 @@
274
275 @dbus.service.method(DBUS_IFACE_SYNC_NAME,
276 in_signature='', out_signature='s')
277+ def get_homedir(self):
278+ """Return the home dir."""
279+ return self.service.sync.get_homedir()
280+
281+ @dbus.service.method(DBUS_IFACE_SYNC_NAME,
282+ in_signature='', out_signature='s')
283 def get_rootdir(self):
284 """Return the root dir/mount point."""
285 return self.service.sync.get_rootdir()
286
287=== modified file 'ubuntuone/platform/tools/__init__.py'
288--- ubuntuone/platform/tools/__init__.py 2011-11-12 17:09:09 +0000
289+++ ubuntuone/platform/tools/__init__.py 2012-01-12 14:04:25 +0000
290@@ -651,6 +651,11 @@
291 return self.proxy.call_method('file_system', 'get_dirty_nodes')
292
293 @log_call(logger.debug)
294+ def get_home_dir(self):
295+ """Return the home directory."""
296+ return self.proxy.call_method('sync_daemon', 'get_homedir')
297+
298+ @log_call(logger.debug)
299 def get_root_dir(self):
300 """Return the root directory."""
301 return self.proxy.call_method('sync_daemon', 'get_rootdir')
302
303=== modified file 'ubuntuone/platform/windows/ipc.py'
304--- ubuntuone/platform/windows/ipc.py 2011-10-25 02:24:29 +0000
305+++ ubuntuone/platform/windows/ipc.py 2012-01-12 14:04:25 +0000
306@@ -372,6 +372,7 @@
307 remote_calls = [
308 'connect',
309 'disconnect',
310+ 'get_homedir',
311 'get_rootdir',
312 'get_sharesdir',
313 'get_sharesdir_link',
314@@ -393,6 +394,10 @@
315 """Disconnect from the server."""
316 self.service.sync.disconnect()
317
318+ def get_homedir(self):
319+ """Return the home dir/mount point."""
320+ return self.service.sync.get_homedir()
321+
322 def get_rootdir(self):
323 """Return the root dir/mount point."""
324 return self.service.sync.get_rootdir()
325@@ -647,7 +652,6 @@
326
327 signal_mapping = {}
328
329-
330 def get_throttling_limits(self):
331 """Get the read/write limit from AQ and return a dict.
332
333
334=== modified file 'ubuntuone/platform/windows/ipc_client.py'
335--- ubuntuone/platform/windows/ipc_client.py 2011-11-02 16:37:55 +0000
336+++ ubuntuone/platform/windows/ipc_client.py 2012-01-12 14:04:25 +0000
337@@ -264,6 +264,10 @@
338 """Disconnect from the server."""
339
340 @remote
341+ def get_homedir(self):
342+ """Return the home dir/mount point."""
343+
344+ @remote
345 def get_rootdir(self):
346 """Return the root dir/mount point."""
347
348
349=== modified file 'ubuntuone/platform/windows/os_helper.py'
350--- ubuntuone/platform/windows/os_helper.py 2011-12-29 12:16:21 +0000
351+++ ubuntuone/platform/windows/os_helper.py 2012-01-12 14:04:25 +0000
352@@ -60,6 +60,10 @@
353 WinWorldSid,
354 )
355
356+from comtypes import shelllink
357+from comtypes.client import CreateObject
358+from comtypes.persist import IPersistFile
359+
360 # ugly trick to stop pylint for complaining about
361 # WindowsError on Linux
362 if sys.platform != 'win32':
363@@ -564,7 +568,7 @@
364 @windowspath()
365 def path_exists(path):
366 """Return if the path exists."""
367- return os.path.exists(path)
368+ return os.path.exists(path) or native_is_link(path)
369
370
371 @windowspath()
372@@ -638,16 +642,12 @@
373 destination = destination.replace(LONG_PATH_PREFIX, u'')
374 target = target.replace(LONG_PATH_PREFIX, u'')
375
376- shell_script = Dispatch('WScript.Shell')
377 try:
378- shortcut = shell_script.CreateShortCut(destination)
379- shortcut.Targetpath = target
380- shortcut.save()
381- except AttributeError:
382- # This try-except is required at least for the current implementation
383- # to allow the application to run even when the paths has unicode chars
384- logger.exception('Link couldn\'t be created for '
385- 'destination %r:', destination)
386+ shortcut = CreateObject(shelllink.ShellLink)
387+ shortcut.SetPath(target)
388+ shortcut.SetWorkingDirectory(target)
389+ pf = shortcut.QueryInterface(IPersistFile)
390+ pf.Save(destination, True)
391 except:
392 logger.exception('make_link could not be completed for target %r, '
393 'destination %r:', target, destination)
394@@ -658,17 +658,30 @@
395 @windowspath()
396 def read_link(path):
397 """Read the destination of a link."""
398+ # THIS SHOULD BE FIXED IN ORDER TO SUPPORT THE PROPER API
399+ # The workaround to support unicode paths was to use: WorkingDirectory,
400+ # because TargetPath or anything related was returning malformed paths.
401+ # The bug associated to this issue is: #907336
402+ # https://bugs.launchpad.net/ubuntuone-client/+bug/907336
403 if not path.endswith(u'.lnk'):
404 path += u'.lnk'
405- shell_script = Dispatch('WScript.Shell')
406- shortcut = shell_script.CreateShortCut(path)
407- result = get_syncdaemon_valid_path(LONG_PATH_PREFIX + shortcut.Targetpath)
408+ shortcut = CreateObject(shelllink.ShellLink)
409+ pf = shortcut.QueryInterface(IPersistFile)
410+ pf.Load(path, True)
411+ target_path = shortcut.GetWorkingDirectory().encode('utf-8')
412+ target_path = target_path.decode('utf-8')
413+ result = get_syncdaemon_valid_path(LONG_PATH_PREFIX + target_path)
414 return result
415
416
417 @windowspath()
418 def is_link(path):
419 """Returns if a path is a link or not."""
420+ return native_is_link(path)
421+
422+
423+def native_is_link(path):
424+ """Check if a file is a link, using native paths."""
425 if not path.endswith('.lnk'):
426 path += '.lnk'
427 return os.path.exists(path)
428
429=== modified file 'ubuntuone/syncdaemon/interaction_interfaces.py'
430--- ubuntuone/syncdaemon/interaction_interfaces.py 2011-12-06 20:23:14 +0000
431+++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-01-12 14:04:25 +0000
432@@ -1243,6 +1243,11 @@
433 self.main.event_q.push('SYS_USER_DISCONNECT')
434
435 @log_call(logger.debug)
436+ def get_homedir(self):
437+ """Return the home dir point."""
438+ return self.main.get_homedir().decode('utf-8')
439+
440+ @log_call(logger.debug)
441 def get_rootdir(self):
442 """Return the root dir/mount point."""
443 return self.main.get_rootdir().decode('utf-8')
444
445=== modified file 'ubuntuone/syncdaemon/main.py'
446--- ubuntuone/syncdaemon/main.py 2011-10-21 13:40:09 +0000
447+++ ubuntuone/syncdaemon/main.py 2012-01-12 14:04:25 +0000
448@@ -21,7 +21,7 @@
449
450 from twisted.internet import defer, reactor, task
451
452-from ubuntu_sso.xdg_base_directory import native_path
453+from ubuntu_sso.xdg_base_directory import native_path, xdg_home
454 from ubuntuone.syncdaemon import (
455 action_queue,
456 config,
457@@ -249,6 +249,10 @@
458 """Do the server rescan."""
459 return self.vm.server_rescan()
460
461+ def get_homedir(self):
462+ """Return the home dir point."""
463+ return xdg_home
464+
465 def get_rootdir(self):
466 """Return the base dir/mount point."""
467 return self.root_dir

Subscribers

People subscribed via source and target branches