Re: adding new info to GnomeVFSFileInfo



Are there any chances that this patch or something similar goes in for
2.2 (whose freeze is in 1 month...) ?

Christophe

Le ven 20/09/2002 à 09:06, Christophe Fergeau a écrit :
> > 
> > Well, since the project has traditionally been closely connected with
> > Nautilus we use the Nautilus coding style. Theres no reason to change
> > that. Oh, and vi is the official GnomeVFS editor ;-)
> > > 
> 
> Here is a patch taking into account your various remarks (mainly about
> the coding style and the executable flag). But I used both emacs and vi
> to generate it. Is it ok or should I rework the patch only with vi ? :p
> I was also wondering if the executable flag needed to be set for remote
> directories if the dir is accessible. Any idea ?
> 
> Christophe
> ----
> 

> Seulement dans gnome-vfs-new: aclocal.m4
> diff -urbB gnome-vfs/ChangeLog gnome-vfs-new/ChangeLog
> --- gnome-vfs/ChangeLog	2002-07-27 05:50:12.000000000 +0200
> +++ gnome-vfs-new/ChangeLog	2002-09-19 22:17:38.000000000 +0200
> @@ -1,3 +1,13 @@
> +2002-09-19  Christophe Fergeau  <teuf users sourceforge net>
> +
> +	* libgnomevfs/gnome-vfs-file-info.h: modified GnomeVFSInfoFields and
> +	  GnomeVFSFilePermissions to be able to report access(2)-like 
> +	  information in GnomeVFSFileInfo
> +	* modules/ssh-method.c
> +	* modules/file-method.c: report access information in do_get_file_info
> +	* test/test-info.c: display access information if available
> +	
> +
>  2002-07-26  Ian McKellar  <yakk yakk net>
>  
>  	* libgnomevfs/gnome-vfs-xfer.c: (copy_file):
> diff -urbB gnome-vfs/libgnomevfs/gnome-vfs-file-info.h gnome-vfs-new/libgnomevfs/gnome-vfs-file-info.h
> --- gnome-vfs/libgnomevfs/gnome-vfs-file-info.h	2002-06-21 19:39:25.000000000 +0200
> +++ gnome-vfs-new/libgnomevfs/gnome-vfs-file-info.h	2002-09-19 22:23:37.000000000 +0200
> @@ -77,7 +77,8 @@
>  	GNOME_VFS_FILE_INFO_FIELDS_MTIME = 1 << 10,
>  	GNOME_VFS_FILE_INFO_FIELDS_CTIME = 1 << 11,
>  	GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME = 1 << 12,
> -	GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE = 1 << 13
> +	GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE = 1 << 13,
> +	GNOME_VFS_FILE_INFO_FIELDS_ACCESS = 1 << 14
>  } GnomeVFSFileInfoFields;
>  
>  /* File permissions.  These are the same as the Unix ones, but we wrap them
> @@ -105,10 +106,12 @@
>  	GNOME_VFS_PERM_OTHER_READ = S_IROTH,
>  	GNOME_VFS_PERM_OTHER_WRITE = S_IWOTH,
>  	GNOME_VFS_PERM_OTHER_EXEC = S_IXOTH,
> -	GNOME_VFS_PERM_OTHER_ALL = S_IROTH | S_IWOTH | S_IXOTH
> +	GNOME_VFS_PERM_OTHER_ALL = S_IROTH | S_IWOTH | S_IXOTH,
> +	GNOME_VFS_PERM_ACCESS_READABLE   = 1 << 16,
> +	GNOME_VFS_PERM_ACCESS_WRITABLE   = 1 << 17,
> +	GNOME_VFS_PERM_ACCESS_EXECUTABLE = 1 << 18
>  } GnomeVFSFilePermissions;
>  
> -
>  typedef struct {
>  	/* Base name of the file (no path).  */
>  	char *name;
> @@ -113,7 +116,7 @@
>  	/* Base name of the file (no path).  */
>  	char *name;
>  
> -	/* Fields which are actually valid in this strcture. */
> +	/* Fields which are actually valid in this structure. */
>  	GnomeVFSFileInfoFields valid_fields;
>  
>  	/* File type (i.e. regular, directory, block device...).  */
> diff -urbB gnome-vfs/modules/file-method.c gnome-vfs-new/modules/file-method.c
> --- gnome-vfs/modules/file-method.c	2002-07-13 01:33:30.000000000 +0200
> +++ gnome-vfs-new/modules/file-method.c	2002-09-19 21:50:41.000000000 +0200
> @@ -593,6 +593,28 @@
>  	}
>  }
>  
> +static void
> +get_access_info (GnomeVFSFileInfo *file_info,
> +		 const gchar *full_name)
> +{
> +	/* FIXME: should check errno after calling access because we don't
> +	 * want to set valid_fields if something bad happened during one
> +	 * of the access calls
> +	 */
> +	if (access (full_name, R_OK) == 0) {
> +		file_info->permissions |= GNOME_VFS_PERM_ACCESS_READABLE;
> +	}
> +
> +	if (access (full_name, W_OK) == 0) {
> +		file_info->permissions |= GNOME_VFS_PERM_ACCESS_WRITABLE;
> +	}
> +
> +	if (access (full_name, X_OK) == 0) {
> +		file_info->permissions |= GNOME_VFS_PERM_ACCESS_EXECUTABLE;
> +	}
> +	file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_ACCESS;
> +}
> +
>  static GnomeVFSResult
>  get_stat_info (GnomeVFSFileInfo *file_info,
>  	       const gchar *full_name,
> @@ -823,6 +845,8 @@
>  		return result;
>  	}
>  
> +	get_access_info (file_info, full_name);
> +
>  	if (options & GNOME_VFS_FILE_INFO_GET_MIME_TYPE) {
>  		get_mime_type (file_info, full_name, options, &statbuf);
>  	}
> diff -urbB gnome-vfs/modules/ssh-method.c gnome-vfs-new/modules/ssh-method.c
> --- gnome-vfs/modules/ssh-method.c	2002-07-19 09:57:11.000000000 +0200
> +++ gnome-vfs-new/modules/ssh-method.c	2002-09-19 22:14:36.000000000 +0200
> @@ -463,6 +463,62 @@
>  
>  #define LINE_LENGTH 4096 /* max line length we'll grok */
>  
> +static void get_access_info (GnomeVFSURI *uri, GnomeVFSFileInfo *file_info)
> +{
> +	gint i;
> +	gchar *name;
> +	gchar *quoted_name;
> +	struct param {
> +		char c;
> +		GnomeVFSFilePermissions perm;
> +	};
> +	struct param params[2] = {{'r', GNOME_VFS_PERM_ACCESS_READABLE},
> +				  {'w', GNOME_VFS_PERM_ACCESS_WRITABLE}};
> +
> +	
> +	name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S);
> +
> +
> +	if ( *name == '\0' ) {
> +		quoted_name = g_shell_quote ("/");
> +	} else {
> +		quoted_name = g_shell_quote (name);
> +	}
> +	g_free (name);
> +
> +	for (i = 0; i<2; i++) {
> +		gchar c;
> +		gchar *cmd;
> +		SshHandle *handle;
> +		GnomeVFSFileSize bytes_read;
> +		GnomeVFSResult result;
> +
> +		cmd = g_strdup_printf ("test -%c %s && echo $?", 
> +				       params[i].c, quoted_name);
> +		result = ssh_connect (&handle, uri, cmd);
> +		g_free (cmd);
> +		
> +		if (result != GNOME_VFS_OK) {
> +			g_free(quoted_name);
> +			return;
> +		}		
> +		
> +		result = ssh_read (handle, &c, 1, &bytes_read);
> +		if ((bytes_read > 0) && (c == '0')) {
> +			file_info->permissions |= params[i].perm;
> +		} else {
> +			file_info->permissions &= ~params[i].perm;
> +		}
> +			
> +		ssh_destroy (handle);
> +	}
> +
> +	file_info->permissions &= ~GNOME_VFS_PERM_ACCESS_EXECUTABLE;
> +	file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_ACCESS;
> +
> +	g_free(quoted_name);
> +}
> +
>  static GnomeVFSResult 
>  do_read_directory (GnomeVFSMethod *method,
>  		   GnomeVFSMethodHandle *method_handle,
> @@ -535,6 +591,8 @@
>  		file_info->valid_fields &= 
>  			~GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE;
>  
> +		get_access_info (((SshHandle*)method_handle)->uri, file_info);
> +		
>  		/* Break out.
>  		   We are in a loop so we get the first 'ls' line;
>  		   often it starts with 'total 2213' etc.
> diff -urbB gnome-vfs/test/test-info.c gnome-vfs-new/test/test-info.c
> --- gnome-vfs/test/test-info.c	2002-05-02 04:43:32.000000000 +0200
> +++ gnome-vfs-new/test/test-info.c	2002-09-19 21:55:21.000000000 +0200
> @@ -116,6 +116,15 @@
>  	if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE)
>  		printf ("Inode #           : %ld\n", (gulong) info->inode);
>  
> +	if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
> +		printf ("Readable          : %s\n", 
> +			(info->permissions&GNOME_VFS_PERM_ACCESS_READABLE?"YES":"NO"));
> +		printf ("Writable          : %s\n", 
> +			(info->permissions&GNOME_VFS_PERM_ACCESS_WRITABLE?"YES":"NO"));
> +		printf ("Executable        : %s\n", 
> +			(info->permissions&GNOME_VFS_PERM_ACCESS_EXECUTABLE?"YES":"NO"));
> +	}
> +	
>  
>  #undef FLAG_STRING
>  }





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