Midnight commander mount desktop shortcuts



Using gmc (CVS of 1999/04/21), recreate desktop shortcuts fails for
me because the name of the link in the .gnome-desktop directory is
x_basename(device_name). Since there may be several NFS mounts
with the same basename (e.g. henry:/disk10/prw and henry:/disk13/prw
in my case), the names conflict and the second link cannot be created.
I used this patch. Note that make_safe_filename() creates a valid
filename assuming that all characters found in the device name
are also valid as a filename with the exception of /. In this case
it uses a web-style escape code (%2f).



Peter Wainwright
Home: prw@wainpr.demon.co.uk   Work: peter.wainwright@nrpb.org.uk
http://www.wainpr.demon.co.uk
Visit the Opera Exchange Homepage at http://www.treda.co.uk/opex/
diff -U4 -r mc-old/gnome/gmount.c mc/gnome/gmount.c
--- mc-old/gnome/gmount.c	Fri Apr 16 23:26:21 1999
+++ mc/gnome/gmount.c	Thu Apr 22 22:10:00 1999
@@ -355,8 +355,9 @@
 	for (l = list; l; l = l->next) {
 		devname_info_t *dit = l->data;
 		char *dev_name;
 		char *short_dev_name;
+		char *safe_dev_name;
 		char *format;
 		char *icon;
 		int count;
 		char buffer[128];
@@ -364,8 +365,9 @@
 		gboolean ejectable;
 
 		dev_name = dit->devname;
 		short_dev_name = x_basename (dev_name);
+		safe_dev_name = make_safe_filename (dev_name);
 
 		release_format = FALSE;
 		ejectable = FALSE;
 		
@@ -408,9 +410,10 @@
 		}
 
 		/* Create the actual link */
 
-		create_device_link (dit->mount_point, short_dev_name, buffer, icon, ejectable);
+		create_device_link (dit->mount_point, safe_dev_name, buffer, icon, ejectable);
+		g_free (safe_dev_name);
 
 		g_free (dit->devname);
 		g_free (dit->mount_point);
 		g_free (dit);
diff -U4 -r mc-old/src/util.c mc/src/util.c
--- mc-old/src/util.c	Wed Apr  7 14:05:11 1999
+++ mc/src/util.c	Thu Apr 22 22:25:40 1999
@@ -664,8 +664,27 @@
     char  *where;
     return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
 }
 
+char *make_safe_filename (char *s)
+{
+  char *f, *ip, *op;
+  int n = 0;
+  for (ip = s; *ip; ip++)
+    if (*ip == '/' || *ip == '%') n++;
+  f = g_malloc (strlen(s) + 2*n + 1);
+  for (ip = s, op = f; *ip; ip++, op++) {
+    if (*ip == '/' || *ip == '%') {
+      *op++ = '%';
+      sprintf(op, "%02x", (unsigned char)*ip);
+      op++;
+    }
+    else *op = *ip;
+  }
+  *op++ = '\0';
+  return f;
+}
+
 void my_putenv (char *name, char *data)
 {
     char *full;
 
diff -U4 -r mc-old/src/util.h mc/src/util.h
--- mc-old/src/util.h	Mon Mar 29 09:37:57 1999
+++ mc/src/util.h	Thu Apr 22 22:10:18 1999
@@ -36,8 +36,9 @@
 char *diff_two_paths (char *first, char *second);
 int  set_nonblocking (int fd);
 
 char *x_basename (char *s);
+char *make_safe_filename (char *s);
 char *g_readlink (char *path);
 
 extern int align_extensions;
 


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