static GnomeVFSResult do_open_directory (GnomeVFSMethod *method, GnomeVFSMethodHandle **method_handle, GnomeVFSURI *uri, GnomeVFSFileInfoOptions options, GnomeVFSContext *context) { const gchar *path; DirHandle *handle; FakeNode *file; g_print ("do_open_directory: '%s'\n", uri->text); path = gnome_vfs_uri_get_path (uri); if (!path) { path = "/"; } handle = g_new0 (DirHandle, 1); handle->options = options; file = get_fake_node_from_uri (uri); if (file) { handle->gnode = file->gnode; handle->current_child = handle->gnode->children; } else { return GNOME_VFS_ERROR_NOT_FOUND; } *method_handle = (GnomeVFSMethodHandle *) handle; return GNOME_VFS_OK; }
static FakeNode * add_fake_node (GnomeVFSURI *uri, gboolean directory) { GnomeVFSURI *parent_uri; FakeNode *parent_file; const gchar *path, *name; FakeNode *file; parent_uri = gnome_vfs_uri_get_parent (uri); parent_file = get_fake_node_from_uri (parent_uri); if (!parent_file) { return NULL; } path = gnome_vfs_uri_get_path (uri); name = strrchr (path, '/') + 1; g_print ("ADD FAKE: %s, dir: %d\n", name, directory); file = fake_node_new (name, NULL); file->gnode = g_node_append_data (parent_file->gnode, file); file->directory = directory; print_tree (root, 0); return file; }
static GnomeVFSResult do_get_file_info (GnomeVFSMethod *method, GnomeVFSURI *uri, GnomeVFSFileInfo *file_info, GnomeVFSFileInfoOptions options, GnomeVFSContext *context) { const gchar *path; FakeNode *file; g_print ("do_get_file_info\n"); path = gnome_vfs_uri_get_path (uri); if (!path) { return GNOME_VFS_ERROR_INVALID_URI; } if (path[0] == '/') { path++; } file = get_fake_node_from_uri (uri); if (!file) { return GNOME_VFS_ERROR_NOT_FOUND; } if (file->gnode == root) { /* Root directory. */ file_info->name = g_strdup ("Tutorial"); } else { file_info->name = g_strdup (file->name); } if (file->directory) { file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY; file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE; file_info->mime_type = g_strdup ("x-directory/normal"); file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; } else { file_info->type = GNOME_VFS_FILE_TYPE_REGULAR; file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_TYPE; file_info->mime_type = g_strdup ("text/plain"); file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; file_info->size = file->size; file_info->valid_fields |= GNOME_VFS_FILE_INFO_FIELDS_SIZE; g_print ("size: %d\n", (gint) file_info->size); } return GNOME_VFS_OK; }
/** * file_exists_and_readable: * @filename: a #const gchar * with a file path * * tests if the file exists, and if it is readable, the last * check is not reliable, it does not check all the groups you are * in, so change this function before you rely on that check! * * this function is Gnome-VFS aware, so it will work on URI's * * Return value: gboolean, TRUE if readable, else FALSE **/ gboolean file_exists_and_readable(const gchar * filename) { gchar *ondiskencoding; /* not sure the purpose of returning true here by default so I changed it to false. */ /* gboolean retval=TRUE; */ gboolean retval = FALSE; #ifdef WIN32 if (strchr(filename,'/')==filename) filename++; #endif /* WIN32 */ #ifdef DEVELOPMENT g_assert(filename); #endif if (!filename || strlen(filename) < 2) { DEBUG_MSG("file_exists_and_readable, strlen(filename) < 2 or no filename!!!!\n"); return FALSE; } DEBUG_MSG("file_exists_and_readable, filename(%p)=\"%s\", strlen(filename)=%d\n", filename, filename, strlen(filename)); ondiskencoding = get_filename_on_disk_encoding(filename); DEBUG_MSG("file_exists_and_readable, ondiskencoding='%s'\n",ondiskencoding); #ifdef HAVE_GNOME_VFS { GnomeVFSURI* uri; uri = gnome_vfs_uri_new(ondiskencoding); retval = gnome_vfs_uri_exists(uri); DEBUG_MSG("gnome_vfs_uri has path %s\n",gnome_vfs_uri_get_path(uri)); gnome_vfs_uri_unref(uri); DEBUG_MSG("file_exists_and_readable, return %d for %s\n",retval,filename); } #else /* HAVE_GNOME_VFS */ { #ifdef WIN32 struct _stat naamstat; errno = 0; retval = ((_stat(ondiskencoding, &naamstat) == 0) && (errno == 0)); #else /* NOT WIN32 */ struct stat naamstat; errno = 0; retval = ((stat(ondiskencoding, &naamstat) == 0) && (errno == 0)); #endif DEBUG_MSG("file_exists_and_readable, retval=%d (ernno=%d) for\n %s\n",retval,errno,ondiskencoding); } #endif /* HAVE_GNOME_VFS */ g_free(ondiskencoding); return retval; }
static FakeNode * get_fake_node_from_uri (const GnomeVFSURI *uri) { const gchar *tmp; GList *list, *l; gchar *part; GNode *gnode, *found_gnode = NULL; FakeNode *file; gchar *path; tmp = gnome_vfs_uri_get_path (uri); if (!tmp || strcmp (tmp, "/") == 0) { /* Special case the root. */ return root->data; } if (tmp[0] == '/') { tmp++; } //g_print ("GET FAKE %s\n", tmp); /* Split the path into separate components. */ list = split_path (tmp); l = list; gnode = root->children; while (gnode) { part = l->data; file = gnode->data; //g_print ("FILE %s (compare to %s)\n", file->name, part); path = file->name; if (path[0] == '/') { path++; } if (strcmp (part, path) == 0) { l = l->next; if (!l) { found_gnode = gnode; break; } gnode = gnode->children; continue; } gnode = gnode->next; } for (l = list; l; l = l->next) { g_free (l->data); } g_list_free (list); //g_print ("GOT FAKE %p\n", found_node ? found_node->data : NULL); return found_gnode ? found_gnode->data : NULL; }