Re: semantics of gnome_vfs_get_file_info_from_handle



On Mon, 2003-02-03 at 12:32, Colin Walters wrote:

> GnomeVFSResult	 gnome_vfs_get_known_file_info_from_handle
> 						(GnomeVFSHandle *handle,
> 						 GnomeVFSFileInfo *info);

The attached patch adds the above API, and implements it for the HTTP
method.  I also added support to the test-shell for it.  Ok to commit?

Index: test/test-shell.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/test/test-shell.c,v
retrieving revision 1.27
diff -u -d -I$Id: -r1.27 test-shell.c
--- test/test-shell.c	4 Nov 2002 12:51:48 -0000	1.27
+++ test/test-shell.c	4 Feb 2003 02:43:55 -0000
@@ -227,6 +227,7 @@
 	printf ("File operations:\n");
 	printf (" * open <handle> <name>:   open a file\n");
 	printf (" * create <handle> <name>: create a file\n");
+	printf (" * handleinfo <handle>:    information from handle\n");
 	printf (" * close <handle>:         close a file\n");
 	printf (" * read <handle> <bytes>:  read bytes from stream\n");
 	printf (" * seek <handle> <pos>:    seek set position\n");
@@ -541,24 +542,10 @@
 }
 
 static void
-do_info (void)
+print_info (GnomeVFSFileInfo *info)
 {
-	char             *from;
-	GnomeVFSResult    result;
-	GnomeVFSFileInfo *info;
 	const char *mime_type;
-       struct tm *loctime;
-
-	from = get_fname ();
-
-
-	info = gnome_vfs_file_info_new ();
-	result = gnome_vfs_get_file_info (
-		from, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
-
-	if (show_if_error (result, "getting info on: ", from))
-		return;
-
+	struct tm *loctime;
 	fprintf (stdout, "Name: '%s'\n", info->name);
 	if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) {
 		fprintf (stdout, "Type: ");
@@ -586,8 +573,8 @@
 			break;
 		case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
 			fprintf (stdout, "symlink\n");
-                       fprintf (stdout, "symlink points to: %s", 
-                                                     info->symlink_name);
+			fprintf (stdout, "symlink points to: %s", 
+				 info->symlink_name);
 			break;
 		default:
 			fprintf (stdout, "Error; invalid value");
@@ -609,18 +596,38 @@
 
 	fprintf (stdout, "Mime Type: %s \n", mime_type);
         
-       loctime = localtime(&info->atime);
-       fprintf (stdout, "Last Accessed: %s", asctime(loctime));
-       loctime = localtime(&info->mtime);
-       fprintf (stdout, "Last Modified: %s", asctime(loctime));
-       loctime = localtime(&info->ctime);
-       fprintf (stdout, "Last Changed: %s", asctime(loctime));
+	loctime = localtime(&info->atime);
+	fprintf (stdout, "Last Accessed: %s", asctime(loctime));
+	loctime = localtime(&info->mtime);
+	fprintf (stdout, "Last Modified: %s", asctime(loctime));
+	loctime = localtime(&info->ctime);
+	fprintf (stdout, "Last Changed: %s", asctime(loctime));
         
-       fprintf (stdout, "uid: %d\n", info->uid);
-       fprintf (stdout, "gid: %d\n", info->gid);
+	fprintf (stdout, "uid: %d\n", info->uid);
+
+	fprintf (stdout, "gid: %d\n", info->gid);
 	fprintf (stdout, "\n");
 	/* FIXME bugzilla.eazel.com 2800: hack here; should dump them all */
-	
+}
+
+static void
+do_info (void)
+{
+	char             *from;
+	GnomeVFSResult    result;
+	GnomeVFSFileInfo *info;
+
+	from = get_fname ();
+
+
+	info = gnome_vfs_file_info_new ();
+	result = gnome_vfs_get_file_info (
+		from, info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE);
+
+	if (show_if_error (result, "getting info on: ", from))
+		return;
+
+	print_info (info);
 	gnome_vfs_file_info_unref (info);
 }
 
@@ -876,6 +883,26 @@
 	close_file (get_handle ());
 }
 
+static void
+do_handleinfo (void)
+{
+	const char *handlename = get_handle ();
+	GnomeVFSResult    result;
+	GnomeVFSHandle *handle = lookup_file (handlename);
+	GnomeVFSFileInfo *info;
+
+	if (!handle)
+		return;
+
+	info = gnome_vfs_file_info_new ();
+	result = gnome_vfs_get_known_file_info_from_handle (handle, info);
+
+	if (show_if_error (result, "getting info from handle: ", handlename))
+		return;
+
+	print_info (info);
+	gnome_vfs_file_info_unref (info);
+}
 
 /*
  * ---------------------------------------------------------------------
@@ -1046,6 +1073,8 @@
 			do_create ();
 		else if (g_ascii_strcasecmp (ptr, "close") == 0)
 			do_close ();
+		else if (g_ascii_strcasecmp (ptr, "handleinfo") == 0)
+			do_handleinfo ();
 		else if (g_ascii_strcasecmp (ptr, "read") == 0)
 			do_read ();
 		else if (g_ascii_strcasecmp (ptr, "seek") == 0)
Index: modules/http-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/http-method.c,v
retrieving revision 1.141
diff -u -d -I$Id: -r1.141 http-method.c
--- modules/http-method.c	13 Sep 2002 13:41:42 -0000	1.141
+++ modules/http-method.c	4 Feb 2003 02:43:57 -0000
@@ -2358,6 +2358,19 @@
 	return result;
 }
 
+static GnomeVFSResult
+do_get_known_file_info (GnomeVFSMethod *method,
+			GnomeVFSMethodHandle *method_handle,
+			GnomeVFSFileInfo *file_info)
+{
+	HttpFileHandle *handle = (HttpFileHandle *) method_handle;
+
+	ANALYZE_HTTP ("==> +do_get_known_file_info");
+
+	gnome_vfs_file_info_copy (file_info, handle->file_info);
+	return GNOME_VFS_OK;
+}
+
 static gboolean
 do_is_local (GnomeVFSMethod *method,
 	     const GnomeVFSURI *uri)
@@ -2584,7 +2597,11 @@
 	do_set_file_info,
 	NULL, /* truncate */
 	NULL, /* find_directory */
-	NULL  /* create_symbolic_link */
+	NULL, /* create_symbolic_link */
+	NULL, /* monitor_add */
+	NULL, /* monitor_cancel */
+	NULL, /* file_control */
+	do_get_known_file_info,
 };
 
 GnomeVFSMethod *
Index: modules/file-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/file-method.c,v
retrieving revision 1.111
diff -u -d -I$Id: -r1.111 file-method.c
--- modules/file-method.c	5 Dec 2002 09:42:29 -0000	1.111
+++ modules/file-method.c	4 Feb 2003 02:44:00 -0000
@@ -2283,7 +2283,7 @@
 	do_create_symbolic_link,
 	do_monitor_add,
 	do_monitor_cancel,
-	do_file_control
+	do_file_control,
 };
 
 GnomeVFSMethod *
Index: libgnomevfs/gnome-vfs-ops.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-ops.h,v
retrieving revision 1.25
diff -u -d -I$Id: -r1.25 gnome-vfs-ops.h
--- libgnomevfs/gnome-vfs-ops.h	12 Nov 2002 09:29:05 -0000	1.25
+++ libgnomevfs/gnome-vfs-ops.h	4 Feb 2003 02:44:00 -0000
@@ -85,6 +85,10 @@
 						 GnomeVFSFileInfo *info,
 						 GnomeVFSFileInfoOptions options);
 
+GnomeVFSResult	 gnome_vfs_get_known_file_info_from_handle
+						(GnomeVFSHandle *handle,
+						 GnomeVFSFileInfo *info);
+
 GnomeVFSResult   gnome_vfs_truncate             (const gchar *text_uri,
 						 GnomeVFSFileSize length);
 GnomeVFSResult   gnome_vfs_truncate_uri         (GnomeVFSURI *uri,
Index: libgnomevfs/gnome-vfs-ops.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-ops.c,v
retrieving revision 1.36
diff -u -d -I$Id: -r1.36 gnome-vfs-ops.c
--- libgnomevfs/gnome-vfs-ops.c	19 Dec 2002 17:57:19 -0000	1.36
+++ libgnomevfs/gnome-vfs-ops.c	4 Feb 2003 02:44:00 -0000
@@ -306,26 +306,25 @@
 }
 
 /**
- * gnome_vfs_get_file_info_from_handle:
+ * gnome_vfs_get_known_file_info_from_handle:
  * @handle: Handle of the file for which information must be retrieved
  * @info: Pointer to a GnomeVFSFileInfo object that will hold the information
  * for the file on return
- * @options: Options for retrieving file information
- * to retrieve for the file
  * 
- * Retrieve information about an open file.  The information will be stored in
- * @info.
+ * Retrieve any known information about an open file, without
+ * performing any new file operations.  The information will be stored
+ * in @info.
+ *
+ * The speed of this operation is entirely independent of that of the
+ * underlying filesystem.
  * 
  * Return value: An integer representing the result of the operation
  **/
 GnomeVFSResult
-gnome_vfs_get_file_info_from_handle (GnomeVFSHandle *handle,
-				     GnomeVFSFileInfo *info,
-				     GnomeVFSFileInfoOptions options)
+gnome_vfs_get_known_file_info_from_handle (GnomeVFSHandle *handle,
+					   GnomeVFSFileInfo *info)
 {
-	return gnome_vfs_get_file_info_from_handle_cancellable (handle, info,
-								options,
-								NULL);
+	return _gnome_vfs_handle_do_get_known_file_info (handle, info);
 }
 
 /**
Index: libgnomevfs/gnome-vfs-method.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-method.h,v
retrieving revision 1.13
diff -u -d -I$Id: -r1.13 gnome-vfs-method.h
--- libgnomevfs/gnome-vfs-method.h	12 Nov 2002 09:29:05 -0000	1.13
+++ libgnomevfs/gnome-vfs-method.h	4 Feb 2003 02:44:01 -0000
@@ -133,6 +133,11 @@
 					 GnomeVFSFileInfoOptions options,
 					 GnomeVFSContext *context);
 
+typedef GnomeVFSResult (* GnomeVFSMethodGetKnownFileInfoFromHandleFunc)
+					(GnomeVFSMethod *method,
+					 GnomeVFSMethodHandle *method_handle,
+					 GnomeVFSFileInfo *file_info);
+
 typedef GnomeVFSResult (* GnomeVFSMethodTruncateFunc) (GnomeVFSMethod *method,
 						       GnomeVFSURI *uri,
 						       GnomeVFSFileSize length,
@@ -254,6 +259,7 @@
 	GnomeVFSMethodMonitorAddFunc monitor_add;
 	GnomeVFSMethodMonitorCancelFunc monitor_cancel;
 	GnomeVFSMethodFileControlFunc file_control;
+	GnomeVFSMethodGetKnownFileInfoFromHandleFunc get_known_file_info_from_handle;
 };
 
 gboolean	   gnome_vfs_method_init   (void);
Index: libgnomevfs/gnome-vfs-handle.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-handle.c,v
retrieving revision 1.23
diff -u -d -I$Id: -r1.23 gnome-vfs-handle.c
--- libgnomevfs/gnome-vfs-handle.c	19 Dec 2002 17:57:19 -0000	1.23
+++ libgnomevfs/gnome-vfs-handle.c	4 Feb 2003 02:44:01 -0000
@@ -177,6 +177,14 @@
 			    context));
 }
 
+GnomeVFSResult
+_gnome_vfs_handle_do_get_known_file_info (GnomeVFSHandle *handle,
+					  GnomeVFSFileInfo *info)
+{
+	INVOKE_AND_RETURN (handle, get_known_file_info_from_handle,
+			   (handle->uri->method, handle->method_handle, info));
+}
+
 GnomeVFSResult _gnome_vfs_handle_do_truncate     (GnomeVFSHandle *handle,
 						 GnomeVFSFileSize length,
 						 GnomeVFSContext *context)
Index: libgnomevfs/gnome-vfs-handle-private.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-handle-private.h,v
retrieving revision 1.3
diff -u -d -I$Id: -r1.3 gnome-vfs-handle-private.h
--- libgnomevfs/gnome-vfs-handle-private.h	19 Dec 2002 17:57:19 -0000	1.3
+++ libgnomevfs/gnome-vfs-handle-private.h	4 Feb 2003 02:44:01 -0000
@@ -58,6 +58,8 @@
 						      GnomeVFSFileInfo        *info,
 						      GnomeVFSFileInfoOptions  options,
 						      GnomeVFSContext         *context);
+GnomeVFSResult   _gnome_vfs_handle_do_get_known_file_info (GnomeVFSHandle          *handle,
+							   GnomeVFSFileInfo        *info);
 GnomeVFSResult   _gnome_vfs_handle_do_truncate        (GnomeVFSHandle          *handle,
 						      GnomeVFSFileSize         length,
 						      GnomeVFSContext         *context);


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