static void trash_backend_add_info (TrashItem *item, GFileInfo *info, gboolean is_toplevel) { if (is_toplevel) { const gchar *delete_date; GFile *original, *real; g_assert (item != NULL); original = trash_item_get_original (item); if (original) { gchar *edit_name, *path; path = g_file_get_path (original); edit_name = gvfs_file_info_populate_names_as_local (info, path); g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH, path); g_free (edit_name); g_free (path); } real = trash_item_get_file (item); if (real) { char *uri; uri = g_file_get_uri (real); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, uri); g_free (uri); } delete_date = trash_item_get_delete_date (item); if (delete_date) g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_TRASH_DELETION_DATE, delete_date); } g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH, FALSE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, is_toplevel); }
static void parse_xml_node (GFile *file, xmlNodePtr filenode) { xmlNodePtr node; xmlAttrPtr attr; xmlChar *property; const char *new_key; GHashTable *list_keys; GList *keys, *l; GHashTableIter iter; GFileInfo *info; int i; char **strv; GError *error; info = g_file_info_new (); for (attr = filenode->properties; attr != NULL; attr = attr->next) { if (strcmp ((char *)attr->name, "name") == 0 || strcmp ((char *)attr->name, "timestamp") == 0) { continue; } new_key = convert_key_name (attr->name); if (new_key) { property = xmlGetProp (filenode, attr->name); if (property) { g_file_info_set_attribute_string (info, new_key, property); xmlFree (property); } } } list_keys = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); for (node = filenode->children; node != NULL; node = node->next) { for (attr = node->properties; attr != NULL; attr = attr->next) { new_key = convert_key_name (node->name); if (new_key) { property = xmlGetProp (node, attr->name); if (property) { keys = g_hash_table_lookup (list_keys, new_key); keys = g_list_append (keys, property); g_hash_table_replace (list_keys, (char *)new_key, keys); } } } } g_hash_table_iter_init (&iter, list_keys); while (g_hash_table_iter_next (&iter, (void **)&new_key, (void **)&keys)) { strv = g_new0 (char *, g_list_length (keys) + 1); for (l = keys, i = 0; l != NULL; l = l->next, i++) { strv[i] = l->data; } g_file_info_set_attribute_stringv (info, new_key, strv); g_free (strv); g_list_foreach (keys, (GFunc)xmlFree, NULL); g_list_free (keys); } g_hash_table_destroy (list_keys); if (info) { error = NULL; if (!g_file_set_attributes_from_info (file, info, 0, NULL, &error)) { char *uri; uri = g_file_get_uri (file); if (!quiet) { g_print ("error setting info for %s: %s\n", uri, error->message); } g_free (uri); g_error_free (error); } g_object_unref (info); } }
static void file_info_from_message (SoupMessage *msg, GFileInfo *info, GFileAttributeMatcher *matcher) { const char *text; GHashTable *params; char *basename; char *ed_name; basename = ed_name = NULL; /* prefer the filename from the Content-Disposition (rfc2183) header if one if present. See bug 551298. */ if (soup_message_headers_get_content_disposition (msg->response_headers, NULL, ¶ms)) { const char *name = g_hash_table_lookup (params, "filename"); if (name) basename = g_strdup (name); g_hash_table_destroy (params); } if (basename == NULL) { const SoupURI *uri; uri = soup_message_get_uri (msg); basename = http_uri_get_basename (uri->path); } g_debug ("basename:%s\n", basename); /* read http/1.1 rfc, until then we copy the local files * behaviour */ if (basename != NULL && (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME))) ed_name = gvfs_file_info_populate_names_as_local (info, basename); g_free (basename); g_free (ed_name); if (soup_message_headers_get_encoding (msg->response_headers) == SOUP_ENCODING_CONTENT_LENGTH) { goffset start, end, length; gboolean ret; ret = soup_message_headers_get_content_range (msg->response_headers, &start, &end, &length); if (ret && length != -1) { g_file_info_set_size (info, length); } else if (!ret) { length = soup_message_headers_get_content_length (msg->response_headers); g_file_info_set_size (info, length); } } g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); text = soup_message_headers_get_content_type (msg->response_headers, NULL); if (text) { GIcon *icon; g_file_info_set_content_type (info, text); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, text); icon = g_content_type_get_icon (text); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_content_type_get_symbolic_icon (text); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } text = soup_message_headers_get_one (msg->response_headers, "Last-Modified"); if (text) { SoupDate *sd; GTimeVal tv; sd = soup_date_new_from_string(text); if (sd) { soup_date_to_timeval (sd, &tv); g_file_info_set_modification_time (info, &tv); soup_date_free (sd); } } text = soup_message_headers_get_one (msg->response_headers, "ETag"); if (text) { g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ETAG_VALUE, text); } }
static gboolean rotation_plugin_store_state_co (RotationPluginStoreStateData* _data_) { switch (_data_->_state_) { case 0: goto _state_0; case 1: goto _state_1; case 2: goto _state_2; default: g_assert_not_reached (); } _state_0: _data_->_tmp0_ = NULL; g_object_get ((PeasActivatable*) _data_->self, "object", &_data_->_tmp0_, NULL); _data_->_tmp1_ = NULL; _data_->_tmp1_ = _data_->_tmp0_; _data_->t = G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp1_, totem_object_get_type (), TotemObject); _data_->_tmp2_ = NULL; _data_->_tmp2_ = _data_->t; _data_->_tmp3_ = NULL; _data_->_tmp3_ = totem_object_get_current_mrl (_data_->_tmp2_); _data_->mrl = _data_->_tmp3_; _data_->_tmp4_ = NULL; _data_->_tmp4_ = _data_->mrl; if (_data_->_tmp4_ == NULL) { _g_free0 (_data_->mrl); _g_object_unref0 (_data_->t); if (_data_->_state_ == 0) { g_simple_async_result_complete_in_idle (_data_->_async_result); } else { g_simple_async_result_complete (_data_->_async_result); } g_object_unref (_data_->_async_result); return FALSE; } _data_->_tmp5_ = NULL; _data_->_tmp5_ = _data_->mrl; _data_->_tmp6_ = NULL; _data_->_tmp6_ = g_file_new_for_uri (_data_->_tmp5_); _data_->file = _data_->_tmp6_; { _data_->_tmp7_ = NULL; _data_->_tmp7_ = _data_->file; _data_->_state_ = 1; g_file_query_info_async (_data_->_tmp7_, GIO_ROTATION_FILE_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, rotation_plugin_store_state_ready, _data_); return FALSE; _state_1: _data_->_tmp8_ = NULL; _data_->_tmp8_ = g_file_query_info_finish (_data_->_tmp7_, _data_->_res_, &_data_->_inner_error_); _data_->file_info = _data_->_tmp8_; if (G_UNLIKELY (_data_->_inner_error_ != NULL)) { if (g_error_matches (_data_->_inner_error_, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) { goto __catch0_g_io_error_not_supported; } goto __catch0_g_error; } _data_->_tmp9_ = NULL; _data_->_tmp9_ = g_strdup (""); _data_->state_str = _data_->_tmp9_; _data_->_tmp10_ = NULL; _data_->_tmp10_ = _data_->self->priv->bvw; _data_->_tmp11_ = 0; _data_->_tmp11_ = bacon_video_widget_get_rotation (_data_->_tmp10_); _data_->rotation = _data_->_tmp11_; _data_->_tmp12_ = 0; _data_->_tmp12_ = _data_->rotation; if (_data_->_tmp12_ != BVW_ROTATION_R_ZERO) { _data_->_tmp13_ = 0; _data_->_tmp13_ = _data_->rotation; _data_->_tmp14_ = NULL; _data_->_tmp14_ = g_strdup_printf ("%u", (guint) _data_->_tmp13_); _g_free0 (_data_->state_str); _data_->state_str = _data_->_tmp14_; } _data_->_tmp15_ = NULL; _data_->_tmp15_ = _data_->file_info; _data_->_tmp16_ = NULL; _data_->_tmp16_ = _data_->state_str; g_file_info_set_attribute_string (_data_->_tmp15_, GIO_ROTATION_FILE_ATTRIBUTE, _data_->_tmp16_); _data_->_tmp17_ = NULL; _data_->_tmp17_ = _data_->file; _data_->_tmp18_ = NULL; _data_->_tmp18_ = _data_->file_info; _data_->_state_ = 2; g_file_set_attributes_async (_data_->_tmp17_, _data_->_tmp18_, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, rotation_plugin_store_state_ready, _data_); return FALSE; _state_2: g_file_set_attributes_finish (_data_->_tmp17_, _data_->_res_, NULL, &_data_->_inner_error_); if (G_UNLIKELY (_data_->_inner_error_ != NULL)) { _g_free0 (_data_->state_str); _g_object_unref0 (_data_->file_info); if (g_error_matches (_data_->_inner_error_, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) { goto __catch0_g_io_error_not_supported; } goto __catch0_g_error; } _g_free0 (_data_->state_str); _g_object_unref0 (_data_->file_info); } goto __finally0; __catch0_g_io_error_not_supported: { _data_->e = _data_->_inner_error_; _data_->_inner_error_ = NULL; _g_error_free0 (_data_->e); } goto __finally0; __catch0_g_error: { _data_->_vala1_e = _data_->_inner_error_; _data_->_inner_error_ = NULL; _data_->_tmp19_ = NULL; _data_->_tmp19_ = _data_->_vala1_e; _data_->_tmp20_ = NULL; _data_->_tmp20_ = _data_->_tmp19_->message; g_warning ("totem-rotation-plugin.vala:156: Could not store file attribute: %s", _data_->_tmp20_); _g_error_free0 (_data_->_vala1_e); } __finally0: if (G_UNLIKELY (_data_->_inner_error_ != NULL)) { _g_object_unref0 (_data_->file); _g_free0 (_data_->mrl); _g_object_unref0 (_data_->t); g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code); g_clear_error (&_data_->_inner_error_); return FALSE; } _g_object_unref0 (_data_->file); _g_free0 (_data_->mrl); _g_object_unref0 (_data_->t); if (_data_->_state_ == 0) { g_simple_async_result_complete_in_idle (_data_->_async_result); } else { g_simple_async_result_complete (_data_->_async_result); } g_object_unref (_data_->_async_result); return FALSE; }
GFileInfo * gvfs_file_info_demarshal (char *data, gsize size) { guint32 num_attrs, i; GInputStream *memstream; GDataInputStream *in; GFileInfo *info; char *attr, *str, **strv; GFileAttributeType type; GFileAttributeStatus status; GObject *obj; int objtype; memstream = g_memory_input_stream_new_from_data (data, size, NULL); in = g_data_input_stream_new (memstream); g_object_unref (memstream); info = g_file_info_new (); num_attrs = g_data_input_stream_read_uint32 (in, NULL, NULL); for (i = 0; i < num_attrs; i++) { attr = read_string (in); type = g_data_input_stream_read_byte (in, NULL, NULL); status = g_data_input_stream_read_byte (in, NULL, NULL); switch (type) { case G_FILE_ATTRIBUTE_TYPE_STRING: str = read_string (in); g_file_info_set_attribute_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: str = read_string (in); g_file_info_set_attribute_byte_string (info, attr, str); g_free (str); break; case G_FILE_ATTRIBUTE_TYPE_STRINGV: strv = read_stringv (in); g_file_info_set_attribute_stringv (info, attr, strv); g_strfreev (strv); break; case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: g_file_info_set_attribute_boolean (info, attr, g_data_input_stream_read_byte (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT32: g_file_info_set_attribute_uint32 (info, attr, g_data_input_stream_read_uint32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT32: g_file_info_set_attribute_int32 (info, attr, g_data_input_stream_read_int32 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_UINT64: g_file_info_set_attribute_uint64 (info, attr, g_data_input_stream_read_uint64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_INT64: g_file_info_set_attribute_int64 (info, attr, g_data_input_stream_read_int64 (in, NULL, NULL)); break; case G_FILE_ATTRIBUTE_TYPE_OBJECT: objtype = g_data_input_stream_read_byte (in, NULL, NULL); obj = NULL; if (objtype == 1) { char *icon_str; icon_str = read_string (in); obj = (GObject *)g_icon_new_for_string (icon_str, NULL); g_free (icon_str); } else { g_warning ("Unsupported GFileInfo object type %d\n", objtype); g_free (attr); goto out; } g_file_info_set_attribute_object (info, attr, obj); if (obj) g_object_unref (obj); break; case G_FILE_ATTRIBUTE_TYPE_INVALID: break; default: g_warning ("Unsupported GFileInfo attribute type %d\n", type); g_free (attr); goto out; break; } g_file_info_set_attribute_status (info, attr, status); g_free (attr); } out: g_object_unref (in); return info; }
static void gth_metadata_provider_image_read (GthMetadataProvider *self, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { gboolean format_recognized; GFileInputStream *stream; char *description = NULL; int width; int height; const char *mime_type = NULL; format_recognized = FALSE; stream = g_file_read (file_data->file, cancellable, NULL); if (stream != NULL) { int buffer_size; guchar *buffer; gssize size; buffer_size = BUFFER_SIZE; buffer = g_new (guchar, buffer_size); size = g_input_stream_read (G_INPUT_STREAM (stream), buffer, buffer_size, cancellable, NULL); if (size >= 0) { if ((size >= 24) /* PNG signature */ && (buffer[0] == 0x89) && (buffer[1] == 0x50) && (buffer[2] == 0x4E) && (buffer[3] == 0x47) && (buffer[4] == 0x0D) && (buffer[5] == 0x0A) && (buffer[6] == 0x1A) && (buffer[7] == 0x0A) /* IHDR Image header */ && (buffer[12] == 0x49) && (buffer[13] == 0x48) && (buffer[14] == 0x44) && (buffer[15] == 0x52)) { /* PNG */ width = (buffer[16] << 24) + (buffer[17] << 16) + (buffer[18] << 8) + buffer[19]; height = (buffer[20] << 24) + (buffer[21] << 16) + (buffer[22] << 8) + buffer[23]; description = _("PNG"); mime_type = "image/png"; format_recognized = TRUE; } #if HAVE_LIBJPEG else if ((size >= 4) && (buffer[0] == 0xff) && (buffer[1] == 0xd8) && (buffer[2] == 0xff)) { /* JPEG */ GthTransform orientation; if (g_seekable_can_seek (G_SEEKABLE (stream))) { g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, cancellable, NULL); } else { g_object_unref (stream); stream = g_file_read (file_data->file, cancellable, NULL); } if (_jpeg_get_image_info (G_INPUT_STREAM (stream), &width, &height, &orientation, cancellable, NULL)) { description = _("JPEG"); mime_type = "image/jpeg"; format_recognized = TRUE; if ((orientation == GTH_TRANSFORM_ROTATE_90) || (orientation == GTH_TRANSFORM_ROTATE_270) || (orientation == GTH_TRANSFORM_TRANSPOSE) || (orientation == GTH_TRANSFORM_TRANSVERSE)) { int tmp = width; width = height; height = tmp; } } } #endif /* HAVE_LIBJPEG */ #if HAVE_LIBWEBP else if ((size > 15) && (memcmp (buffer + 8, "WEBPVP8", 7) == 0)) { WebPDecoderConfig config; if (WebPInitDecoderConfig (&config)) { if (WebPGetFeatures (buffer, buffer_size, &config.input) == VP8_STATUS_OK) { width = config.input.width; height = config.input.height; description = _("WebP"); mime_type = "image/webp"; format_recognized = TRUE; } WebPFreeDecBuffer (&config.output); } } #endif /* HAVE_LIBWEBP */ else if ((size >= 26) && (strncmp ((char *) buffer, "gimp xcf ", 9) == 0)) { /* XCF */ GInputStream *mem_stream; GDataInputStream *data_stream; mem_stream = g_memory_input_stream_new_from_data (buffer, BUFFER_SIZE, NULL); data_stream = g_data_input_stream_new (mem_stream); g_data_input_stream_set_byte_order (data_stream, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN); if (g_seekable_seek (G_SEEKABLE (data_stream), 14, G_SEEK_SET, NULL, NULL)) { int base_type; width = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); height = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); base_type = g_data_input_stream_read_uint32 (data_stream, NULL, NULL); if (base_type == 0) description = "XCF RGB"; else if (base_type == 1) description = "XCF grayscale"; else if (base_type == 2) description = "XCF indexed"; else description = "XCF"; mime_type = "image/x-xcf"; format_recognized = TRUE; } g_object_unref (data_stream); g_object_unref (mem_stream); } } g_free (buffer); g_object_unref (stream); } if (! format_recognized) { /* use gdk_pixbuf_get_file_info */ char *filename; filename = g_file_get_path (file_data->file); if (filename != NULL) { GdkPixbufFormat *format; format = gdk_pixbuf_get_file_info (filename, &width, &height); if (format != NULL) { format_recognized = TRUE; description = gdk_pixbuf_format_get_description (format); } g_free (filename); } } if (format_recognized) { char *size; g_file_info_set_attribute_string (file_data->info, "general::format", description); g_file_info_set_attribute_int32 (file_data->info, "image::width", width); g_file_info_set_attribute_int32 (file_data->info, "image::height", height); g_file_info_set_attribute_int32 (file_data->info, "frame::width", width); g_file_info_set_attribute_int32 (file_data->info, "frame::height", height); if (mime_type != NULL) gth_file_data_set_mime_type (file_data, mime_type); size = g_strdup_printf (_("%d × %d"), width, height); g_file_info_set_attribute_string (file_data->info, "general::dimensions", size); g_free (size); } }
void ss__gth_catalog_write_metadata (GthCatalog *catalog, GthFileData *file_data) { if (g_value_hash_is_set (catalog->attributes, "slideshow::personalize")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::personalize", g_value_hash_get_boolean (catalog->attributes, "slideshow::personalize")); g_file_info_set_attribute_status (file_data->info, "slideshow::personalize", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::automatic")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::automatic", g_value_hash_get_boolean (catalog->attributes, "slideshow::automatic")); g_file_info_set_attribute_status (file_data->info, "slideshow::automatic", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::wrap-around")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::wrap-around", g_value_hash_get_boolean (catalog->attributes, "slideshow::wrap-around")); g_file_info_set_attribute_status (file_data->info, "slideshow::wrap-around", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::random-order")) { g_file_info_set_attribute_boolean (file_data->info, "slideshow::random-order", g_value_hash_get_boolean (catalog->attributes, "slideshow::random-order")); g_file_info_set_attribute_status (file_data->info, "slideshow::random-order", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::delay")) { g_file_info_set_attribute_int32 (file_data->info, "slideshow::delay", g_value_hash_get_int (catalog->attributes, "slideshow::delay")); g_file_info_set_attribute_status (file_data->info, "slideshow::delay", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::transition")) { g_file_info_set_attribute_string (file_data->info, "slideshow::transition", g_value_hash_get_string (catalog->attributes, "slideshow::transition")); g_file_info_set_attribute_status (file_data->info, "slideshow::transition", G_FILE_ATTRIBUTE_STATUS_SET); } if (g_value_hash_is_set (catalog->attributes, "slideshow::playlist")) { g_file_info_set_attribute_stringv (file_data->info, "slideshow::playlist", g_value_hash_get_stringv (catalog->attributes, "slideshow::playlist")); g_file_info_set_attribute_status (file_data->info, "slideshow::playlist", G_FILE_ATTRIBUTE_STATUS_SET); } }
static gboolean convert_file (ConvertData *data) { GFile *file; DocItem *item; const gchar *uri; xmlNodePtr node; xmlNodePtr cur; gint total, current; gchar *text; if (!data->current) return FALSE; item = (DocItem *) data->current->data; uri = (const gchar *)item->uri; node = item->cur; data->current = g_list_next (data->current); /* Update progress information */ total = g_list_length (data->items); current = ++(data->n_item); text = g_strdup_printf (_("Converting %s"), uri); gtk_label_set_text (GTK_LABEL (data->label), text); g_free (text); text = g_strdup_printf (_("%d of %d documents converted"), current, total); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (data->progress), text); g_free (text); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data->progress), (gdouble)(current - 1) / total); file = g_file_new_for_uri (uri); if (!g_file_query_exists (file, NULL)) { g_printerr ("Uri %s does not exist\n", uri); g_object_unref (file); return data->current != NULL; } for (cur = node->xmlChildrenNode; cur != NULL; cur = cur->next) { xmlChar *key; xmlChar *value; if (xmlStrcmp (cur->name, (const xmlChar *)"entry") != 0) continue; key = xmlGetProp (cur, (const xmlChar *)"key"); value = xmlGetProp (cur, (const xmlChar *)"value"); if (key && value) { GFileInfo *info; gchar *gio_key; GError *error = NULL; info = g_file_info_new (); gio_key = g_strconcat (EV_METADATA_NAMESPACE"::", key, NULL); g_file_info_set_attribute_string (info, gio_key, (const gchar *)value); g_free (gio_key); if (!g_file_set_attributes_from_info (file, info, 0, NULL, &error)) { g_printerr ("Error setting metadata for %s: %s\n", uri, error->message); g_error_free (error); } g_object_unref (info); } if (key) xmlFree (key); if (value) xmlFree (value); } g_object_unref (file); return data->current != NULL; }
static gboolean g_vfs_ftp_dir_cache_funcs_process (GInputStream * stream, int debug_id, const GVfsFtpFile * dir, GVfsFtpDirCacheEntry *entry, gboolean is_unix, GCancellable * cancellable, GError ** error) { struct list_state state = { NULL, }; GDataInputStream *data; GFileInfo *info; int type; GVfsFtpFile *file; char *line, *s; gsize length; /* protect against code reorg - in current code, error never is NULL */ g_assert (error != NULL); g_assert (*error == NULL); data = g_data_input_stream_new (stream); /* we use LF only, because the mozilla code can handle lines ending in CR */ g_data_input_stream_set_newline_type (data, G_DATA_STREAM_NEWLINE_TYPE_LF); while ((line = g_data_input_stream_read_line (data, &length, cancellable, error))) { struct list_result result = { 0, }; GFileType file_type = G_FILE_TYPE_UNKNOWN; GTimeVal tv = { 0, 0 }; /* strip trailing \r - ParseFTPList only removes it if the line ends in \r\n, * but we stripped the \n already. */ if (length > 0 && line[length - 1] == '\r') line[--length] = '\0'; g_debug ("<<%2d << %s\n", debug_id, line); type = ParseFTPList (line, &state, &result); if (type != 'd' && type != 'f' && type != 'l') { g_free (line); continue; } /* don't list . and .. directories * Let's hope they're not important files on some ftp servers */ if (result.fe_fnlen == 1 && result.fe_fname[0] == '.') { g_free (line); continue; } if (result.fe_fnlen == 2 && result.fe_fname[0] == '.' && result.fe_fname[1] == '.') { g_free (line); continue; } s = g_strndup (result.fe_fname, result.fe_fnlen); file = g_vfs_ftp_file_new_child (dir, s, NULL); g_free (s); if (file == NULL) { g_debug ("# invalid filename, skipping"); g_free (line); continue; } info = g_file_info_new (); s = g_path_get_basename (g_vfs_ftp_file_get_gvfs_path (file)); g_file_info_set_name (info, s); g_free (s); if (type == 'l') { char *link; link = g_strndup (result.fe_lname, result.fe_lnlen); g_file_info_set_symlink_target (info, link); g_file_info_set_is_symlink (info, TRUE); g_free (link); } g_file_info_set_size (info, g_ascii_strtoull (result.fe_size, NULL, 10)); /* If unix format then parse the attributes */ if (state.lstyle == 'U') { char file_mode[10], uid[64], gid[64]; guint32 mode; /* POSIX ls -l form: mode, links, owner, group */ if (sscanf(line, "%10c %*u %63s %63s", file_mode, uid, gid) == 3) { if (g_vfs_ftp_parse_mode (file_mode, &mode, &file_type)) { g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE, mode); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER, uid); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP, gid); } } else g_debug ("# unknown listing format\n"); } if (file_type == G_FILE_TYPE_UNKNOWN) { file_type = type == 'f' ? G_FILE_TYPE_REGULAR : type == 'l' ? G_FILE_TYPE_SYMBOLIC_LINK : G_FILE_TYPE_DIRECTORY; } gvfs_file_info_populate_default (info, g_vfs_ftp_file_get_gvfs_path (file), file_type); if (is_unix) g_file_info_set_is_hidden (info, result.fe_fnlen > 0 && result.fe_fname[0] == '.'); /* Workaround: * result.fetime.tm_year contains actual year instead of offset-from-1900, * which mktime expects. */ if (result.fe_time.tm_year >= 1900) result.fe_time.tm_year -= 1900; tv.tv_sec = mktime (&result.fe_time); if (tv.tv_sec != -1) g_file_info_set_modification_time (info, &tv); g_vfs_ftp_dir_cache_entry_add (entry, file, info); g_free (line); } g_object_unref (data); return *error != NULL; }