Hello community, here is the log from the commit of package nautilus-share checked in at Sun May 7 16:26:40 CEST 2006. -------- --- GNOME/nautilus-share/nautilus-share.changes 2006-02-22 01:56:55.000000000 +0100 +++ STABLE/nautilus-share/nautilus-share.changes 2006-05-03 23:42:01.000000000 +0200 @@ -1,0 +2,7 @@ +Wed May 3 23:39:33 CEST 2006 - federico@novell.com + +- Added nautilus-share-170212-restore-modified-permissions.diff to fix + https://bugzilla.novell.com/show_bug.cgi?id=170212. We now restore + the permissions of a folder when unsharing it. + +------------------------------------------------------------------- New: ---- nautilus-share-170212-restore-modified-permissions.diff ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ nautilus-share.spec ++++++ --- /var/tmp/diff_new_pack.bUzUlG/_old 2006-05-07 16:26:28.000000000 +0200 +++ /var/tmp/diff_new_pack.bUzUlG/_new 2006-05-07 16:26:28.000000000 +0200 @@ -13,7 +13,7 @@ Name: nautilus-share BuildRequires: eel-devel gnome-patch-translation gnutls-devel intltool libgnomeprintui-devel libwnck-devel mDNSResponder-devel nautilus-devel perl-XML-Parser update-desktop-files Version: 0.6.4 -Release: 17 +Release: 30 URL: http://gentoo.ovibes.net/nautilus-share/ Group: Productivity/Networking/Samba License: GPL @@ -22,6 +22,7 @@ Patch: %{name}-include.patch Patch1: nautilus-share-net-usershare.diff Patch2: nautilus-share-potfiles.patch +Patch3: nautilus-share-170212-restore-modified-permissions.diff Requires: gnome-icon-theme samba >= 3.0.21a-4.2 Autoreqprov: on BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -62,6 +63,7 @@ gnome-patch-translation-prepare %patch %patch1 -p0 +%patch3 -p1 # NOTE: You can ignore iter.* uninitialized warnings in nautilus-share.c: # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22197 gnome-patch-translation-update @@ -92,6 +94,10 @@ /opt/gnome/share/nautilus-share %changelog -n nautilus-share +* Wed May 03 2006 - federico@novell.com +- Added nautilus-share-170212-restore-modified-permissions.diff to fix + https://bugzilla.novell.com/show_bug.cgi?id=170212. We now restore + the permissions of a folder when unsharing it. * Wed Feb 22 2006 - federico@novell.com - Updated nautilus-share-net-usershare.diff to fix https://bugzilla.novell.com/show_bug.cgi?id=152552. Now we don't ++++++ nautilus-share-170212-restore-modified-permissions.diff ++++++ 2006-05-03 Federico Mena Quintero <federico@novell.com> Fix https://bugzilla.novell.com/show_bug.cgi?id=170212 - restore the permissions of folders when unsharing them if we had to modify them. * src/nautilus-share.c (save_changed_permissions): New function; creates a GKeyFile in ~/.gnome2/nautilus-share-modified-permissions to save a list of the folders for which we had to add permissions. (restore_saved_permissions): New function; the counterpart to restore_saved_permissions(). Restores the permissions of a directory. (confirm_sharing_permissions): Call save_changed_permissions() after chmod() succeeds. Return an enum rather than a boolean. (property_page_commit): Call restore_saved_permissions() if we are unsharing a folder, or if we failed to share the folder. Index: nautilus-share/src/nautilus-share.c =================================================================== RCS file: /cvsroot/nautilus-share/src/nautilus-share.c,v retrieving revision 1.17 diff -u -r1.17 nautilus-share.c --- nautilus-share/src/nautilus-share.c 22 Feb 2006 00:10:23 -0000 1.17 +++ nautilus-share/src/nautilus-share.c 3 May 2006 21:16:42 -0000 @@ -56,6 +56,7 @@ #include "shares.h" + static GObjectClass *parent_class; /* Structure to hold all the information for a share's property page. If @@ -252,7 +253,124 @@ gtk_widget_destroy (dialog); } -static gboolean +static char * +get_key_file_path (void) +{ + return g_build_filename (g_get_home_dir (), ".gnome2", "nautilus-share-modified-permissions", NULL); +} + +static void +save_key_file (const char *filename, GKeyFile *key_file) +{ + char *contents; + gsize length; + + /* NULL GError */ + contents = g_key_file_to_data (key_file, &length, NULL); + if (!contents) + return; + + /* NULL GError */ + g_file_set_contents (filename, contents, length, NULL); + + g_free (contents); +} + +static void +save_changed_permissions (const char *path, gboolean need_r, gboolean need_w, gboolean need_x) +{ + GKeyFile *key_file; + char *key_file_path; + + key_file = g_key_file_new (); + key_file_path = get_key_file_path (); + + /* NULL GError + * + * We don't check the return value of this. If the file doesn't exist, we'll + * simply want to create it. + */ + g_key_file_load_from_file (key_file, key_file_path, 0, NULL); + + g_key_file_set_boolean (key_file, path, "need_r", need_r); + g_key_file_set_boolean (key_file, path, "need_w", need_w); + g_key_file_set_boolean (key_file, path, "need_x", need_x); + + save_key_file (key_file_path, key_file); + + g_key_file_free (key_file); + g_free (key_file_path); +} + +static void +remove_permissions (const char *path, gboolean need_r, gboolean need_w, gboolean need_x) +{ + struct stat st; + mode_t new_mode; + + if (!need_r && !need_w && !need_x) + return; + + if (stat (path, &st) != 0) + return; + + new_mode = st.st_mode; + + if (need_r) + new_mode &= ~S_IROTH; + + if (need_w) + new_mode &= ~S_IWOTH; + + if (need_x) + new_mode &= ~S_IXOTH; + + /* Bleah, no error checking */ + chmod (path, new_mode); +} + +static void +restore_saved_permissions (const char *path) +{ + GKeyFile *key_file; + char *key_file_path; + + key_file = g_key_file_new (); + key_file_path = get_key_file_path (); + + if (!g_key_file_load_from_file (key_file, key_file_path, 0, NULL)) + goto out; + + if (g_key_file_has_group (key_file, path)) + { + gboolean need_r, need_w, need_x; + + /* NULL GError */ + need_r = g_key_file_get_boolean (key_file, path, "need_r", NULL); + need_w = g_key_file_get_boolean (key_file, path, "need_w", NULL); + need_x = g_key_file_get_boolean (key_file, path, "need_x", NULL); + + remove_permissions (path, need_r, need_w, need_x); + + /* NULL GError */ + g_key_file_remove_group (key_file, path, NULL); + + save_key_file (key_file_path, key_file); + } + + out: + + g_key_file_free (key_file); + g_free (key_file_path); +} + +typedef enum { + CONFIRM_CANCEL_OR_ERROR, + CONFIRM_NO_MODIFICATIONS, + CONFIRM_MODIFIED +} ConfirmPermissionsStatus; + +static ConfirmPermissionsStatus confirm_sharing_permissions (GtkWidget *widget, const char *path, gboolean is_shared, gboolean is_writable) { struct stat st; @@ -262,10 +380,10 @@ gboolean need_x; if (!is_shared) - return TRUE; + return CONFIRM_NO_MODIFICATIONS; if (stat (path, &st) != 0) - return TRUE; /* We'll just let "net usershare" give back an error if the file disappears */ + return CONFIRM_NO_MODIFICATIONS; /* We'll just let "net usershare" give back an error if the file disappears */ mode = st.st_mode; new_mode = mode; @@ -283,16 +401,23 @@ if (need_r || need_w || need_x) { if (!message_confirm_missing_permissions (widget, path, need_r, need_w, need_x)) - return FALSE; + return CONFIRM_CANCEL_OR_ERROR; if (chmod (path, new_mode) != 0) { error_when_changing_permissions (widget, path); - return FALSE; + return CONFIRM_CANCEL_OR_ERROR; } + + save_changed_permissions (path, need_r, need_w, need_x); + + return CONFIRM_MODIFIED; } + else + return CONFIRM_NO_MODIFICATIONS; - return TRUE; + g_assert_not_reached (); + return CONFIRM_CANCEL_OR_ERROR; } static gboolean @@ -300,6 +425,7 @@ { gboolean is_shared; ShareInfo share_info; + ConfirmPermissionsStatus status; GError *error; gboolean retval; @@ -310,7 +436,8 @@ share_info.comment = (char *) gtk_entry_get_text (GTK_ENTRY (page->entry_share_comment)); share_info.is_writable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page->checkbutton_share_rw_ro)); - if (!confirm_sharing_permissions (page->main, page->path, is_shared, share_info.is_writable)) + status = confirm_sharing_permissions (page->main, page->path, is_shared, share_info.is_writable); + if (status == CONFIRM_CANCEL_OR_ERROR) return FALSE; /* the user didn't want us to change his folder's permissions */ error = NULL; @@ -320,6 +447,10 @@ { property_page_set_error (page, error->message); g_error_free (error); + + /* Since the operation failed, we restore things to the way they were */ + if (status == CONFIRM_MODIFIED) + restore_saved_permissions (page->path); } else { @@ -327,6 +458,9 @@ nautilus_file_info_invalidate_extension_info (page->fileinfo); } + if (!is_shared) + restore_saved_permissions (page->path); + return retval; } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Remember to have fun...
participants (1)
-
root@suse.de