Re: adding new info to GnomeVFSFileInfo
- From: Christophe Fergeau <teuf users sourceforge net>
- To: Michael Meeks <michael ximian com>
- Cc: Ian McKellar <yakk yakk net>, gnome-vfs-list gnome org
- Subject: Re: adding new info to GnomeVFSFileInfo
- Date: 13 Oct 2002 22:01:31 +0200
Hi,
Here is a patch which adds a GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS so
that apps can tell if they are interested in this info.
The patch is against the 2.0 branch, but should go only in head imo, I
hope it applies correctly. I also haven't modified gnome-vfs docs
Christophe
Le jeu 03/10/2002 à 15:35, Michael Meeks a écrit :
> Hi Christophe,
>
> Ok, so the patch looks fine to me - except for the fact that it's not
> using the operation mask to limit the number of syscalls it does we need
> something like:
>
> if (options & GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
>
> So we avoid doing 3 (potential synchronous network round-trip) access
> calls, per operation.
>
> On Fri, 2002-09-20 at 08:06, Christophe Fergeau wrote:
> > I was also wondering if the executable flag needed to be set for remote
> > directories if the dir is accessible. Any idea ?
>
> No idea; what's there is fine for the moment; who is using this
> information ? where is this information being used incidentally ?
>
> If you add an options mask / guard around those ops, it looks fine to
> commit to me.
>
> Regards,
>
> Michael.
>
> --
> mmeeks gnu org <><, Pseudo Engineer, itinerant idiot
>
> _______________________________________________
> gnome-vfs-list mailing list
> gnome-vfs-list gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-vfs-list
? access.diff
Index: libgnomevfs/gnome-vfs-file-info.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-file-info.h,v
retrieving revision 1.19.2.1
diff -u -d -b -u -r1.19.2.1 gnome-vfs-file-info.h
--- libgnomevfs/gnome-vfs-file-info.h 21 Jun 2002 17:39:25 -0000 1.19.2.1
+++ libgnomevfs/gnome-vfs-file-info.h 13 Oct 2002 19:36:40 -0000
@@ -77,7 +77,9 @@
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,7 +107,10 @@
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;
@@ -113,7 +118,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...). */
@@ -174,7 +179,8 @@
GNOME_VFS_FILE_INFO_GET_MIME_TYPE = 1 << 0,
GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE = 1 << 1,
GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE = 1 << 2,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS = 1 << 3
+ GNOME_VFS_FILE_INFO_FOLLOW_LINKS = 1 << 3,
+ GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS = 1 << 4
} GnomeVFSFileInfoOptions;
typedef enum {
Index: modules/file-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/file-method.c,v
retrieving revision 1.105.2.5
diff -u -d -b -u -r1.105.2.5 file-method.c
--- modules/file-method.c 15 Aug 2002 12:04:12 -0000 1.105.2.5
+++ modules/file-method.c 13 Oct 2002 19:36:41 -0000
@@ -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,
@@ -821,6 +843,10 @@
if (result != GNOME_VFS_OK) {
g_free (full_name);
return result;
+ }
+
+ if (options & GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS) {
+ get_access_info (file_info, full_name);
}
if (options & GNOME_VFS_FILE_INFO_GET_MIME_TYPE) {
Index: modules/ssh-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/ssh-method.c,v
retrieving revision 1.8.2.3
diff -u -d -b -u -r1.8.2.3 ssh-method.c
--- modules/ssh-method.c 30 Sep 2002 19:56:42 -0000 1.8.2.3
+++ modules/ssh-method.c 13 Oct 2002 19:36:41 -0000
@@ -446,6 +446,62 @@
return ssh_destroy ((SshHandle *)method_handle);
}
+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,
@@ -520,6 +576,9 @@
~GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT;
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;
Index: test/test-info.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/test/test-info.c,v
retrieving revision 1.14
diff -u -d -b -u -r1.14 test-info.c
--- test/test-info.c 2 May 2002 02:43:32 -0000 1.14
+++ test/test-info.c 13 Oct 2002 19:36:42 -0000
@@ -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
}
@@ -151,6 +160,7 @@
result = gnome_vfs_get_file_info (uri,
info,
(GNOME_VFS_FILE_INFO_GET_MIME_TYPE
+ | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS
| GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
if (result != GNOME_VFS_OK) {
fprintf (stderr, "%s: %s: %s\n",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]