Merge lp:~ralsina/ubuntuone-control-panel/check_subscribe_errors into lp:ubuntuone-control-panel

Proposed by Roberto Alsina on 2012-08-06
Status: Merged
Approved by: Alejandro J. Cura on 2012-08-07
Approved revision: 343
Merged at revision: 339
Proposed branch: lp:~ralsina/ubuntuone-control-panel/check_subscribe_errors
Merge into: lp:ubuntuone-control-panel
Diff against target: 124 lines (+61/-4)
3 files modified
ubuntuone/controlpanel/gui/__init__.py (+3/-0)
ubuntuone/controlpanel/gui/qt/folders.py (+14/-4)
ubuntuone/controlpanel/gui/qt/tests/test_folders.py (+44/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/check_subscribe_errors
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2012-08-07
Brian Curtin (community) Approve on 2012-08-06
Eric Casteleijn (community) 2012-08-06 Approve on 2012-08-06
Review via email: mp+118420@code.launchpad.net

Commit Message

 - Give an error if the user subscribes a UDF and the local path is not a folder (Fixes LP:1033488)

Description of the Change

Text approved by Robert Grant.

To test IRL, create a UDF, then unsubscribe from it, remove it from disk, and create a file in its place.
When you try to subscribe to it again, it will give an error.

For another test: create a UDF, unsubscribe it, remove it from disk, and create a valid symlink pointing to a folder. When you try to subscribe to it again, it will give an error.

To post a comment you must log in.
341. By Roberto Alsina on 2012-08-06

untypo

Eric Casteleijn (thisfred) wrote :

+1 with s/already exists in your device/already exists on your device/

review: Approve
review: Approve
Alejandro J. Cura (alecu) wrote :

When the symlink points to a folder, it gets wrongly detected as a folder, and then an IPCError occurs.

review: Needs Fixing
Alejandro J. Cura (alecu) wrote :

Just to be clear, a symlink pointing to a folder is not possible right now within syncdaemon, because that folder could be in a different filesystem, or on a removable drive, etc, etc.

342. By Roberto Alsina on 2012-08-07

add test for when you are subscribing to a folder that exists as a valid symlink pointing to a folder

343. By Roberto Alsina on 2012-08-07

handle case when you are subscribing to a folder that exists as a valid symlink pointing to a folder

Roberto Alsina (ralsina) wrote :

Added test and handler for the case where the folder the user tries to subscribe is a symlink that points to a real folder.

I think this covers all possible combinations ;-)

Alejandro J. Cura (alecu) wrote :

Works exactly as described!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/__init__.py'
2--- ubuntuone/controlpanel/gui/__init__.py 2012-05-29 14:36:17 +0000
3+++ ubuntuone/controlpanel/gui/__init__.py 2012-08-07 01:39:17 +0000
4@@ -140,6 +140,9 @@
5 'with your local folder "%(folder_path)s" when '
6 'subscribing.\nDo you want to subscribe to this '
7 'cloud folder?')
8+FOLDER_EXISTS_AS_FILE = _('Unable to subscribe because '
9+ '"%(folder_path)s" already exists on your '
10+ 'device and is not a folder.')
11 FOLDERS_MANAGE_LABEL = _('Go to the web for public and private sharing '
12 'options')
13 FOLDERS_TITLE = _('Select which folders from your cloud you want to sync with '
14
15=== modified file 'ubuntuone/controlpanel/gui/qt/folders.py'
16--- ubuntuone/controlpanel/gui/qt/folders.py 2012-06-04 16:25:39 +0000
17+++ ubuntuone/controlpanel/gui/qt/folders.py 2012-08-07 01:39:17 +0000
18@@ -26,6 +26,8 @@
19 from PyQt4 import QtGui, QtCore
20 from twisted.internet import defer
21
22+from ubuntuone.platform import is_link
23+
24 from ubuntuone.controlpanel.utils import default_folders
25 from ubuntuone.controlpanel.logger import setup_logging, log_call
26 from ubuntuone.controlpanel.gui import (
27@@ -38,6 +40,7 @@
28 FOLDERS_COLUMN_NAME,
29 FOLDERS_COLUMN_SYNC_LOCALLY,
30 FOLDERS_CONFIRM_MERGE,
31+ FOLDER_EXISTS_AS_FILE,
32 FOLDERS_MANAGE_LABEL,
33 GET_MORE_STORAGE,
34 humanize,
35@@ -328,16 +331,23 @@
36 os.path.exists(volume_path))
37 response = YES
38 if subscribed and os.path.exists(volume_path):
39- text = FOLDERS_CONFIRM_MERGE % {'folder_path': volume_path}
40- buttons = YES | NO | CANCEL
41- response = QtGui.QMessageBox.warning(self, '', text, buttons, YES)
42+ if os.path.isdir(volume_path) and not is_link(volume_path):
43+ text = FOLDERS_CONFIRM_MERGE % {'folder_path': volume_path}
44+ buttons = YES | NO | CANCEL
45+ response = QtGui.QMessageBox.warning(self, '', text, buttons,
46+ YES)
47+ else:
48+ text = FOLDER_EXISTS_AS_FILE % {'folder_path': volume_path}
49+ buttons = CLOSE
50+ QtGui.QMessageBox.warning(self, '', text, buttons)
51+ response = NO
52
53 self.is_processing = True
54
55 if response == YES:
56 # user accepted, merge the folder content
57 yield self.backend.change_volume_settings(volume_id,
58- {'subscribed': subscribed})
59+ {'subscribed': subscribed})
60 self.load()
61 else:
62 # restore old value
63
64=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_folders.py'
65--- ubuntuone/controlpanel/gui/qt/tests/test_folders.py 2012-06-22 14:42:29 +0000
66+++ ubuntuone/controlpanel/gui/qt/tests/test_folders.py 2012-08-07 01:39:17 +0000
67@@ -591,6 +591,8 @@
68 def test_confirm_dialog_if_path_exists(self):
69 """The confirmation dialog is correct."""
70 self.patch(gui.os.path, 'exists', lambda path: True)
71+ self.patch(gui.os.path, 'isdir', lambda path: True)
72+ self.patch(gui, 'is_link', lambda path: False)
73
74 # make sure the item is subscribed
75 self.ui.is_processing = True
76@@ -607,6 +609,48 @@
77 self.assertEqual(FakedDialog.kwargs, {})
78
79 @defer.inlineCallbacks
80+ def test_error_if_path_exists_as_file(self):
81+ """The error dialog is correct."""
82+ self.patch(gui.os.path, 'exists', lambda path: True)
83+ self.patch(gui.os.path, 'isdir', lambda path: False)
84+ self.patch(gui, 'is_link', lambda path: False)
85+
86+ # make sure the item is subscribed
87+ self.ui.is_processing = True
88+ self.set_item_checked()
89+ self.ui.is_processing = False
90+
91+ yield self.ui.on_folders_itemChanged(self.item)
92+
93+ volume_path = self.item.volume_path
94+ msg = gui.FOLDER_EXISTS_AS_FILE % {'folder_path': volume_path}
95+ buttons = gui.CLOSE
96+ self.assertEqual(FakedDialog.args,
97+ (self.ui, '', msg, buttons))
98+ self.assertEqual(FakedDialog.kwargs, {})
99+
100+ @defer.inlineCallbacks
101+ def test_error_if_path_exists_as_valid_link(self):
102+ """The error dialog is correct."""
103+ self.patch(gui.os.path, 'exists', lambda path: True)
104+ self.patch(gui.os.path, 'isdir', lambda path: True)
105+ self.patch(gui, 'is_link', lambda path: True)
106+
107+ # make sure the item is subscribed
108+ self.ui.is_processing = True
109+ self.set_item_checked()
110+ self.ui.is_processing = False
111+
112+ yield self.ui.on_folders_itemChanged(self.item)
113+
114+ volume_path = self.item.volume_path
115+ msg = gui.FOLDER_EXISTS_AS_FILE % {'folder_path': volume_path}
116+ buttons = gui.CLOSE
117+ self.assertEqual(FakedDialog.args,
118+ (self.ui, '', msg, buttons))
119+ self.assertEqual(FakedDialog.kwargs, {})
120+
121+ @defer.inlineCallbacks
122 def test_confirm_dialog_if_path_does_not_exist(self):
123 """The confirmation dialog is not created if not needed."""
124 self.patch(gui.os.path, 'exists', lambda path: False)

Subscribers

People subscribed via source and target branches