gboolean rejilla_image_format_get_clone_size (gchar *uri, guint64 *blocks, guint64 *size_img, GCancellable *cancel, GError **error) { GFileInfo *info; GFile *file; if (!uri) return FALSE; /* NOTE: follow symlink if any */ file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, cancel, error); g_object_unref (file); if (!info) return FALSE; if (size_img) *size_img = g_file_info_get_size (info); if (blocks) *blocks = REJILLA_BYTES_TO_SECTORS (g_file_info_get_size (info), 2448); g_object_unref (info); return TRUE; }
gchar * nc_data_snia_get_fits (const gchar *filename, gboolean check_size) { gchar *full_filename = ncm_cfg_get_fullpath (filename); gchar *url_str = g_strdup_printf ("http://download.savannah.gnu.org/releases/numcosmo/%s", filename); GFile *local = g_file_new_for_path (full_filename); GFile *remote = g_file_new_for_uri (url_str); GError *error = NULL; gint prog = 0; gboolean download = FALSE; if (g_file_test (full_filename, G_FILE_TEST_EXISTS)) { if (check_size) { GFileInfo *local_info, *remote_info; local_info = g_file_query_info (local, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (local_info == NULL) g_error ("nc_data_snia_get_fits: cannot get info for %s: %s.", full_filename, error->message); remote_info = g_file_query_info (remote, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (remote_info == NULL) g_error ("nc_data_snia_get_fits: cannot get info for %s: %s." " To use this catalog, download the file from the url and copy " "to ~/.numcosmo directory.", url_str, error->message); if (g_file_info_get_size (local_info) != g_file_info_get_size (remote_info)) download = TRUE; } } else download = TRUE; if (download) { ncm_message ("# Downloading file [%s]...\n", url_str); if (!g_file_copy (remote, local, G_FILE_COPY_OVERWRITE, NULL, &_nc_data_snia_copy_prog, &prog, &error)) g_error ("nc_data_snia_get_fits: cannot get fits file from %s: %s." " To use this catalog, download the file from the url and copy " "to ~/.numcosmo directory.", url_str, error->message); } g_free (url_str); g_object_unref (local); g_object_unref (remote); return full_filename; }
static toff_t get_file_size(thandle_t handle) { Priv *p = (Priv*) handle; GError *error = NULL; GFileInfo *info; goffset size; g_assert(p->stream); size = p->allocated; if (p->file != NULL) { info = g_file_query_info(p->file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error); if (info == NULL) { g_warning("%s", error->message); g_error_free(error); } else { if (g_file_info_has_attribute(info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) size = g_file_info_get_size(info); g_object_unref(info); } } return (toff_t) size; }
static void gth_metadata_provider_file_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes) { GFileAttributeMatcher *matcher; char *value; GTimeVal *timeval_p; const char *value_s; matcher = g_file_attribute_matcher_new (attributes); value = g_format_size_for_display (g_file_info_get_size (file_data->info)); g_file_info_set_attribute_string (file_data->info, "gth::file::display-size", value); g_free (value); timeval_p = gth_file_data_get_modification_time (file_data); value = _g_time_val_strftime (timeval_p, "%x %X"); g_file_info_set_attribute_string (file_data->info, "gth::file::display-mtime", value); g_free (value); value = g_file_get_parse_name (file_data->file); g_file_info_set_attribute_string (file_data->info, "gth::file::full-name", value); g_free (value); value_s = get_static_string (g_file_info_get_content_type (file_data->info)); if (value_s != NULL) g_file_info_set_attribute_string (file_data->info, "gth::file::content-type", value_s); g_file_attribute_matcher_unref (matcher); }
static void update_selection_status (DialogData *data) { GList *file_list; int n_selected; goffset size_selected; GList *scan; char *size_selected_formatted; char *text_selected; file_list = get_files_to_download (data); n_selected = 0; size_selected = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; n_selected++; size_selected += g_file_info_get_size (file_data->info); } size_selected_formatted = g_format_size (size_selected); text_selected = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_selected), n_selected, size_selected_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text_selected); g_free (text_selected); g_free (size_selected_formatted); _g_object_list_unref (file_list); }
/** * Create file stream and set mime type for channel * @param info file info used to determine mime type * @return NS_OK when file stream created successfuly, error code otherwise */ nsresult nsGIOInputStream::DoOpenFile(GFileInfo *info) { GError *error = nullptr; mStream = g_file_read(mHandle, nullptr, &error); if (!mStream) { nsresult rv = MapGIOResult(error); g_warning("Cannot read from file: %s", error->message); g_error_free(error); return rv; } const char * content_type = g_file_info_get_content_type(info); if (content_type) { char *mime_type = g_content_type_get_mime_type(content_type); if (mime_type) { if (strcmp(mime_type, APPLICATION_OCTET_STREAM) != 0) { SetContentTypeOfChannel(mime_type); } g_free(mime_type); } } else { g_warning("Missing content type."); } mBytesRemaining = g_file_info_get_size(info); // Update the content length attribute on the channel. We do this // synchronously without proxying. This hack is not as bad as it looks! mChannel->SetContentLength(mBytesRemaining); return NS_OK; }
static void upload_photo_wrote_body_data_cb (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data) { PicasaWebService *self = user_data; GthFileData *file_data; char *details; double current_file_fraction; if (self->priv->post_photos->current == NULL) return; self->priv->post_photos->wrote_body_data_size += chunk->length; if (self->priv->post_photos->wrote_body_data_size > msg->request_body->length) return; file_data = self->priv->post_photos->current->data; /* Translators: %s is a filename */ details = g_strdup_printf (_("Uploading '%s'"), g_file_info_get_display_name (file_data->info)); current_file_fraction = (double) self->priv->post_photos->wrote_body_data_size / msg->request_body->length; gth_task_progress (GTH_TASK (self), NULL, details, FALSE, (double) (self->priv->post_photos->uploaded_size + (g_file_info_get_size (file_data->info) * current_file_fraction)) / self->priv->post_photos->total_size); g_free (details); }
/*int*/ main (int argc, char **argv) { GFile *file; GFileInfo *info; GCancellable *cancel; time_t time; GError *error = NULL; g_type_init(); cancel = g_cancellable_new (); file = g_file_new_for_uri ("file:///home/gabriel/Imagens/jazzradio1.jpg"); info = g_file_query_info (file, "standard::*", G_FILE_QUERY_INFO_NONE, cancel, &error); guint32 xtime; xtime = g_file_info_get_attribute_uint32 (info, "time::created-usec"); GDate *date; date = g_date_new_julian (xtime); g_print ("Dia: %d\n=========", (int) g_date_get_month(date)); if (error) g_printerr ("FUDEU: %s\n", error->message); g_print ("O tamanho do arquivo eh: %d", (int) g_file_info_get_size (info)); return 0; }
static void post_photos_info_ready_cb (GList *files, GError *error, gpointer user_data) { PicasaWebService *self = user_data; GList *scan; if (error != NULL) { post_photos_done (self, error); return; } self->priv->post_photos->file_list = _g_object_list_ref (files); self->priv->post_photos->total_size = 0; self->priv->post_photos->n_files = 0; for (scan = self->priv->post_photos->file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; self->priv->post_photos->total_size += g_file_info_get_size (file_data->info); self->priv->post_photos->n_files += 1; } self->priv->post_photos->current = self->priv->post_photos->file_list; picasa_wev_service_post_current_file (self); }
static void iterate_contacts (TpChannel *channel, GArray *handles, char **argv) { GError *error = NULL; int i; for (i = 0; i < handles->len; i++) { int handle = g_array_index (handles, int, i); /* FIXME: we should check that our client has the * FT capability */ /* begin ex.filetransfer.sending.gfileinfo */ GFile *file = g_file_new_for_commandline_arg (argv[3]); GFileInfo *info = g_file_query_info (file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &error); handle_error (error); GHashTable *props = tp_asv_new ( TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT, handle, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING, g_file_info_get_display_name (info), TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING, g_file_info_get_content_type (info), TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64, g_file_info_get_size (info), NULL); tp_cli_connection_interface_requests_call_create_channel ( conn, -1, props, create_ft_channel_cb, NULL, NULL, NULL); g_hash_table_destroy (props); g_object_unref (info); g_object_unref (file); /* end ex.filetransfer.sending.gfileinfo */ } }
static void ft_handler_gfile_ready_cb (GObject *source, GAsyncResult *res, CallbacksData *cb_data) { GFileInfo *info; GError *error = NULL; GTimeVal mtime; EmpathyFTHandlerPriv *priv = GET_PRIV (cb_data->handler); DEBUG ("Got GFileInfo."); info = g_file_query_info_finish (priv->gfile, res, &error); if (error != NULL) goto out; if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR) { error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK, EMPATHY_FT_ERROR_INVALID_SOURCE_FILE, _("The selected file is not a regular file")); goto out; } priv->total_bytes = g_file_info_get_size (info); if (priv->total_bytes == 0) { error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK, EMPATHY_FT_ERROR_EMPTY_SOURCE_FILE, _("The selected file is empty")); goto out; } priv->content_type = g_strdup (g_file_info_get_content_type (info)); priv->filename = g_strdup (g_file_info_get_display_name (info)); g_file_info_get_modification_time (info, &mtime); priv->mtime = mtime.tv_sec; priv->transferred_bytes = 0; priv->description = NULL; g_object_unref (info); out: if (error != NULL) { if (!g_cancellable_is_cancelled (priv->cancellable)) g_cancellable_cancel (priv->cancellable); cb_data->callback (cb_data->handler, error, cb_data->user_data); g_error_free (error); callbacks_data_free (cb_data); } else { /* see if FT/hashing are allowed */ check_hashing (cb_data); } }
static gchar *readall(const gchar *path, GError **error) { GFile *f = g_file_new_for_path(path); GFileInputStream *fis = NULL; GFileInfo *info; int len; gchar *ret = NULL; if (!(info = g_file_query_info(f, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, error))) goto cleanup; len = g_file_info_get_size(info); ret = g_new0(gchar, len+1); if (!(fis = g_file_read(f, NULL, error))) goto cleanup; if (!g_input_stream_read_all(G_INPUT_STREAM(fis), ret, len, NULL, NULL, error)) goto cleanup; ret[len] = '\0'; *error = NULL; cleanup: if (*error) { g_free(ret); ret = NULL; } g_object_unref(f); if (fis) g_object_unref(fis); return ret; }
static gboolean estimate_size_visitor (GFile *file, const char *rel_path, GFileInfo *info, EstimateSizeCallbackData *data, gboolean *recurse) { if (file_info_is_image (info)) { data->image_paths = g_list_append (data->image_paths, get_backing_file (file)); } else { data->only_images = FALSE; } if (file_info_is_allowed (info)) { if (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY) { data->size += g_file_info_get_size (info); } } else { data->unreadable_paths = g_list_append (data->unreadable_paths, g_strdup (rel_path)); } *recurse = TRUE; return TRUE; }
GVariant * ostree_zlib_file_header_new (GFileInfo *file_info, GVariant *xattrs) { guint64 size; guint32 uid; guint32 gid; guint32 mode; guint32 rdev; const char *symlink_target; GVariant *ret; ot_lvariant GVariant *tmp_xattrs = NULL; size = g_file_info_get_size (file_info); uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid"); gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid"); mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode"); rdev = g_file_info_get_attribute_uint32 (file_info, "unix::rdev"); if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK) symlink_target = g_file_info_get_symlink_target (file_info); else symlink_target = ""; if (xattrs == NULL) tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0)); ret = g_variant_new ("(tuuuus@a(ayay))", GUINT64_TO_BE (size), GUINT32_TO_BE (uid), GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), GUINT32_TO_BE (rdev), symlink_target, xattrs ? xattrs : tmp_xattrs); g_variant_ref_sink (ret); return ret; }
static void gimp_image_prop_view_label_set_filesize (GtkWidget *label, GimpImage *image) { GFile *file = gimp_image_get_any_file (image); if (file) { GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { goffset size = g_file_info_get_size (info); gchar *str = g_format_size (size); gtk_label_set_text (GTK_LABEL (label), str); g_free (str); g_object_unref (info); } else { gtk_label_set_text (GTK_LABEL (label), NULL); } } else { gtk_label_set_text (GTK_LABEL (label), NULL); } }
GwgetData * gwget_data_create(gchar *url, gchar *dir) { GwgetData *gwgetdata; GFile *file; GFileInfo *info; gint length; GError *err = NULL; g_return_val_if_fail(url != NULL, NULL); g_return_val_if_fail(dir != NULL, NULL); g_return_val_if_fail(gwget_pref.download_dir != NULL, NULL); gwgetdata = g_new0(GwgetData,1); gwgetdata->url = g_strdup(url); gwgetdata->log_tag = -1; /* Figure out a directory to use if none given */ length = strlen (dir); if (length == 0) { dir = gwget_pref.download_dir; } /* Add a trailing '/' unless already present */ length = strlen (dir); if (dir[length - 1] == '/') gwgetdata->dir = g_strdup (dir); else gwgetdata->dir = g_strconcat (dir, "/", NULL); gwget_data_set_filename_from_url(gwgetdata,gwgetdata->url); gwget_data_set_filename(gwgetdata,gwgetdata->filename); file = g_file_new_for_path (gwgetdata->local_filename); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, &err); if (err==NULL) { gwgetdata->cur_size = g_file_info_get_size (info); } else { gwgetdata->cur_size = 0; g_error_free (err); } gwgetdata->line = NULL; gwgetdata->session_start_time = 0; gwgetdata->session_start_size = 0; gwgetdata->session_elapsed = 0; gwgetdata->state = DL_NOT_STARTED; gwgetdata->total_size = 0; gwgetdata->total_time = 0; gwgetdata->recursive=FALSE; gwgetdata->multimedia=FALSE; gwgetdata->mirror=FALSE; num_of_download++; return gwgetdata; }
static gpointer stlink_gui_populate_filemem_view (STlinkGUI *gui) { guchar buffer[MEM_READ_SIZE]; GFile *file; GFileInfo *file_info; GInputStream *input_stream; gint off; GError *err = NULL; g_return_val_if_fail (gui != NULL, NULL); g_return_val_if_fail (gui->filename != NULL, NULL); file = g_file_new_for_path (gui->filename); input_stream = G_INPUT_STREAM (g_file_read (file, NULL, &err)); if (err) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out; } file_info = g_file_input_stream_query_info (G_FILE_INPUT_STREAM (input_stream), G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &err); if (err) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out_input; } if (gui->file_mem.memory) { g_free (gui->file_mem.memory); } gui->file_mem.size = g_file_info_get_size (file_info); gui->file_mem.memory = g_malloc (gui->file_mem.size); for (off = 0; off < gui->file_mem.size; off += MEM_READ_SIZE) { guint n_read = MEM_READ_SIZE; if (off + MEM_READ_SIZE > gui->file_mem.size) { n_read = gui->file_mem.size - off; } if (g_input_stream_read (G_INPUT_STREAM (input_stream), &buffer, n_read, NULL, &err) == -1) { stlink_gui_set_info_error_message (gui, err->message); g_error_free (err); goto out_input; } memcpy (gui->file_mem.memory + off, buffer, n_read); gui->progress.fraction = (gdouble) (off + n_read) / gui->file_mem.size; } g_idle_add ((GSourceFunc) stlink_gui_update_filemem_view, gui); out_input: g_object_unref (input_stream); out: g_object_unref (file); return NULL; }
/* * et_opus_read_file_info: * @file: file to read info from * @ETFileInfo: ET_File_Info to put information into * @error: a GError or %NULL * * Read header information of an Opus file. * * Returns: %TRUE if successful otherwise %FALSE */ gboolean et_opus_read_file_info (GFile *gfile, ET_File_Info *ETFileInfo, GError **error) { OggOpusFile *file; const OpusHead* head; GFileInfo *info; g_return_val_if_fail (gfile != NULL && ETFileInfo != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); file = et_opus_open_file (gfile, error); if (!file) { g_assert (error == NULL || *error != NULL); return FALSE; } /* FIXME: Improve error-checking. */ head = op_head (file, -1); /* TODO: Read the vendor string from the Vorbis comment? */ ETFileInfo->version = head->version; ETFileInfo->bitrate = op_bitrate (file, -1) / 1000; ETFileInfo->mode = head->channel_count; /* All Opus audio is encoded at 48 kHz, but the input sample rate can * differ, and then input_sample_rate will be set. */ if (head->input_sample_rate != 0) { ETFileInfo->samplerate = head->input_sample_rate; } else { ETFileInfo->samplerate = 48000; } ETFileInfo->duration = op_pcm_total (file, -1) / 48000; op_free (file); info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info) { ETFileInfo->size = g_file_info_get_size (info); g_object_unref (info); } else { ETFileInfo->size = 0; } g_assert (error == NULL || *error == NULL); return TRUE; }
/* * et_picture_load_file_data: * @file: the GFile from which to load an image * @error: a #GError to provide information on errors, or %NULL to ignore * * Load an image from the supplied @file. * * Returns: an image on success, %NULL otherwise */ static Picture * et_picture_load_file_data (GFile *file, GError **error) { Picture *pic; gchar *buffer = NULL; gsize size; gsize bytes_read; GFileInfo *info; GFileInputStream *file_istream; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); if (!info) { g_assert (error == NULL || *error != NULL); return NULL; } file_istream = g_file_read (file, NULL, error); if (!file_istream) { g_assert (error == NULL || *error != NULL); return NULL; } size = g_file_info_get_size (info); buffer = g_malloc (size); g_object_unref (info); if (!g_input_stream_read_all (G_INPUT_STREAM (file_istream), buffer, size, &bytes_read, NULL, error)) { g_free (buffer); g_debug ("Only %" G_GSIZE_FORMAT " bytes out of %" G_GSIZE_FORMAT " bytes of picture data were read", bytes_read, size); g_object_unref (file_istream); g_assert (error == NULL || *error != NULL); return NULL; } else { /* Image loaded. */ pic = Picture_Allocate(); pic->size = size; pic->data = (guchar *)buffer; g_object_unref (file_istream); g_assert (error == NULL || *error == NULL); return pic; } }
goffset rstto_file_get_size (RsttoFile *r_file ) { goffset size = 0; GFileInfo *file_info = g_file_query_info (r_file->priv->file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); size = g_file_info_get_size ( file_info ); g_object_unref (file_info); return size; }
static void show_info (GFileInfo *info) { const char *name, *type; goffset size; char **attributes; int i; gboolean first_attr; if ((g_file_info_get_is_hidden (info)) && !show_hidden) return; name = g_file_info_get_name (info); if (name == NULL) name = ""; size = g_file_info_get_size (info); type = type_to_string (g_file_info_get_file_type (info)); if (show_long) g_print ("%s\t%"G_GUINT64_FORMAT"\t(%s)", name, (guint64)size, type); else g_print ("%s", name); first_attr = TRUE; attributes = g_file_info_list_attributes (info, NULL); for (i = 0 ; attributes[i] != NULL; i++) { char *val_as_string; if (!show_long || strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_NAME) == 0 || strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_SIZE) == 0 || strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_TYPE) == 0 || strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) == 0) continue; if (first_attr) { g_print ("\t"); first_attr = FALSE; } else g_print (" "); val_as_string = g_file_info_get_attribute_as_string (info, attributes[i]); g_print ("%s=%s", attributes[i], val_as_string); g_free (val_as_string); } g_strfreev (attributes); g_print ("\n"); }
// Prüfen, ob die Ziel-Datei bereits vorhanden ist // Vergleicht auch die Dateigrössen gboolean exist_target (const gchar *target, const gchar *source) { GFile *file_target; file_target = g_file_new_for_path (target); if (g_file_query_exists (file_target, NULL)) { GFile *file_source; GFileInfo *info_target, *info_source; file_source = g_file_new_for_path (source); info_target = g_file_query_info (file_target, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_CREATE_NONE, NULL, NULL); info_source = g_file_query_info (file_source, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_CREATE_NONE, NULL, NULL); if (g_file_info_get_size (info_target) == g_file_info_get_size (info_source)) { return TRUE; } } return FALSE; }
static void upload_photo_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { FacebookService *self = user_data; SoupBuffer *body; DomDocument *doc = NULL; GError *error = NULL; GthFileData *file_data; if (msg->status_code != 200) { GError *error; error = g_error_new_literal (SOUP_HTTP_ERROR, msg->status_code, soup_status_get_phrase (msg->status_code)); upload_photos_done (self, error); g_error_free (error); return; } body = soup_message_body_flatten (msg->response_body); if (facebook_utils_parse_response (body, &doc, &error)) { DomElement *node; /* save the photo id */ for (node = DOM_ELEMENT (doc)->first_child; node; node = node->next_sibling) { if (g_strcmp0 (node->tag_name, "pid") == 0) { const char *id; id = dom_element_get_inner_text (node); self->priv->post_photos->ids = g_list_prepend (self->priv->post_photos->ids, g_strdup (id)); } } g_object_unref (doc); } else { soup_buffer_free (body); upload_photos_done (self, error); return; } soup_buffer_free (body); file_data = self->priv->post_photos->current->data; self->priv->post_photos->uploaded_size += g_file_info_get_size (file_data->info); self->priv->post_photos->current = self->priv->post_photos->current->next; facebook_service_upload_current_file (self); }
gssize media_size (gchar *path) { GFile *gfile; GFileInfo *ginfo; GError *err = NULL; goffset size; gfile = g_file_new_for_path (path); ginfo = g_file_query_info (gfile, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err); size = g_file_info_get_size (ginfo); g_object_unref (gfile); return size; }
static GInputStream * webkit_soup_request_file_send (WebKitSoupRequest *request, GCancellable *cancellable, GError **error) { WebKitSoupRequestFile *file = WEBKIT_SOUP_REQUEST_FILE (request); GInputStream *stream; GError *my_error = NULL; if (!webkit_soup_request_file_ensure_file (file, cancellable, error)) return NULL; stream = G_INPUT_STREAM (g_file_read (file->priv->gfile, cancellable, &my_error)); if (stream == NULL) { if (g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY)) { GFileEnumerator *enumerator; g_clear_error (&my_error); enumerator = g_file_enumerate_children (file->priv->gfile, "*", G_FILE_QUERY_INFO_NONE, cancellable, error); if (enumerator) { stream = webkit_soup_directory_input_stream_new (enumerator, webkit_soup_request_get_uri (request)); g_object_unref (enumerator); file->priv->mime_type = g_strdup ("text/html"); } } else { g_propagate_error (error, my_error); } } else { GFileInfo *info = g_file_query_info (file->priv->gfile, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, cancellable, NULL); if (info) { const char *content_type; file->priv->size = g_file_info_get_size (info); content_type = g_file_info_get_content_type (info); if (content_type) file->priv->mime_type = g_content_type_get_mime_type (content_type); g_object_unref (info); } } return stream; }
gboolean ostree_raw_file_to_content_stream (GInputStream *input, GFileInfo *file_info, GVariant *xattrs, GInputStream **out_input, guint64 *out_length, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gpointer header_data; gsize header_size; ot_lobj GInputStream *ret_input = NULL; ot_lvariant GVariant *file_header = NULL; ot_lptrarray GPtrArray *streams = NULL; ot_lobj GOutputStream *header_out_stream = NULL; ot_lobj GInputStream *header_in_stream = NULL; file_header = ostree_file_header_new (file_info, xattrs); header_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); if (!ostree_write_variant_with_size (header_out_stream, file_header, 0, NULL, NULL, cancellable, error)) goto out; if (!g_output_stream_close (header_out_stream, cancellable, error)) goto out; header_size = g_memory_output_stream_get_data_size ((GMemoryOutputStream*) header_out_stream); header_data = g_memory_output_stream_steal_data ((GMemoryOutputStream*) header_out_stream); header_in_stream = g_memory_input_stream_new_from_data (header_data, header_size, g_free); streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); g_ptr_array_add (streams, g_object_ref (header_in_stream)); if (input) g_ptr_array_add (streams, g_object_ref (input)); ret_input = (GInputStream*)ostree_chain_input_stream_new (streams); ret = TRUE; ot_transfer_out_value (out_input, &ret_input); if (out_length) *out_length = header_size + g_file_info_get_size (file_info); out: return ret; }
/** * gsf_input_gio_new: * @file: * @err: optionally NULL. * * Returns: A new #GsfInputGio or NULL */ GsfInput * gsf_input_gio_new (GFile *file, GError **err) { GsfInputGio *input; GInputStream *stream; gsf_off_t filesize; g_return_val_if_fail (file != NULL, NULL); stream = (GInputStream *)g_file_read (file, NULL, err); if (stream == NULL) return NULL; if (!can_seek (stream)) return make_local_copy (file, stream); { GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); if (!info) return make_local_copy (file, stream); filesize = g_file_info_get_size (info); g_object_unref (info); } input = g_object_new (GSF_INPUT_GIO_TYPE, NULL); if (G_UNLIKELY (NULL == input)) { g_input_stream_close (stream, NULL, NULL); g_object_unref (stream); return NULL; } gsf_input_set_size (GSF_INPUT (input), filesize); g_object_ref (file); input->stream = stream; input->file = file; input->buf = NULL; input->buf_size = 0; set_name_from_file (GSF_INPUT (input), file); return GSF_INPUT (input); }
/** * gsf_input_gio_new: * @file: * @err: (allow-none): place to store a #GError if anything goes wrong * * Returns: A new #GsfInputGio or %NULL */ GsfInput * gsf_input_gio_new (GFile *file, GError **err) { GsfInputGio *input; GInputStream *stream; gsf_off_t filesize; g_return_val_if_fail (file != NULL, NULL); stream = (GInputStream *)g_file_read (file, NULL, err); if (stream == NULL) return NULL; if (1) { /* see https://bugzilla.gnome.org/show_bug.cgi?id=724970 */ return make_local_copy (file, stream); } if (!can_seek (stream)) return make_local_copy (file, stream); { GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); if (!info) return make_local_copy (file, stream); filesize = g_file_info_get_size (info); g_object_unref (info); } input = g_object_new (GSF_INPUT_GIO_TYPE, NULL); gsf_input_set_size (GSF_INPUT (input), filesize); g_object_ref (file); input->stream = stream; input->file = file; input->buf = NULL; input->buf_size = 0; set_name_from_file (GSF_INPUT (input), file); return GSF_INPUT (input); }
ChupaData * chupa_data_new_from_file(GFile *file, ChupaMetadata *metadata, GError **error) { ChupaData *data; GInputStream *stream; GFileInfo *info; stream = G_INPUT_STREAM(g_file_read(file, NULL, error)); if (!stream) return NULL; if (!metadata) metadata = chupa_metadata_new(); info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); if (info) { chupa_metadata_set_content_length(metadata, g_file_info_get_size(info)); g_object_unref(info); } info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL); if (info) { chupa_metadata_set_string(metadata, meta_filename, g_file_info_get_display_name(info)); g_object_unref(info); } if (!chupa_metadata_get_path(metadata)) { gchar *path; path = g_file_get_path(file); if (path) { chupa_metadata_set_path(metadata, path); g_free(path); } } data = chupa_data_new(stream, metadata); g_object_unref(stream); g_object_unref(metadata); return data; }
static void gtkhash_hash_file_get_size_finish( G_GNUC_UNUSED GObject *source, GAsyncResult *res, struct hash_file_s *data) { GFileInfo *info = g_file_input_stream_query_info_finish( data->stream, res, NULL); data->file_size = g_file_info_get_size(info); g_object_unref(info); if (G_UNLIKELY(g_cancellable_is_cancelled(data->cancellable))) gtkhash_hash_file_set_state(data, HASH_FILE_STATE_CLOSE); else if (data->file_size == 0) gtkhash_hash_file_set_state(data, HASH_FILE_STATE_HASH); else { gtkhash_hash_file_set_state(data, HASH_FILE_STATE_READ); gtkhash_hash_file_add_report_source(data); } gtkhash_hash_file_add_source(data); }