Re: BonoboStreamFS content_type



On Tue, 20 Feb 2001, Dietmar Maurer wrote:
> 
> The patch stores the path to the file. I think this is a bad idea - what if
> someone
> renames the file during you have a handle to it? I would like a solution that
> 
> works without storing the file path.

Ok, I'v attached a patch which doesn't store the file path anymore. But
you have the same problem in bonobo-storage-fs.c for directories, where
you save the path for the directory.

Anyway, the patch adds the mime-type recognation also for
bonobo-storage-fs.c and fixes a nasty bug which let the last two directory
entries drop out of the directory list. 

May I commit?

Regards,

   Jens
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.978
diff -u -r1.978 ChangeLog
--- ChangeLog	2001/02/20 00:01:27	1.978
+++ ChangeLog	2001/02/20 13:30:09
@@ -1,3 +1,16 @@
+2001-02-20  Jens Finke <jens gnome org>
+
+	* storage-modules/bonobo-storage-fs.c (fs_get_info): Obtain mime
+	type for regular files.
+	(fs_list_contents): Obtain mime type for regular files, fixed
+	directory list creation bug.
+
+	* storage-modules/bonobo-stream-fs.c: Added private struct to hold
+	the mime type for this stream.
+	(fs_finalize): New function.
+	(bonobo_stream_fs_init): New function.
+	(bonobo_stream_create): Obtain mime type.
+	
 2001-02-19  Michael Meeks  <michael ximian com>
 
 	* doc/api/Makefile.am (scan): add bonobo-async,
Index: storage-modules/bonobo-storage-fs.c
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-storage-fs.c,v
retrieving revision 1.36
diff -u -r1.36 bonobo-storage-fs.c
--- storage-modules/bonobo-storage-fs.c	2001/02/08 23:37:46	1.36
+++ storage-modules/bonobo-storage-fs.c	2001/02/20 13:30:21
@@ -17,6 +17,7 @@
 #include <errno.h>
 #include <libgnome/gnome-defs.h>
 #include <libgnome/gnome-util.h>
+#include <libgnome/gnome-mime.h>
 #include <storage-modules/bonobo-storage-fs.h>
 #include <storage-modules/bonobo-stream-fs.h>
 #include <bonobo/bonobo-storage-plugin.h>
@@ -65,9 +66,11 @@
 	} else {
 		si->type = Bonobo_STORAGE_TYPE_REGULAR;
 		si->content_type = 
-			CORBA_string_dup ("application/octet-stream");
+			CORBA_string_dup (gnome_mime_type_of_file (full));
 	}
 
+	g_free (full);
+
 	return si;
 
  get_info_except:
@@ -194,7 +197,7 @@
 	struct stat st;
 	DIR *dir = NULL;
 	gint i, max, v, num_entries = 0;
-	gchar *full;
+	gchar *full = NULL;
 
 	if (mask & ~(Bonobo_FIELD_CONTENT_TYPE | Bonobo_FIELD_SIZE |
 		     Bonobo_FIELD_TYPE)) {
@@ -220,8 +223,10 @@
 		
 		if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
 		    (de->d_name[0] == '.' && de->d_name[1] == '.' 
-		     && de->d_name[2] == '\0'))
+		     && de->d_name[2] == '\0')) {
+			i--;
 			continue; /* Ignore . and .. */
+		}
 
 		buf [i].name = CORBA_string_dup (de->d_name);
 		buf [i].size = 0;
@@ -229,9 +234,8 @@
 
 		full = g_concat_dir_and_file (storage_fs->path, de->d_name);
 		v = stat (full, &st);
-		g_free (full);
 
-		if (v == -1) 
+		if (v == -1)
 			goto list_contents_except;
 
 		buf [i].size = st.st_size;
@@ -243,9 +247,11 @@
 		} else { 
 			buf [i].type = Bonobo_STORAGE_TYPE_REGULAR;
 			buf [i].content_type = 
-				CORBA_string_dup ("application/octet-stream");
+				CORBA_string_dup (gnome_mime_type_of_file (full));
 		}
 
+		g_free (full);
+
 		num_entries++;
 	}
 
@@ -262,6 +268,9 @@
 
 	if (list) 
 		CORBA_free (list);
+
+	if (full)
+		g_free (full);
 	
 	if (errno == ENOENT) 
 		CORBA_exception_set (ev, CORBA_USER_EXCEPTION, 
Index: storage-modules/bonobo-stream-fs.c
===================================================================
RCS file: /cvs/gnome/bonobo/storage-modules/bonobo-stream-fs.c,v
retrieving revision 1.42
diff -u -r1.42 bonobo-stream-fs.c
--- storage-modules/bonobo-stream-fs.c	2000/11/30 21:58:30	1.42
+++ storage-modules/bonobo-stream-fs.c	2001/02/20 13:30:22
@@ -14,9 +14,14 @@
 #include <sys/stat.h>
 #include <libgnome/gnome-defs.h>
 #include <libgnome/gnome-util.h>
+#include <libgnome/gnome-mime.h>
 #include <storage-modules/bonobo-stream-fs.h>
 #include <errno.h>
 
+struct _BonoboStreamFSPrivate {
+	gchar *mime_type;
+};
+
 static BonoboStreamClass *bonobo_stream_fs_parent_class;
 
 static gint
@@ -60,7 +65,7 @@
 	si->size = st.st_size;
 	si->type = Bonobo_STORAGE_TYPE_REGULAR;
 	si->name = CORBA_string_dup ("");
-	si->content_type = CORBA_string_dup ("application/octet-stream");
+	si->content_type = CORBA_string_dup (stream_fs->priv->mime_type);
 
 	return si;
 
@@ -289,11 +294,28 @@
 	
 	if (close (stream_fs->fd)) 
 		g_warning ("Close failed");
-	
 	stream_fs->fd = -1;
+
+	if (stream_fs->path)
+		g_free (stream_fs->path);
+	stream_fs->path = NULL;
+
+	if (stream_fs->priv->mime_type)
+		g_free (stream_fs->priv->mime_type);
+	stream_fs->priv->mime_type = NULL;
 }
 
 static void
+fs_finalize (GtkObject *object)
+{
+	BonoboStreamFS *stream_fs = BONOBO_STREAM_FS (object);
+	
+	if (stream_fs->priv)
+		g_free (stream_fs->priv);
+	stream_fs->priv = NULL;
+}
+
+static void
 bonobo_stream_fs_class_init (BonoboStreamFSClass *klass)
 {
 	GtkObjectClass    *oclass = (GtkObjectClass *) klass;
@@ -313,6 +335,14 @@
         sclass->revert   = fs_revert;
 
 	oclass->destroy = fs_destroy;
+	oclass->finalize = fs_finalize;
+}
+
+static void
+bonobo_stream_fs_init (BonoboStreamFS *stream_fs)
+{
+	stream_fs->priv = g_new0 (BonoboStreamFSPrivate,1);
+	stream_fs->priv->mime_type = NULL;
 }
 
 /**
@@ -331,7 +361,7 @@
 			sizeof (BonoboStreamFS),
 			sizeof (BonoboStreamFSClass),
 			(GtkClassInitFunc) bonobo_stream_fs_class_init,
-			(GtkObjectInitFunc) NULL,
+			(GtkObjectInitFunc) bonobo_stream_fs_init,
 			NULL, /* reserved 1 */
 			NULL, /* reserved 2 */
 			(GtkClassInitFunc) NULL
@@ -368,7 +398,7 @@
 }
 
 static BonoboStream *
-bonobo_stream_create (int fd)
+bonobo_stream_create (int fd, const char *path)
 {
 	BonoboStreamFS *stream_fs;
 	Bonobo_Stream corba_stream;
@@ -378,6 +408,7 @@
 		return NULL;
 	
 	stream_fs->fd = fd;
+	stream_fs->priv->mime_type = g_strdup (gnome_mime_type_of_file (path));
 	
 	corba_stream = bonobo_stream_corba_object_create (
 		BONOBO_OBJECT (stream_fs));
@@ -461,7 +492,7 @@
 		return NULL;
 	}
 
-	if (!(stream = bonobo_stream_create (fd)))
+	if (!(stream = bonobo_stream_create (fd, path)))
 		CORBA_exception_set (ev, CORBA_USER_EXCEPTION, 
 				     ex_Bonobo_Storage_IOError, NULL);
 


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