On Tue, 2002-09-17 at 04:28, Christophe Fergeau wrote: > /* File permissions. These are the same as the Unix ones, but we wrap them > @@ -105,15 +106,22 @@ > 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, > + /* FIXME: I put this stuff there to avoid using one of the > + * padding pointers, but nothing proves that any of this value is > + * not already used by one of the S_ constants. > + * Too bad these constants weren't modified before GNOME2 :( > + */ > + GNOME_VFS_PERM_ACCESS_READABLE = 1 << 16, > + GNOME_VFS_PERM_ACCESS_WRITEABLE = 1 << 17, > + GNOME_VFS_PERM_ACCESS_EXECUTABLE = 1 << 18 I think its a good idea to put these flags above the space used by POSIX in case we want to support flags like SUID in the future. I was a little concerned that the GnomeVFSFilePermissions might change size, but it doesn't look like it will on Linux/x86 or Solaris/sparc. Does anyone know of a platform we support that this will break on? > static GnomeVFSResult > +get_access_info (GnomeVFSFileInfo *file_info, > + const gchar *full_name) > +{ > + 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_WRITEABLE; > + } > + > + 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; > + return GNOME_VFS_OK; > +} Can you check for error returns from access (-1). Oh, and the standard style nitpick that you need to put a space between function names and parens - foo (bar) vs foo(bar). > +static void get_access_info (GnomeVFSURI *uri, GnomeVFSFileInfo *file_info) > +{ > + gint i; > + gchar *name; > + struct param { > + char c; > + GnomeVFSFilePermissions perm; > + }; > + struct param params[3] = {{'r', GNOME_VFS_PERM_ACCESS_READABLE}, > + {'w', GNOME_VFS_PERM_ACCESS_WRITEABLE}, > + {'x', GNOME_VFS_PERM_ACCESS_EXECUTABLE}}; > + > + /* FIXME: escape for shell */ > + name = gnome_vfs_unescape_string (uri->text, G_DIR_SEPARATOR_S); > + > + if ( *name == '\0' ) { > + g_free(name); > + name = g_strdup ("'/'"); > + } > + > + for (i = 0; i<3; i++) { > + gchar c; > + gchar *cmd; > + SshHandle *handle; > + GnomeVFSFileSize bytes_read; > + GnomeVFSResult result; > + > + cmd = g_strdup_printf("access -%c %s && echo $?", > + params[i].c, name); > + result = ssh_connect (&handle, uri, cmd); > + g_free (cmd); > + > + if (result != GNOME_VFS_OK) { > + return; > + } > + > + result = ssh_read (handle, &c, 1, &bytes_read); > + if ((bytes_read > 0) && (c == '0')) { > + g_print("%c\n", params[i].c); > + file_info->permissions |= params[i].perm; > + } > + ssh_destroy (handle); > + } > + file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_ACCESS; > +} > + Perhaps this should go into a version of gnome_vfs_parse_ls_lga that accepts a username in libgnomevfs/gnome-vfs-parse-ls.[ch] so that we can share this code with the ftp method and extfs methods... Otherwise, it looks pretty good to me - I'll be interested to hear the input of others too though. Ian
Attachment:
signature.asc
Description: This is a digitally signed message part