Re: [PATCH] Don't set r/o permissions when copying from r/o locations



Am Freitag, den 10.03.2006, 10:37 +0100 schrieb Alexander Larsson:
> On Thu, 2006-03-09 at 22:39 +0100, Christian Neumair wrote:
> > The attached patch ensures that CDs are copied with r/w permissions by
> > passing GNOME_VFS_XFER_TARGET_DEFAULT_PERMS to the Xfer operation if one
> > of the source URIs is on a CD-ROM, or another read-only location. This
> > has to wait until after the code freeze, and fixes bug 167102 [1].
> > 
> > [1] http://bugzilla.gnome.org/show_bug.cgi?id=167102#
> 
> Take a look at gnome_vfs_volume_monitor_get_volume_for_path(). It'll
> help your patch a lot.

Whoho, thanks!

Proposed nautilus, gnome-vfs and hal patches attached. CCing David.
Notably the HAL semantics allow us to use new API without depending on a
nev version :).

-- 
Christian Neumair <chris gnome-de org>
Index: libgnomevfs/gnome-vfs-hal-mounts.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-hal-mounts.c,v
retrieving revision 1.28
diff -u -p -r1.28 gnome-vfs-hal-mounts.c
--- libgnomevfs/gnome-vfs-hal-mounts.c	2 Mar 2006 17:39:23 -0000	1.28
+++ libgnomevfs/gnome-vfs-hal-mounts.c	10 Mar 2006 17:31:49 -0000
@@ -1028,7 +1028,9 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 				libhal_volume_get_mount_point (hal_volume));
 		}
 		vol->priv->filesystem_type = g_strdup (libhal_volume_get_fstype (hal_volume));
-		vol->priv->is_read_only = FALSE;
+		vol->priv->is_read_only = libhal_device_get_property_bool (volume_monitor_daemon->hal_ctx,
+									   libhal_volume_get_udi (hal_volume),
+									   "volume.is_read_only", NULL);
 		vol->priv->is_mounted = TRUE;
 		
 		vol->priv->device_type = _hal_get_gnome_vfs_device_type (hal_drive);
Index: doc/spec/hal-spec.xml.in
===================================================================
RCS file: /cvs/hal/hal/doc/spec/hal-spec.xml.in,v
retrieving revision 1.68
diff -u -p -r1.68 hal-spec.xml.in
--- doc/spec/hal-spec.xml.in	8 Mar 2006 05:15:47 -0000	1.68
+++ doc/spec/hal-spec.xml.in	10 Mar 2006 17:06:28 -0000
@@ -2525,6 +2525,14 @@
               <entry>This property is TRUE if and only if the volume is mounted</entry>
             </row>
             <row>
+              <entry><literal>volume.is_mounted_read_only</literal> (bool)</entry>
+              <entry></entry>
+              <entry>Yes</entry>
+              <entry>This property is TRUE if and only if the volume is mounted and
+              the volume's file-system is read-only.
+              </entry>
+            </row>
+            <row>
               <entry><literal>volume.mount_point</literal> (string)</entry>
               <entry>example: /media/compact_flash1  </entry>
               <entry>Yes (is blank only when volume.is_mounted is FALSE)</entry>
Index: hald/linux2/blockdev.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/blockdev.c,v
retrieving revision 1.38
diff -u -p -r1.38 blockdev.c
--- hald/linux2/blockdev.c	24 Feb 2006 04:29:06 -0000	1.38
+++ hald/linux2/blockdev.c	10 Mar 2006 17:06:31 -0000
@@ -228,9 +228,13 @@ blockdev_refresh_mount_state (HalDevice 
 				/* found entry for this device in /proc/mounts */
 				device_property_atomic_update_begin ();
 				hal_device_property_set_bool (dev, "volume.is_mounted", TRUE);
+				hal_device_property_set_bool (dev, "volume.is_mounted_read_only",
+							      hasmntopt (&mnt, MNTOPT_RO) ? TRUE : FALSE);
 				hal_device_property_set_string (dev, "volume.mount_point", mnt.mnt_dir);
 				device_property_atomic_update_end ();
-				HAL_INFO (("  set %s to be mounted at %s", hal_device_get_udi (dev), mnt.mnt_dir));
+				HAL_INFO (("  set %s to be mounted at %s (%s)",
+					   hal_device_get_udi (dev), mnt.mnt_dir,
+					   hasmntopt (&mnt, MNTOPT_RO) ? "ro" : "rw"));
 				volumes = g_slist_delete_link (volumes, volume);
 				break;
 			}
@@ -247,6 +251,7 @@ blockdev_refresh_mount_state (HalDevice 
 		mount_point = g_strdup (hal_device_property_get_string (dev, "volume.mount_point"));
 		device_property_atomic_update_begin ();
 		hal_device_property_set_bool (dev, "volume.is_mounted", FALSE);
+		hal_device_property_set_bool (dev, "volume.is_mounted_read_only", FALSE);
 		hal_device_property_set_string (dev, "volume.mount_point", "");
 		device_property_atomic_update_end ();
 		HAL_INFO (("set %s to unmounted", hal_device_get_udi (dev)));
Index: libhal-storage/libhal-storage.c
===================================================================
RCS file: /cvs/hal/hal/libhal-storage/libhal-storage.c,v
retrieving revision 1.33
diff -u -p -r1.33 libhal-storage.c
--- libhal-storage/libhal-storage.c	25 Feb 2006 20:38:23 -0000	1.33
+++ libhal-storage/libhal-storage.c	10 Mar 2006 17:06:35 -0000
@@ -722,6 +722,7 @@ struct LibHalVolume_s {
 	char *device_file;
 	char *volume_label; /* may be NULL, is never "" */
 	dbus_bool_t is_mounted;
+	dbus_bool_t is_mounted_read_only; /* TRUE iff is_mounted and r/o fs */
 	char *mount_point;  /* NULL iff !is_mounted */
 	char *fstype;       /* NULL iff !is_mounted or unknown */
 	char *fsversion;
@@ -1108,6 +1109,7 @@ libhal_volume_from_udi (LibHalContext *h
 		LIBHAL_PROP_EXTRACT_STRING ("volume.fstype",             vol->fstype);
 		LIBHAL_PROP_EXTRACT_STRING ("volume.fsversion",             vol->fsversion);
 		LIBHAL_PROP_EXTRACT_BOOL   ("volume.is_mounted",         vol->is_mounted);
+		LIBHAL_PROP_EXTRACT_BOOL   ("volume.is_mounted_read_only", vol->is_mounted_read_only);
 		LIBHAL_PROP_EXTRACT_STRING ("volume.fsusage",            vol_fsusage_textual);
 		LIBHAL_PROP_EXTRACT_STRING ("volume.uuid",               vol->uuid);
 
@@ -1453,6 +1455,12 @@ libhal_volume_is_mounted (LibHalVolume *
 }
 
 dbus_bool_t 
+libhal_volume_is_mounted_read_only (LibHalVolume *volume)
+{
+	return volume->is_mounted_read_only;
+}
+
+dbus_bool_t 
 libhal_volume_is_partition (LibHalVolume *volume)
 {
 	return volume->is_partition;
Index: libhal-storage/libhal-storage.h
===================================================================
RCS file: /cvs/hal/hal/libhal-storage/libhal-storage.h,v
retrieving revision 1.18
diff -u -p -r1.18 libhal-storage.h
--- libhal-storage/libhal-storage.h	25 Feb 2006 20:38:23 -0000	1.18
+++ libhal-storage/libhal-storage.h	10 Mar 2006 17:06:36 -0000
@@ -281,6 +281,7 @@ const char          *libhal_volume_get_f
 const char          *libhal_volume_get_fsversion                 (LibHalVolume     *volume);
 LibHalVolumeUsage    libhal_volume_get_fsusage                   (LibHalVolume     *volume);
 dbus_bool_t          libhal_volume_is_mounted                    (LibHalVolume     *volume);
+dbus_bool_t          libhal_volume_is_mounted_read_only          (LibHalVolume     *volume);
 dbus_bool_t          libhal_volume_is_partition                  (LibHalVolume     *volume);
 dbus_bool_t          libhal_volume_is_disc                       (LibHalVolume     *volume);
 unsigned int         libhal_volume_get_partition_number          (LibHalVolume     *volume);
Index: libnautilus-private/nautilus-file-operations.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-operations.c,v
retrieving revision 1.206
diff -u -p -r1.206 nautilus-file-operations.c
--- libnautilus-private/nautilus-file-operations.c	16 Feb 2006 23:58:03 -0000	1.206
+++ libnautilus-private/nautilus-file-operations.c	10 Mar 2006 17:29:11 -0000
@@ -51,6 +51,8 @@
 #include <libgnomevfs/gnome-vfs-result.h>
 #include <libgnomevfs/gnome-vfs-uri.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-volume.h>
+#include <libgnomevfs/gnome-vfs-volume-monitor.h>
 #include "nautilus-file-changes-queue.h"
 #include "nautilus-file-private.h"
 #include "nautilus-desktop-icon-file.h"
@@ -1881,6 +1883,7 @@ nautilus_file_operations_copy_move (cons
 	gboolean target_is_mapping;
 	gboolean have_nonmapping_source;
 	gboolean have_nonlocal_source;
+	gboolean have_readonly_source;
 	
 	IconPositionIterator *icon_position_iterator;
 
@@ -1914,6 +1917,7 @@ nautilus_file_operations_copy_move (cons
 	target_uri_list = NULL;
 	have_nonlocal_source = FALSE;
 	have_nonmapping_source = FALSE;
+	have_readonly_source = FALSE;
 	duplicate = copy_action != GDK_ACTION_MOVE;
 	for (p = item_uris; p != NULL; p = p->next) {
 		/* Filter out special Nautilus link files */
@@ -1938,7 +1942,31 @@ nautilus_file_operations_copy_move (cons
 		if (strcmp (source_uri->method_string, "burn") != 0) {
 			have_nonmapping_source = TRUE;
 		}
-			
+
+		if (!have_readonly_source) {
+			GnomeVFSVolume *volume;
+			char *text_uri, *path;
+
+			text_uri = gnome_vfs_uri_to_string (source_uri, GNOME_VFS_URI_HIDE_NONE);
+
+			path = gnome_vfs_get_local_path_from_uri (text_uri);
+
+			volume = NULL;
+			if (path != NULL) {
+				/* TODO should we resolve symlinks ourselves, or should
+				 * gnome_vfs_volume_monitor_get_volume_for_path use lstat? */
+				volume = gnome_vfs_volume_monitor_get_volume_for_path (gnome_vfs_get_volume_monitor (), path);
+			}
+
+			if (volume != NULL && gnome_vfs_volume_is_read_only (volume)) {
+				have_readonly_source = TRUE;
+			}
+
+			gnome_vfs_volume_unref (volume);
+			g_free (path);
+			g_free (text_uri);
+		}
+
 		/* Note: this could be null if we're e.g. copying the top level file of a web site */
 		source_dir_uri = gnome_vfs_uri_get_parent (source_uri);
 		target_uri = NULL;
@@ -1994,6 +2022,10 @@ nautilus_file_operations_copy_move (cons
 		 * for target files.
 		 */
 		move_options |= GNOME_VFS_XFER_USE_UNIQUE_NAMES;
+	}
+
+	if (have_readonly_source) {
+		move_options |= GNOME_VFS_XFER_TARGET_DEFAULT_PERMS;
 	}
 
 	/* List may be NULL if we filtered all items out */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]