static void pygvfinfo_dealloc(PyGnomeVFSFileInfo *self) { if (self->finfo) gnome_vfs_file_info_unref(self->finfo); PyObject_FREE(self); }
const char * gnome_vfs_get_special_mime_type (GnomeVFSURI *uri) { GnomeVFSResult error; GnomeVFSFileInfo *info; const char *type; info = gnome_vfs_file_info_new (); type = NULL; /* Get file info and examine the type field to see if file is * one of the special kinds. */ error = gnome_vfs_get_file_info_uri (uri, info, GNOME_VFS_FILE_INFO_DEFAULT); if (error == GNOME_VFS_OK && info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) { switch (info->type) { case GNOME_VFS_FILE_TYPE_DIRECTORY: type = "x-directory/normal"; break; case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE: type = "x-special/device-char"; break; case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE: type = "x-special/device-block"; break; case GNOME_VFS_FILE_TYPE_FIFO: type = "x-special/fifo"; break; case GNOME_VFS_FILE_TYPE_SOCKET: type = "x-special/socket"; break; default: break; } } gnome_vfs_file_info_unref (info); return type; }
void la_track_unref(LaTrack * self) { if (--self->refcount > 0) return; if (self->uri) g_free(self->uri); if (self->title) g_free(self->title); if (self->genre) g_free(self->genre); if (self->artist) g_free(self->artist); if (self->album) g_free(self->album); if (self->track) g_free(self->track); if (self->year) g_free(self->year); if (self->comment) g_free(self->comment); if (self->icon) g_free(self->icon); if (self->size_str) g_free(self->size_str); if (self->time_str) g_free(self->time_str); if (self->date_str) g_free(self->date_str); if (self->rating_str) g_free(self->rating_str); if (self->quality_str) g_free(self->quality_str); if (self->summary_str) g_free(self->summary_str); if (self->vfs_uri) gnome_vfs_uri_unref(self->vfs_uri); if (self->vfs_info) gnome_vfs_file_info_unref(self->vfs_info); g_free(self); }
void populate_tree_model (GtkListStore *model) { GnomeVFSDirectoryHandle *handle; GnomeVFSFileInfo *info; GnomeVFSResult res; GtkTreeIter iter; // GValue *value; #define URI "/" gnome_vfs_init(); res = gnome_vfs_directory_open (&handle, URI, GNOME_VFS_FILE_INFO_DEFAULT); if (res) goto error; for (;;) { info = gnome_vfs_file_info_new (); res = gnome_vfs_directory_read_next (handle, info); if (res == GNOME_VFS_ERROR_EOF) break; if (res && res != GNOME_VFS_ERROR_EOF) { gnome_vfs_file_info_unref (info); goto error; } puts(info->name); // value = g_new0 (GValue, 1); // g_value_init (value, G_TYPE_POINTER); // g_value_set_pointer (value, info); gtk_list_store_append (GTK_LIST_STORE(model), &iter); /** ?? **/ // gtk_list_store_set_value (GTK_LIST_STORE(model), &iter, COLUMN_ONE, value); // gtk_list_store_set (model, &iter, COLUMN_ONE, info->name, -1); gtk_list_store_set (model, &iter, COLUMN_ONE, info, COLUMN_TWO, 0, -1); } goto done; error: puts(gnome_vfs_result_to_string (res)); done: gnome_vfs_directory_close (handle); }
/*--------------------------------------------------------------------------*/ static GList * prune_list_from_dir( GList *remote_list, gint *n, const gchar *dirname ) { GnomeVFSFileInfo *local_info, *remote_info; GList *local_list; GList *p_remote, *p_local; gchar *local_text_uri; GnomeVFSResult ret; gb_debug (DEBUG_UPDATE, "START"); if ( dirname == NULL ) return remote_list; local_text_uri = gnome_vfs_get_uri_from_local_path( dirname ); if ( (ret = gnome_vfs_directory_list_load (&local_list, local_text_uri, GNOME_VFS_FILE_INFO_DEFAULT)) != GNOME_VFS_OK ) { return remote_list; } for ( p_local=local_list; p_local != NULL; p_local=p_local->next ) { local_info = (GnomeVFSFileInfo *)p_local->data; for ( p_remote=remote_list; p_remote != NULL; p_remote=p_remote->next ) { remote_info = (GnomeVFSFileInfo *)p_remote->data; if ( g_strcasecmp( local_info->name, remote_info->name ) == 0 ) { remote_list = g_list_remove_link( remote_list, p_remote ); gnome_vfs_file_info_unref( remote_info ); p_remote->data = remote_info = NULL; g_list_free_1( p_remote ); p_remote = NULL; *n -= 1; break; } } } g_free( local_text_uri ); gb_debug (DEBUG_UPDATE, "END"); return remote_list; }
void file_data_update (FileData *fd) { GnomeVFSFileInfo *info; GnomeVFSResult result; g_return_if_fail (fd != NULL); fd->error = FALSE; fd->thumb_loaded = FALSE; fd->thumb_created = FALSE; info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info (fd->path, info, (GNOME_VFS_FILE_INFO_FOLLOW_LINKS | GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE)); if (result != GNOME_VFS_OK) { fd->error = TRUE; fd->size = 0L; fd->mtime = 0; fd->ctime = 0; fd->exif_data_loaded = FALSE; fd->mime_type = NULL; return; } fd->name = file_name_from_path (fd->path); g_free (fd->display_name); fd->display_name = gnome_vfs_unescape_string_for_display (fd->name); fd->mime_type = get_static_string (info->mime_type); fd->size = info->size; fd->mtime = info->mtime; fd->ctime = info->ctime; fd->exif_data_loaded = FALSE; gnome_vfs_file_info_unref (info); }
gboolean magick_make_webimage(struct data *data, struct image *image, const gchar *uri, gint image_h) { MagickWand *wand; struct image_size *img_size = NULL; GnomeVFSResult result; GnomeVFSFileInfo *info; g_debug("in magick_make_webimage"); wand = _generate_webimage(data, image, image_h, &img_size); if (wand == NULL) return FALSE; /* save the image to a file */ if (!_save(data, wand, uri)) { DestroyMagickWand(wand); g_free(img_size); return FALSE; } DestroyMagickWand(wand); /* get file size */ info = gnome_vfs_file_info_new(); result = gnome_vfs_get_file_info(uri, info, GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); if (result == GNOME_VFS_OK) { img_size->size = info->size / 1024; } else { img_size->size = 0; } image->sizes = g_slist_append(image->sizes, img_size); gnome_vfs_file_info_unref(info); return TRUE; }
static gboolean gst_gnome_vfs_src_get_size (GstBaseSrc * basesrc, guint64 * size) { GstGnomeVFSSrc *src; GnomeVFSFileInfo *info; GnomeVFSFileInfoOptions options; GnomeVFSResult res; src = GST_GNOME_VFS_SRC (basesrc); *size = -1; info = gnome_vfs_file_info_new (); options = GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_FOLLOW_LINKS; res = gnome_vfs_get_file_info_from_handle (src->handle, info, options); if (res == GNOME_VFS_OK) { if ((info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) { *size = info->size; GST_DEBUG_OBJECT (src, "from handle: %" G_GUINT64_FORMAT " bytes", *size); } else if (src->own_handle && gnome_vfs_uri_is_local (src->uri)) { GST_DEBUG_OBJECT (src, "file size not known, file local, trying fallback"); res = gnome_vfs_get_file_info_uri (src->uri, info, options); if (res == GNOME_VFS_OK && (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) != 0) { *size = info->size; GST_DEBUG_OBJECT (src, "from uri: %" G_GUINT64_FORMAT " bytes", *size); } } } else { GST_WARNING_OBJECT (src, "getting info failed: %s", gnome_vfs_result_to_string (res)); } gnome_vfs_file_info_unref (info); if (*size == (GnomeVFSFileSize) - 1) return FALSE; GST_DEBUG_OBJECT (src, "return size %" G_GUINT64_FORMAT, *size); return TRUE; }
gboolean mn_vfs_test (GnomeVFSURI *uri, GFileTest test) { GnomeVFSFileInfoOptions options; GnomeVFSFileInfo *file_info; gboolean status = FALSE; g_return_val_if_fail(uri != NULL, FALSE); options = GNOME_VFS_FILE_INFO_DEFAULT; if (! (test & G_FILE_TEST_IS_SYMLINK)) options |= GNOME_VFS_FILE_INFO_FOLLOW_LINKS; if (test & G_FILE_TEST_IS_EXECUTABLE) options |= GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS; file_info = gnome_vfs_file_info_new(); if (gnome_vfs_get_file_info_uri(uri, file_info, options) == GNOME_VFS_OK) { if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) { if (test & G_FILE_TEST_IS_REGULAR) status = file_info->type == GNOME_VFS_FILE_TYPE_REGULAR; if (! status && test & G_FILE_TEST_IS_SYMLINK) status = file_info->type == GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK; if (! status && test & G_FILE_TEST_IS_DIR) status = file_info->type == GNOME_VFS_FILE_TYPE_DIRECTORY; } if (file_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) { if (! status && test & G_FILE_TEST_IS_EXECUTABLE) status = file_info->permissions & GNOME_VFS_PERM_ACCESS_EXECUTABLE; } if (! status && test & G_FILE_TEST_EXISTS) status = TRUE; /* gnome_vfs_get_file_info() succeeded, so the file exists */ } gnome_vfs_file_info_unref(file_info); return status; }
static int tcp_transfer_dir(tcp_con_t *con,const char *path){ int rc; char *basename; GnomeVFSFileInfo *info; GnomeVFSResult res; gchar *dir_uri; if ( (!con) || (!path) ) return -EINVAL; info=gnome_vfs_file_info_new(); dir_uri=gnome_vfs_get_uri_from_local_path(path); rc=-ENOMEM; if (!dir_uri) goto free_info_out; res=gnome_vfs_get_file_info(dir_uri,info,GNOME_VFS_FILE_INFO_FOLLOW_LINKS); if (res != GNOME_VFS_OK) { rc=-res; goto free_info_out; } basename=g_path_get_basename(path); rc=-ENOMEM; if (!basename) goto free_info_out; rc=send_directory(con,path,basename,info); g_free(basename); if (!rc) rc=finalize_send_directory(con,path,info); else err_out("Send directory fail %s (%d)\n", strerror(-rc),rc); free_info_out: gnome_vfs_file_info_unref(info); return rc; }
static gboolean copy_uri (const gchar *src_uri, const gchar *dest_uri, const gchar *copying_format_str, const gchar *copied_format_str, GError **error) { GnomeVFSHandle *read_handle; GnomeVFSHandle *write_handle; GnomeVFSFileInfo *src_info; GnomeVFSFileSize file_size = 0; GnomeVFSFileSize bytes_read = 0; guchar buffer[BUFSIZE]; GnomeVFSResult result; gchar *memsize; GTimeVal last_time = { 0, 0 }; gimp_progress_init (_("Connecting to server")); src_info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info (src_uri, src_info, 0); /* ignore errors here, they will be noticed below */ if (result == GNOME_VFS_OK && (src_info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE)) { file_size = src_info->size; } gnome_vfs_file_info_unref (src_info); result = gnome_vfs_open (&read_handle, src_uri, GNOME_VFS_OPEN_READ); if (result != GNOME_VFS_OK) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Could not open '%s' for reading: %s"), src_uri, gnome_vfs_result_to_string (result)); return FALSE; } result = gnome_vfs_create (&write_handle, dest_uri, GNOME_VFS_OPEN_WRITE, FALSE, 0644); if (result != GNOME_VFS_OK) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Could not open '%s' for writing: %s"), dest_uri, gnome_vfs_result_to_string (result)); gnome_vfs_close (read_handle); return FALSE; } memsize = g_format_size_for_display (file_size); gimp_progress_init_printf (file_size > 0 ? copying_format_str : copied_format_str, memsize); g_free (memsize); while (TRUE) { GnomeVFSFileSize chunk_read; GnomeVFSFileSize chunk_written; GTimeVal now; result = gnome_vfs_read (read_handle, buffer, sizeof (buffer), &chunk_read); if (chunk_read == 0) { if (result != GNOME_VFS_ERROR_EOF) { memsize = g_format_size_for_display (sizeof (buffer)); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to read %s from '%s': %s"), memsize, src_uri, gnome_vfs_result_to_string (result)); g_free (memsize); gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return FALSE; } else { gimp_progress_update (1.0); break; } } bytes_read += chunk_read; /* update the progress only up to 10 times a second */ g_get_current_time (&now); if (((now.tv_sec - last_time.tv_sec) * 1000 + (now.tv_usec - last_time.tv_usec) / 1000) > 100) { if (file_size > 0) { gimp_progress_update ((gdouble) bytes_read / (gdouble) file_size); } else { memsize = g_format_size_for_display (bytes_read); gimp_progress_set_text_printf (copied_format_str, memsize); gimp_progress_pulse (); g_free (memsize); } last_time = now; } result = gnome_vfs_write (write_handle, buffer, chunk_read, &chunk_written); if (chunk_written < chunk_read) { memsize = g_format_size_for_display (chunk_read); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to write %s to '%s': %s"), memsize, dest_uri, gnome_vfs_result_to_string (result)); g_free (memsize); gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return FALSE; } } gnome_vfs_close (read_handle); gnome_vfs_close (write_handle); return TRUE; }
int main (int argc, char **argv) { GnomeVFSResult result; char *text_uri; GnomeVFSURI *src, *dest; GnomeVFSFileInfo *info; if (argc != 3) { printf ("Usage: %s <src> <dest>\n", argv[0]); return 1; } if (!gnome_vfs_init ()) { fprintf (stderr, "Cannot initialize gnome-vfs.\n"); return 1; } command_line_authentication_init (); text_uri = gnome_vfs_make_uri_from_shell_arg (argv[1]); src = gnome_vfs_uri_new (text_uri); g_free (text_uri); text_uri = gnome_vfs_make_uri_from_shell_arg (argv[2]); dest = gnome_vfs_uri_new (text_uri); g_free (text_uri); if (src == NULL || dest == NULL) { result = GNOME_VFS_ERROR_INVALID_URI; goto out; } info = gnome_vfs_file_info_new (); result = gnome_vfs_get_file_info_uri (dest, info, GNOME_VFS_FILE_INFO_DEFAULT); if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_NOT_FOUND) { gnome_vfs_file_info_unref (info); goto out; } /* If the target is a directory do not overwrite it but copy the source into the directory! (This is like cp does it) */ if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE && info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) { char *name; GnomeVFSURI *new_dest; name = gnome_vfs_uri_extract_short_path_name (src); new_dest = gnome_vfs_uri_append_string (dest, name); gnome_vfs_uri_unref (dest); g_free (name); dest = new_dest; } gnome_vfs_file_info_unref (info); result = gnome_vfs_xfer_uri (src, dest, GNOME_VFS_XFER_RECURSIVE, GNOME_VFS_XFER_ERROR_MODE_ABORT, GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, NULL, NULL); out: if (src) { gnome_vfs_uri_unref (src); } if (dest) { gnome_vfs_uri_unref (dest); } if (result != GNOME_VFS_OK) { fprintf (stderr, "Failed to copy %s to %s\nReason: %s\n", argv[1], argv[2], gnome_vfs_result_to_string (result)); return 1; } return 0; }
gboolean apply_transformation_jpeg (FileData *file, GthTransform transform, JpegMcuAction mcu_action, GError **error) { gboolean result = TRUE; char *tmp_dir = NULL; char *tmp_output_file = NULL; JXFORM_CODE transf; char *local_file; GnomeVFSFileInfo *info = NULL; if (file == NULL) return FALSE; if (transform == GTH_TRANSFORM_NONE) return TRUE; tmp_dir = get_temp_dir_name (); if (tmp_dir == NULL) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a temporary folder")); return FALSE; } local_file = get_cache_filename_from_uri (file->path); if (local_file == NULL) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not create a local temporary copy of the remote file.")); result = FALSE; goto apply_transformation_jpeg__free_and_close; } info = gnome_vfs_file_info_new (); gnome_vfs_get_file_info (file->path, info, GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS | GNOME_VFS_FILE_INFO_FOLLOW_LINKS); switch (transform) { case GTH_TRANSFORM_NONE: transf = JXFORM_NONE; break; case GTH_TRANSFORM_FLIP_H: transf = JXFORM_FLIP_H; break; case GTH_TRANSFORM_ROTATE_180: transf = JXFORM_ROT_180; break; case GTH_TRANSFORM_FLIP_V: transf = JXFORM_FLIP_V; break; case GTH_TRANSFORM_TRANSPOSE: transf = JXFORM_TRANSPOSE; break; case GTH_TRANSFORM_ROTATE_90: transf = JXFORM_ROT_90; break; case GTH_TRANSFORM_TRANSVERSE: transf = JXFORM_TRANSVERSE; break; case GTH_TRANSFORM_ROTATE_270: transf = JXFORM_ROT_270; break; default: transf = JXFORM_NONE; break; } tmp_output_file = get_temp_file_name (tmp_dir, NULL); if (! jpegtran (local_file, tmp_output_file, transf, mcu_action, error)) { result = FALSE; goto apply_transformation_jpeg__free_and_close; } if (! local_file_move (tmp_output_file, local_file)) { if (error != NULL) *error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not move temporary file to local destination. Check folder permissions.")); result = FALSE; goto apply_transformation_jpeg__free_and_close; } if (info != NULL) { char *local_uri; local_uri = get_uri_from_local_path (local_file); gnome_vfs_set_file_info (local_uri, info, GNOME_VFS_SET_FILE_INFO_PERMISSIONS | GNOME_VFS_SET_FILE_INFO_OWNER); gnome_vfs_file_info_unref (info); g_free (local_uri); } apply_transformation_jpeg__free_and_close: local_dir_remove_recursive (tmp_dir); g_free (tmp_output_file); g_free (tmp_dir); return result; }