Merge lp:~ralsina/ubuntuone-client/fix_712674 into lp:ubuntuone-client

Proposed by Roberto Alsina
Status: Merged
Approved by: Natalia Bidart
Approved revision: 867
Merged at revision: 859
Proposed branch: lp:~ralsina/ubuntuone-client/fix_712674
Merge into: lp:ubuntuone-client
Diff against target: 102 lines (+42/-3)
3 files modified
nautilus/context-menu.c (+6/-3)
nautilus/ubuntuone-nautilus.h (+1/-0)
nautilus/utils.c (+35/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-client/fix_712674
Reviewer Review Type Date Requested Status
Roman Yepishev (community) fieldtest Approve
dobey (community) Approve
Review via email: mp+49332@code.launchpad.net

Commit message

Don't offer the "Publish" option in the context menu for files/folders that are being shared to the user, because it's not supported.

Description of the change

Adds a utility function to determine if a file or directory is inside a share, and uses that to modify the context menu so you can't try to publish those files/directories.

To fieldtest it, build it using these commands:

WARNING, this overwrites part of ubuntuone-client-gnome, you may need to reinstall it later

./autogen.sh
./configure --prefix=/usr
make
cd nautilus && sudo make install
pkill nautilus
nautilus nautilus ~/Ubuntu\ One/Shared\ With\ Me/

Then check the context menus, the "Ubuntu One->Publish" option should be disabled.
Check also in a subdirectory, with folders and files, and that the Publish option is enabled for contents outside the shares.

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

grrr. "Check also in a subdirectory, with folders and files, and that the Publish option is enabled for contents outside the shares."

Revision history for this message
Roman Yepishev (rye) wrote :

Fails to build ATM:

cc1: warnings being treated as errors
utils.c: In function ‘ubuntuone_is_folder_shares’:
utils.c:144:15: error: unused variable ‘f’

review: Needs Fixing (fieldtest)
861. By Roberto Alsina

Remove unused variable

862. By Roberto Alsina

Simpler function (thx chipaca)

863. By Roberto Alsina

use the right prefix, explain corner case

864. By Roberto Alsina

nicer name for placeholder. Traditions matter

Revision history for this message
dobey (dobey) wrote :

Please rename the function for this to something more than one character different from the _is_shared method. Documenting API is good, but so is having sane method names. :)

Also, please use --fixes=lp:712674 on at least one commit, so that the bug is linked and gets marked as fix committed when the branch lands.

Also, set a more descriptive commit message than "Fix bug ####" please. We don't need to put bug #s in commit messages, as bzr/launchpad have useful metadata for them that we should use.

review: Needs Fixing
865. By Roberto Alsina

Better function name

Revision history for this message
Roberto Alsina (ralsina) wrote :

> Please rename the function for this to something more than one character
> different from the _is_shared method. Documenting API is good, but so is
> having sane method names. :)

Done.

> Also, please use --fixes=lp:712674 on at least one commit, so that the bug is
> linked and gets marked as fix committed when the branch lands.
>
> Also, set a more descriptive commit message than "Fix bug ####" please. We
> don't need to put bug #s in commit messages, as bzr/launchpad have useful
> metadata for them that we should use.

I am used to a system where the link is done by just mentioning the bugs in the commit messages, sorry.

Fixed!

Revision history for this message
Roberto Alsina (ralsina) wrote :

> Fails to build ATM:
>
> cc1: warnings being treated as errors
> utils.c: In function ‘ubuntuone_is_folder_shares’:
> utils.c:144:15: error: unused variable ‘f’

Missed a line I should have deleted.
Fixed!

Revision history for this message
dobey (dobey) wrote :

77 + gchar buf[PATH_MAX + 1];
78 + gchar prefix[PATH_MAX + 1];
79 + g_snprintf(prefix,PATH_MAX,"%s/ubuntuone/shares/",g_get_user_data_dir());

This is just bad C. :)

You should use g_build_filename (); instead to do this. Also, don't fear the space key.

gchar * full_path = g_build_filename (g_get_uer_data_dir (), "ubuntuone", "shares", "", NULL);

And then g_free (full_path); before the return;

Also, can you change the is_shares variable in the code to be is_sharetome or something a little more descriptive and more than a single character different from is_shared as well?

90 + gchar *res = realpath(path, buf);
91 + if (g_str_has_prefix (res, prefix)) {
92 + is_shares = TRUE;
93 + }

This is also wrong here. The gchar *res needs to be declared at the beginning of the function. Also please call it real_path or resolved_path instead. And you should call realpath () with NULL as the second argument to use the return value. You should then g_free () the variable assigned to before returning from the function.

It also looks like there are maybe some spaces vs tabs issues in the spacing of the code, in the diff.
Also please do multi-line comments in the following style:

/*
 * Start of text
 */

review: Needs Fixing
Revision history for this message
Roberto Alsina (ralsina) wrote :

> 77 + gchar buf[PATH_MAX + 1];
> 78 + gchar prefix[PATH_MAX + 1];
> 79 +
> g_snprintf(prefix,PATH_MAX,"%s/ubuntuone/shares/",g_get_user_data_dir());
>
> This is just bad C. :)
>
> You should use g_build_filename (); instead to do this. Also, don't fear the
> space key.

Ok, didn't know g_build_filename.

>
> gchar * full_path = g_build_filename (g_get_uer_data_dir (), "ubuntuone",
> "shares", "", NULL);
>
> And then g_free (full_path); before the return;
>
> Also, can you change the is_shares variable in the code to be is_sharetome or
> something a little more descriptive and more than a single character different
> from is_shared as well?

Sure.

> 90 + gchar *res = realpath(path, buf);
> 91 + if (g_str_has_prefix (res, prefix)) {
> 92 + is_shares = TRUE;
> 93 + }
>
> This is also wrong here. The gchar *res needs to be declared at the beginning
> of the function.

Yes. C++ism :-) Fixed.

> Also please call it real_path or resolved_path instead. And
> you should call realpath () with NULL as the second argument to use the return
> value.
> You should then g_free () the variable assigned to before returning
> from the function.

No. It always returns a pointer to the resolved path, the only difference is that since I used buf the pointer points to somewhere inside buf instead of allocating it using malloc. At least that's what the manual says.

I'll change it because you say it's ugly, but it's not *wrong* ;-)

> It also looks like there are maybe some spaces vs tabs issues in the spacing
> of the code, in the diff.
> Also please do multi-line comments in the following style:

Ok, fixed.

> /*
> * Start of text
> */

Ok, fixed.

866. By Roberto Alsina

Fixes for dobey's 'Needs Fixing'

867. By Roberto Alsina

use g_free for string allocated with g_malloc

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Roman Yepishev (rye) wrote :

Looks great, no publishing in shares.

review: Approve (fieldtest)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/context-menu.c'
2--- nautilus/context-menu.c 2010-10-18 11:05:29 +0000
3+++ nautilus/context-menu.c 2011-02-11 15:30:10 +0000
4@@ -182,11 +182,11 @@
5 NautilusMenuItem *root_item, *menu_item, *urlitem;
6 gchar *path, *item, *homedir_path;
7 gboolean is_managed, is_root, is_udf, is_public, is_shared, is_pending;
8- gboolean is_inhome, is_dir, is_regular;
9+ gboolean is_shared_to_me, is_inhome, is_dir, is_regular;
10 MenuCallbackData *cb_data;
11
12 is_managed = is_root = is_udf = is_public = is_shared = is_pending = FALSE;
13- is_inhome = is_dir = is_regular = FALSE;
14+ is_shared_to_me = is_inhome = is_dir = is_regular = FALSE;
15
16 if (g_list_length (files) != 1)
17 return NULL;
18@@ -218,6 +218,9 @@
19 if (ubuntuone_is_folder_shared (uon, path))
20 is_shared = TRUE;
21
22+ if (ubuntuone_is_inside_shares (uon, path))
23+ is_shared_to_me = TRUE;
24+
25 is_dir = nautilus_file_info_is_directory (file);
26 is_regular = nautilus_file_info_get_file_type (file) == G_FILE_TYPE_REGULAR;
27
28@@ -351,7 +354,7 @@
29 /* public files */
30 menu_item = urlitem = NULL;
31
32- if (is_managed && is_regular) {
33+ if (!is_shared_to_me && is_managed && is_regular) {
34 if (is_public) {
35 urlitem = nautilus_menu_item_new ("ubuntuone-geturl",
36 _("Copy Web _Link"),
37
38=== modified file 'nautilus/ubuntuone-nautilus.h'
39--- nautilus/ubuntuone-nautilus.h 2010-10-18 11:05:29 +0000
40+++ nautilus/ubuntuone-nautilus.h 2011-02-11 15:30:10 +0000
41@@ -64,6 +64,7 @@
42
43 /* Utility functions */
44 gboolean ubuntuone_is_folder_shared (UbuntuOneNautilus *uon, const gchar *path);
45+gboolean ubuntuone_is_inside_shares (UbuntuOneNautilus *uon, const gchar *path);
46 gboolean ubuntuone_is_location_bar_enabled (void);
47
48 gboolean ubuntuone_check_shares_and_public_files (UbuntuOneNautilus *uon,
49
50=== modified file 'nautilus/utils.c'
51--- nautilus/utils.c 2010-10-18 11:05:29 +0000
52+++ nautilus/utils.c 2011-02-11 15:30:10 +0000
53@@ -19,7 +19,11 @@
54 *
55 */
56
57+#include <limits.h>
58+#include <stdlib.h>
59 #include <glib/gi18n.h>
60+#include <glib/gutils.h>
61+#include <glib/gfileutils.h>
62 #include <libnautilus-extension/nautilus-file-info.h>
63 #include <libsyncdaemon/libsyncdaemon.h>
64 #include "ubuntuone-nautilus.h"
65@@ -130,6 +134,37 @@
66 return is_shared;
67 }
68
69+/*
70+ * Similar to ubuntuone_is_folder_shared but it checks if the passed
71+ * folder is inside a folder shared TO the user.
72+ *
73+ * Added to fix bug #712674
74+ */
75+gboolean
76+ubuntuone_is_inside_shares (UbuntuOneNautilus *uon, const gchar *path)
77+{
78+ gboolean is_shared_to_me = FALSE;
79+ gchar *resolved_path;
80+ gchar *prefix = g_build_filename (g_get_user_data_dir (), "ubuntuone", "shares", G_DIR_SEPARATOR_S, NULL);
81+
82+ /*
83+ * Have to use realpath because path contains a symlink like
84+ * ~/Ubuntu One/Shared With Me -> ~/.local/share/ubuntuone/shares
85+ *
86+ * This also claims ~/Ubuntu One/Shared with Me/foo is
87+ * in a share even if it's not true. that's intentional since
88+ * those files are never uploaded, and thus it makes no sense
89+ * to publish them.
90+ */
91+ resolved_path = realpath(path, NULL);
92+ if (g_str_has_prefix (resolved_path, prefix)) {
93+ is_shared_to_me = TRUE;
94+ }
95+ free (resolved_path);
96+ g_free (prefix);
97+ return is_shared_to_me;
98+}
99+
100 gboolean
101 ubuntuone_is_location_bar_enabled (void)
102 {

Subscribers

People subscribed via source and target branches