GdkPixbuf * get_file_pixbuf (GSearchWindow * gsearch, GFileInfo * file_info) { GdkPixbuf * pixbuf; GIcon * icon = NULL; const gchar * thumbnail_path = NULL; if (file_info == NULL) { return NULL; } icon = g_file_info_get_icon (file_info); if (gsearch->show_thumbnails == TRUE) { thumbnail_path = g_file_info_get_attribute_byte_string (file_info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); } if (thumbnail_path != NULL) { pixbuf = gsearchtool_get_thumbnail_image (thumbnail_path); } else { gchar * icon_string; icon_string = g_icon_to_string (icon); pixbuf = (GdkPixbuf *) g_hash_table_lookup (gsearch->search_results_filename_hash_table, icon_string); if (pixbuf == NULL) { pixbuf = get_themed_icon_pixbuf (G_THEMED_ICON (icon), ICON_SIZE, gtk_icon_theme_get_default ()); g_hash_table_insert (gsearch->search_results_filename_hash_table, g_strdup (icon_string), pixbuf); } g_free (icon_string); } return pixbuf; }
static int run_all_tests (int argc, char **argv) { GFile *dir, *file; GFileInfo *info; GFileEnumerator *children; GList *list = NULL; dir = g_file_new_for_path ("uri"); children = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL); while ((info = g_file_enumerator_next_file (children, NULL, NULL))) { const gchar *name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME); if (!g_str_has_suffix (name, ".test")) continue; list = g_list_insert_sorted (list, (gchar *) name, (GCompareFunc) strcmp); } while (list) { gchar *test_id = g_strconcat ("/", list->data, NULL); file = g_file_get_child (dir, list->data); g_test_add_data_func (test_id, file, run_test); g_free (test_id); list = g_list_delete_link (list, list); } return g_test_run (); }
static gboolean xmms_gvfs_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error) { GError *err = NULL; GFile *file; GFileInfo *info; GFileEnumerator *enumerator; /* Same hack as in _init */ if (!g_ascii_strncasecmp (url, "file://", 7)) { file = g_file_new_for_path (url+7); } else { file = g_file_new_for_uri (url); } enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err); g_object_unref (file); if (!enumerator) { xmms_error_set (error, XMMS_ERROR_GENERIC, err->message); return FALSE; } while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL))) { guint32 child_type, flags = 0; guint64 child_size; const gchar *child_name; child_name = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME); child_type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); child_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE); if (child_type & G_FILE_TYPE_DIRECTORY) { flags |= XMMS_XFORM_BROWSE_FLAG_DIR; } xmms_xform_browse_add_entry (xform, child_name, flags); if (~child_type & G_FILE_TYPE_DIRECTORY) { xmms_xform_browse_add_entry_property_int (xform, XMMS_MEDIALIB_ENTRY_PROPERTY_SIZE, child_size); } g_object_unref (info); } g_file_enumerator_close (enumerator, NULL, NULL); return TRUE; }
/** * Gets the attributes of a file * @param meta is the structure where to store meta data (attributes) of * the file * @param fileinfo is a glib structure that contains a lot of informations * about the file and from which we want to keep a few. */ static void get_file_attributes(meta_data_t *meta, GFileInfo *fileinfo) { if (meta != NULL) { meta->inode = g_file_info_get_attribute_uint64(fileinfo, G_FILE_ATTRIBUTE_UNIX_INODE); meta->owner = g_file_info_get_attribute_as_string(fileinfo, G_FILE_ATTRIBUTE_OWNER_USER); meta->group = g_file_info_get_attribute_as_string(fileinfo, G_FILE_ATTRIBUTE_OWNER_GROUP); meta->uid = g_file_info_get_attribute_uint32(fileinfo, G_FILE_ATTRIBUTE_UNIX_UID); meta->gid = g_file_info_get_attribute_uint32(fileinfo, G_FILE_ATTRIBUTE_UNIX_GID); meta->atime = g_file_info_get_attribute_uint64(fileinfo, G_FILE_ATTRIBUTE_TIME_ACCESS); meta->ctime = g_file_info_get_attribute_uint64(fileinfo, G_FILE_ATTRIBUTE_TIME_CHANGED); meta->mtime = g_file_info_get_attribute_uint64(fileinfo, G_FILE_ATTRIBUTE_TIME_MODIFIED); meta->mode = g_file_info_get_attribute_uint32(fileinfo, G_FILE_ATTRIBUTE_UNIX_MODE); meta->size = g_file_info_get_attribute_uint64(fileinfo, G_FILE_ATTRIBUTE_STANDARD_SIZE); /* Do the right things with specific cases */ if (meta->file_type == G_FILE_TYPE_SYMBOLIC_LINK) { meta->link = (gchar *) g_file_info_get_attribute_byte_string(fileinfo, G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET); } else { meta->link = g_strdup(""); } } }
static void photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpointer user_data) { PhotosBaseItem *self = PHOTOS_BASE_ITEM (user_data); PhotosBaseItemPrivate *priv = self->priv; GError *error = NULL; GFile *file = G_FILE (source_object); GFileInfo *info; info = g_file_query_info_finish (file, res, &error); if (error != NULL) { g_warning ("Unable to query info for file at %s: %s", priv->uri, error->message); priv->failed_thumbnailing = TRUE; photos_base_item_set_failed_icon (self); g_error_free (error); goto out; } priv->thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (priv->thumb_path != NULL) photos_base_item_refresh_thumb_path (self); else { photos_base_item_create_thumbnail_async (self, NULL, photos_base_item_create_thumbnail_cb, g_object_ref (file)); } out: g_object_unref (self); }
static GIcon * photos_utils_get_thumbnail_icon (const gchar *uri) { GError *error; GFile *file = NULL; GFile *thumb_file = NULL; GFileInfo *info = NULL; GIcon *icon = NULL; const gchar *thumb_path; file = g_file_new_for_uri (uri); error = NULL; info = g_file_query_info (file, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message); g_error_free (error); goto out; } thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); thumb_file = g_file_new_for_path (thumb_path); icon = g_file_icon_new (thumb_file); out: g_clear_object (&thumb_file); g_clear_object (&info); g_clear_object (&file); return icon; }
static EogThumbData* eog_thumb_data_new (GFile *file, GError **error) { EogThumbData *data; GFileInfo *file_info; GError *ioerror = NULL; g_return_val_if_fail (file != NULL, NULL); g_return_val_if_fail (error != NULL && *error == NULL, NULL); data = g_slice_new0 (EogThumbData); data->uri_str = g_file_get_uri (file); data->thumb_path = gnome_desktop_thumbnail_path_for_uri (data->uri_str, GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_TIME_MODIFIED "," G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," G_FILE_ATTRIBUTE_THUMBNAILING_FAILED "," G_FILE_ATTRIBUTE_ACCESS_CAN_READ, 0, NULL, &ioerror); if (file_info == NULL) { set_vfs_error (error, ioerror); g_clear_error (&ioerror); } if (*error == NULL) { /* if available, copy data */ data->mtime = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED); data->mime_type = g_strdup (g_file_info_get_content_type (file_info)); data->thumb_exists = (g_file_info_get_attribute_byte_string (file_info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH) != NULL); data->failed_thumb_exists = g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); data->can_read = TRUE; if (g_file_info_has_attribute (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) { data->can_read = g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ); } } else { eog_thumb_data_free (data); data = NULL; g_clear_error (&ioerror); } g_object_unref (file_info); return data; }
static char * get_backing_file (GFile *file) { char *mapping; GFileInfo *info; mapping = NULL; info = g_file_query_info (file, "burn::backing-file", 0, NULL, NULL); if (info) { mapping = g_strdup (g_file_info_get_attribute_byte_string (info, "burn::backing-file")); g_object_unref (info); } return mapping; }
static void search_results_populate (IdolTrackerWidget *widget, const gchar *uri) { GFile *file; GFileInfo *info; GError *error = NULL; file = g_file_new_for_uri (uri); info = g_file_query_info (file, "standard::display-name,thumbnail::path", G_FILE_QUERY_INFO_NONE, NULL, &error); if (error == NULL) { GtkTreeIter iter; GdkPixbuf *thumbnail = NULL; const gchar *thumbnail_path; gtk_list_store_append (GTK_LIST_STORE (widget->priv->result_store), &iter); /* Acquire an iterator */ thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumbnail_path != NULL) thumbnail = gdk_pixbuf_new_from_file (thumbnail_path, NULL); gtk_list_store_set (GTK_LIST_STORE (widget->priv->result_store), &iter, IMAGE_COLUMN, thumbnail, FILE_COLUMN, uri, NAME_COLUMN, g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME), -1); if (thumbnail != NULL) g_object_unref (thumbnail); } else { /* Display an error */ gchar *message = g_strdup_printf (_("Could not get name and thumbnail for %s: %s"), uri, error->message); idol_interface_error_blocking (_("File Error"), message, NULL); g_free (message); g_error_free (error); } g_object_unref (info); g_object_unref (file); }
static GIcon * photos_utils_get_thumbnail_icon (PhotosBaseItem *item) { g_autoptr (GFile) thumb_file = NULL; g_autoptr (GFileInfo) info = NULL; GIcon *icon = NULL; const gchar *thumb_path; const gchar *uri; uri = photos_base_item_get_uri (item); if (uri == NULL || uri[0] == '\0') goto out; { g_autoptr (GError) error = NULL; info = photos_base_item_query_info (item, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message); goto out; } } thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumb_path == NULL) goto out; thumb_file = g_file_new_for_path (thumb_path); icon = g_file_icon_new (thumb_file); out: return icon; }
static void on_files_listed (GObject *source_object, GAsyncResult *res, gpointer user_data) { GError *error = NULL; JsonObject *options; GList *files; files = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source_object), res, &error); if (error) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { CockpitFslist *self = COCKPIT_FSLIST (user_data); g_message ("%s: couldn't process files %s", COCKPIT_FSLIST(user_data)->path, error->message); options = cockpit_channel_close_options (COCKPIT_CHANNEL (self)); json_object_set_string_member (options, "message", error->message); cockpit_channel_close (COCKPIT_CHANNEL (self), "internal-error"); } g_clear_error (&error); return; } CockpitFslist *self = COCKPIT_FSLIST (user_data); if (files == NULL) { JsonObject *msg; GBytes *msg_bytes; msg = json_object_new (); json_object_set_string_member (msg, "event", "present-done"); msg_bytes = cockpit_json_write_bytes (msg); json_object_unref (msg); cockpit_channel_send (COCKPIT_CHANNEL(self), msg_bytes, FALSE); g_bytes_unref (msg_bytes); g_clear_object (&self->cancellable); g_object_unref (source_object); if (self->monitor == NULL) { cockpit_channel_done (COCKPIT_CHANNEL (self)); cockpit_channel_close (COCKPIT_CHANNEL (self), NULL); } return; } for (GList *l = files; l; l = l->next) { GFileInfo *info = G_FILE_INFO (l->data); JsonObject *msg; GBytes *msg_bytes; msg = json_object_new (); json_object_set_string_member (msg, "event", "present"); json_object_set_string_member (msg, "path", g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_STANDARD_NAME)); json_object_set_string_member (msg, "type", cockpit_file_type_to_string (g_file_info_get_file_type (info))); msg_bytes = cockpit_json_write_bytes (msg); json_object_unref (msg); cockpit_channel_send (COCKPIT_CHANNEL(self), msg_bytes, FALSE); g_bytes_unref (msg_bytes); } g_list_free_full (files, g_object_unref); g_file_enumerator_next_files_async (G_FILE_ENUMERATOR (source_object), 10, G_PRIORITY_DEFAULT, self->cancellable, on_files_listed, self); }
static gboolean brasero_burn_uri_retrieve_path (BraseroBurnURI *self, const gchar *uri, gchar **path) { GFile *file; GFileInfo *info; BraseroBurnURIPrivate *priv; priv = BRASERO_BURN_URI_PRIVATE (self); if (!uri) return FALSE; file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," "burn::backing-file", G_FILE_QUERY_INFO_NONE, priv->cancel, &priv->error); if (priv->error) { g_object_unref (file); return FALSE; } if (g_cancellable_is_cancelled (priv->cancel)) { g_object_unref (file); return FALSE; } if (!info) { /* Error */ g_object_unref (file); g_object_unref (info); return FALSE; } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { *path = NULL; } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR /* NOTE: burn:// URI allows symlink */ || g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK) { const gchar *real_path; real_path = g_file_info_get_attribute_byte_string (info, "burn::backing-file"); if (!real_path) { priv->error = g_error_new (BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, _("Impossible to retrieve local file path")); g_object_unref (info); g_object_unref (file); return FALSE; } *path = g_strdup (real_path); } g_object_unref (file); g_object_unref (info); return TRUE; }
/** * Gets the icon name from a {@link GLib.File}. * * @param file the file to get the icon name for * @return the icon name for the file, or null if none exists */ gchar* plank_drawing_drawing_service_get_icon_from_file (GFile* file) { gchar* result = NULL; GError * _inner_error_ = NULL; g_return_val_if_fail (file != NULL, NULL); { GFileInfo* info = NULL; GFile* _tmp0_ = NULL; GFileInfo* _tmp1_ = NULL; gchar* custom_icon_name = NULL; GFileInfo* _tmp2_ = NULL; const gchar* _tmp3_ = NULL; gchar* _tmp4_ = NULL; gboolean _tmp5_ = FALSE; const gchar* _tmp6_ = NULL; gchar* custom_icon = NULL; GFileInfo* _tmp8_ = NULL; const gchar* _tmp9_ = NULL; gchar* _tmp10_ = NULL; gboolean _tmp11_ = FALSE; const gchar* _tmp12_ = NULL; gchar* thumb_icon = NULL; GFileInfo* _tmp22_ = NULL; const gchar* _tmp23_ = NULL; gchar* _tmp24_ = NULL; gboolean _tmp25_ = FALSE; const gchar* _tmp26_ = NULL; GFileInfo* _tmp28_ = NULL; GIcon* _tmp29_ = NULL; gchar* _tmp30_ = NULL; _tmp0_ = file; _tmp1_ = g_file_query_info (_tmp0_, G_FILE_ATTRIBUTE_STANDARD_ICON "," PLANK_DRAWING_DRAWING_SERVICE_FILE_ATTRIBUTE_CUSTOM_ICON_NAME "," PLANK_DRAWING_DRAWING_SERVICE_FILE_ATTRIBUTE_CUSTOM_ICON "," G_FILE_ATTRIBUTE_THUMBNAIL_PATH, 0, NULL, &_inner_error_); info = _tmp1_; if (_inner_error_ != NULL) { goto __catch1_g_error; } _tmp2_ = info; _tmp3_ = g_file_info_get_attribute_string (_tmp2_, PLANK_DRAWING_DRAWING_SERVICE_FILE_ATTRIBUTE_CUSTOM_ICON_NAME); _tmp4_ = g_strdup (_tmp3_); custom_icon_name = _tmp4_; _tmp6_ = custom_icon_name; if (_tmp6_ != NULL) { const gchar* _tmp7_ = NULL; _tmp7_ = custom_icon_name; _tmp5_ = g_strcmp0 (_tmp7_, "") != 0; } else { _tmp5_ = FALSE; } if (_tmp5_) { result = custom_icon_name; _g_object_unref0 (info); return result; } _tmp8_ = info; _tmp9_ = g_file_info_get_attribute_string (_tmp8_, PLANK_DRAWING_DRAWING_SERVICE_FILE_ATTRIBUTE_CUSTOM_ICON); _tmp10_ = g_strdup (_tmp9_); custom_icon = _tmp10_; _tmp12_ = custom_icon; if (_tmp12_ != NULL) { const gchar* _tmp13_ = NULL; _tmp13_ = custom_icon; _tmp11_ = g_strcmp0 (_tmp13_, "") != 0; } else { _tmp11_ = FALSE; } if (_tmp11_) { const gchar* _tmp14_ = NULL; gboolean _tmp15_ = FALSE; GFile* _tmp16_ = NULL; const gchar* _tmp17_ = NULL; GFile* _tmp18_ = NULL; GFile* _tmp19_ = NULL; gchar* _tmp20_ = NULL; gchar* _tmp21_ = NULL; _tmp14_ = custom_icon; _tmp15_ = g_str_has_prefix (_tmp14_, "file://"); if (_tmp15_) { result = custom_icon; _g_free0 (custom_icon_name); _g_object_unref0 (info); return result; } _tmp16_ = file; _tmp17_ = custom_icon; _tmp18_ = g_file_get_child (_tmp16_, _tmp17_); _tmp19_ = _tmp18_; _tmp20_ = g_file_get_path (_tmp19_); _tmp21_ = _tmp20_; _g_object_unref0 (_tmp19_); result = _tmp21_; _g_free0 (custom_icon); _g_free0 (custom_icon_name); _g_object_unref0 (info); return result; } _tmp22_ = info; _tmp23_ = g_file_info_get_attribute_byte_string (_tmp22_, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); _tmp24_ = g_strdup (_tmp23_); thumb_icon = _tmp24_; _tmp26_ = thumb_icon; if (_tmp26_ != NULL) { const gchar* _tmp27_ = NULL; _tmp27_ = thumb_icon; _tmp25_ = g_strcmp0 (_tmp27_, "") != 0; } else { _tmp25_ = FALSE; } if (_tmp25_) { result = thumb_icon; _g_free0 (custom_icon); _g_free0 (custom_icon_name); _g_object_unref0 (info); return result; } _tmp28_ = info; _tmp29_ = g_file_info_get_icon (_tmp28_); _tmp30_ = plank_drawing_drawing_service_get_icon_from_gicon (_tmp29_); result = _tmp30_; _g_free0 (thumb_icon); _g_free0 (custom_icon); _g_free0 (custom_icon_name); _g_object_unref0 (info); return result; } goto __finally1; __catch1_g_error: { gchar* _tmp31_ = NULL; GFile* _tmp32_ = NULL; gchar* _tmp33_ = NULL; g_clear_error (&_inner_error_); _inner_error_ = NULL; _tmp32_ = file; _tmp33_ = g_file_get_path (_tmp32_); _tmp31_ = _tmp33_; if (_tmp31_ == NULL) { gchar* _tmp34_ = NULL; _tmp34_ = g_strdup (""); _g_free0 (_tmp31_); _tmp31_ = _tmp34_; } g_debug ("DrawingService.vala:80: Could not get file info for '%s'", _tmp31_); _g_free0 (_tmp31_); } __finally1: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } result = NULL; return result; }
gboolean ot_gio_shutil_rm_rf (GFile *path, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; ot_lobj GFileEnumerator *dir_enum = NULL; ot_lobj GFileInfo *file_info = NULL; GError *temp_error = NULL; dir_enum = g_file_enumerate_children (path, OSTREE_GIO_FAST_QUERYINFO, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, &temp_error); if (!dir_enum) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_clear_error (&temp_error); ret = TRUE; } else g_propagate_error (error, temp_error); goto out; } while ((file_info = g_file_enumerator_next_file (dir_enum, cancellable, &temp_error)) != NULL) { ot_lobj GFile *subpath = NULL; GFileType type; const char *name; type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); subpath = g_file_get_child (path, name); if (type == G_FILE_TYPE_DIRECTORY) { if (!ot_gio_shutil_rm_rf (subpath, cancellable, error)) goto out; } else { if (!ot_gfile_unlink (subpath, cancellable, error)) goto out; } g_clear_object (&file_info); } if (temp_error) { g_propagate_error (error, temp_error); goto out; } if (!g_file_delete (path, cancellable, error)) goto out; ret = TRUE; out: return ret; }
static gboolean ensure_thumbnail_job (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data) { LoadThumbnailData *data = user_data; gboolean thumb_failed; const gchar *thumb_path; GError *error = NULL; GFile *thumb_file = NULL; GFileInputStream *is = NULL; GFileInfo *info = NULL; info = g_file_query_info (data->font_file, ATTRIBUTES_FOR_EXISTING_THUMBNAIL, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_debug ("Can't query info for file %s: %s\n", data->font_path, error->message); goto out; } thumb_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); if (thumb_failed) goto out; thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumb_path != NULL) { thumb_file = g_file_new_for_path (thumb_path); is = g_file_read (thumb_file, NULL, &error); if (error != NULL) { g_debug ("Can't read file %s: %s\n", thumb_path, error->message); goto out; } data->pixbuf = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (is), 128, 128, TRUE, NULL, &error); if (error != NULL) { g_debug ("Can't read thumbnail pixbuf %s: %s\n", thumb_path, error->message); goto out; } } else { data->pixbuf = create_thumbnail (data); } out: g_clear_error (&error); g_clear_object (&is); g_clear_object (&thumb_file); g_clear_object (&info); g_io_scheduler_job_send_to_mainloop_async (job, ensure_thumbnail_job_done, data, NULL); return FALSE; }
static gpointer brasero_burn_uri_thread (gpointer data) { BraseroBurnURI *self = BRASERO_BURN_URI (data); BraseroTrack *current = NULL; BraseroBurnURIPrivate *priv; BraseroTrackData *track; GSList *excluded = NULL; GSList *grafts = NULL; guint64 num = 0; GSList *src; priv = BRASERO_BURN_URI_PRIVATE (self); brasero_job_set_current_action (BRASERO_JOB (self), BRASERO_BURN_ACTION_FILE_COPY, _("Copying files locally"), TRUE); brasero_job_get_current_track (BRASERO_JOB (self), ¤t); /* This is for IMAGE tracks */ if (BRASERO_IS_TRACK_IMAGE (current)) { gchar *uri; gchar *path_toc; gchar *path_image; goffset blocks = 0; BraseroTrackImage *image; path_image = NULL; uri = brasero_track_image_get_source (BRASERO_TRACK_IMAGE (current), TRUE); if (!brasero_burn_uri_retrieve_path (self, uri, &path_image)) { g_free (uri); goto end; } g_free (uri); path_toc = NULL; uri = brasero_track_image_get_toc_source (BRASERO_TRACK_IMAGE (current), TRUE); if (uri) { /* NOTE: if it's a .bin image there is not .toc file */ if (!brasero_burn_uri_retrieve_path (self, uri, &path_toc)) { g_free (path_image); g_free (uri); goto end; } g_free (uri); } brasero_track_get_size (current, &blocks, NULL); image = brasero_track_image_new (); brasero_track_tag_copy_missing (BRASERO_TRACK (image), current); brasero_track_image_set_source (image, path_image, path_toc, brasero_track_image_get_format (BRASERO_TRACK_IMAGE (current))); brasero_track_image_set_block_num (image, blocks); priv->track = BRASERO_TRACK (image); g_free (path_toc); g_free (path_image); goto end; } /* This is for DATA tracks */ for (src = brasero_track_data_get_grafts (BRASERO_TRACK_DATA (current)); src; src = src->next) { GFile *file; GFileInfo *info; BraseroGraftPt *graft; graft = src->data; if (!graft->uri) { grafts = g_slist_prepend (grafts, brasero_graft_point_copy (graft)); continue; } if (!g_str_has_prefix (graft->uri, "burn://")) { grafts = g_slist_prepend (grafts, brasero_graft_point_copy (graft)); continue; } BRASERO_JOB_LOG (self, "Information retrieval for %s", graft->uri); file = g_file_new_for_uri (graft->uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," "burn::backing-file", G_FILE_QUERY_INFO_NONE, priv->cancel, &priv->error); if (priv->error) { g_object_unref (file); goto end; } if (g_cancellable_is_cancelled (priv->cancel)) { g_object_unref (file); goto end; } if (!info) { /* Error */ g_object_unref (file); g_object_unref (info); goto end; } /* See if we were passed the burn:/// uri itself (the root). * Then skip graft point addition */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { if (g_file_info_get_name (info) && strcmp (g_file_info_get_name (info), "/")) { BraseroGraftPt *newgraft; /* we need a dummy directory */ newgraft = g_new0 (BraseroGraftPt, 1); newgraft->uri = NULL; newgraft->path = g_strdup (graft->path); grafts = g_slist_prepend (grafts, newgraft); BRASERO_JOB_LOG (self, "Adding directory %s at %s", newgraft->uri, newgraft->path); grafts = brasero_burn_uri_explore_directory (self, grafts, file, newgraft->path, priv->cancel, &priv->error); } else { BRASERO_JOB_LOG (self, "Directory is root"); grafts = brasero_burn_uri_explore_directory (self, grafts, file, "/", priv->cancel, &priv->error); } if (!grafts) { g_object_unref (info); g_object_unref (file); goto end; } } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR /* NOTE: burn:// URI allows symlink */ || g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK) { const gchar *real_path; BraseroGraftPt *newgraft; real_path = g_file_info_get_attribute_byte_string (info, "burn::backing-file"); if (!real_path) { priv->error = g_error_new (BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, _("Impossible to retrieve local file path")); g_slist_foreach (grafts, (GFunc) brasero_graft_point_free, NULL); g_slist_free (grafts); g_object_unref (info); g_object_unref (file); goto end; } newgraft = brasero_graft_point_copy (graft); g_free (newgraft->uri); newgraft->uri = g_strdup (real_path); /* FIXME: maybe one day, graft->uri will always be an URI */ /* newgraft->uri = g_filename_to_uri (real_path, NULL, NULL); */ BRASERO_JOB_LOG (self, "Added file %s at %s", newgraft->uri, newgraft->path); grafts = g_slist_prepend (grafts, newgraft); } g_object_unref (info); g_object_unref (file); } grafts = g_slist_reverse (grafts); /* remove all excluded starting by burn:// from the list */ for (src = brasero_track_data_get_excluded_list (BRASERO_TRACK_DATA (current)); src; src = src->next) { gchar *uri; uri = src->data; if (uri && g_str_has_prefix (uri, "burn://")) continue; uri = g_strdup (uri); excluded = g_slist_prepend (excluded, uri); BRASERO_JOB_LOG (self, "Added excluded file %s", uri); } excluded = g_slist_reverse (excluded); track = brasero_track_data_new (); brasero_track_tag_copy_missing (BRASERO_TRACK (track), current); brasero_track_data_add_fs (track, brasero_track_data_get_fs (BRASERO_TRACK_DATA (current))); brasero_track_data_get_file_num (BRASERO_TRACK_DATA (current), &num); brasero_track_data_set_file_num (track, num); brasero_track_data_set_source (track, grafts, excluded); priv->track = BRASERO_TRACK (track); end: if (!g_cancellable_is_cancelled (priv->cancel)) priv->thread_id = g_idle_add ((GSourceFunc) brasero_burn_uri_thread_finished, self); /* End thread */ g_mutex_lock (priv->mutex); g_atomic_pointer_set (&priv->thread, NULL); g_cond_signal (priv->cond); g_mutex_unlock (priv->mutex); g_thread_exit (NULL); return NULL; }
static GSList * brasero_burn_uri_explore_directory (BraseroBurnURI *self, GSList *grafts, GFile *file, const gchar *path, GCancellable *cancel, GError **error) { BraseroTrack *current = NULL; GFileEnumerator *enumerator; GSList *current_grafts; GFileInfo *info; enumerator = g_file_enumerate_children (file, G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE "," "burn::backing-file", G_FILE_QUERY_INFO_NONE, cancel, error); if (!enumerator) { g_slist_foreach (grafts, (GFunc) brasero_graft_point_free, NULL); g_slist_free (grafts); return NULL; } brasero_job_get_current_track (BRASERO_JOB (self), ¤t); current_grafts = brasero_track_data_get_grafts (BRASERO_TRACK_DATA (current)); while ((info = g_file_enumerator_next_file (enumerator, cancel, error))) { if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { gchar *disc_path; GFile *directory; BraseroGraftPt *graft; /* Make sure it's not one of the original grafts */ /* we need to know if that's a directory or not since if * it is then mkisofs (but not genisoimage) requires the * disc path to end with '/'; if there isn't '/' at the * end then only the directory contents are added. */ disc_path = g_build_filename (path, g_file_info_get_name (info), G_DIR_SEPARATOR_S, NULL); if (g_slist_find_custom (current_grafts, disc_path, (GCompareFunc) brasero_burn_uri_find_graft)) { BRASERO_JOB_LOG (self, "Graft already in list %s", disc_path); g_object_unref (info); g_free (disc_path); continue; } /* we need a dummy directory */ graft = g_new0 (BraseroGraftPt, 1); graft->uri = NULL; graft->path = disc_path; grafts = g_slist_prepend (grafts, graft); BRASERO_JOB_LOG (self, "Adding directory %s at %s", graft->uri, graft->path); directory = g_file_get_child (file, g_file_info_get_name (info)); grafts = brasero_burn_uri_explore_directory (self, grafts, directory, graft->path, cancel, error); g_object_unref (directory); if (!grafts) { g_object_unref (info); g_object_unref (enumerator); return NULL; } } else if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR /* NOTE: burn:// URI allows symlink */ || g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK) { const gchar *real_path; BraseroGraftPt *graft; gchar *disc_path; real_path = g_file_info_get_attribute_byte_string (info, "burn::backing-file"); if (!real_path) { g_set_error (error, BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, _("Impossible to retrieve local file path")); g_slist_foreach (grafts, (GFunc) brasero_graft_point_free, NULL); g_slist_free (grafts); g_object_unref (info); g_object_unref (file); return NULL; } /* Make sure it's not one of the original grafts */ disc_path = g_build_filename (path, g_file_info_get_name (info), NULL); if (g_slist_find_custom (current_grafts, disc_path, (GCompareFunc) brasero_burn_uri_find_graft)) { BRASERO_JOB_LOG (self, "Graft already in list %s", disc_path); g_object_unref (info); g_free (disc_path); continue; } graft = g_new0 (BraseroGraftPt, 1); graft->path = disc_path; graft->uri = g_strdup (real_path); /* FIXME: maybe one day, graft->uri will always be an URI */ /* graft->uri = g_filename_to_uri (real_path, NULL, NULL); */ /* Make sure it's not one of the original grafts */ grafts = g_slist_prepend (grafts, graft); BRASERO_JOB_LOG (self, "Added file %s at %s", graft->uri, graft->path); } g_object_unref (info); } g_object_unref (enumerator); return grafts; }
static void got_file_info (GFile *file, GAsyncResult *result, gpointer user_data) { GCancellable *cancellable; GFileInfo *info; GError *error = NULL; const gchar *thumbnail_path; gboolean thumbnail_is_valid; GrlLocalMetadataSourcePriv *priv; ResolveData *resolve_data = user_data; GrlSourceResolveSpec *rs = resolve_data->rs; resolution_flags_t flags; GRL_DEBUG ("got_file_info"); priv = GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (resolve_data->source); cancellable = resolve_data_ensure_cancellable (resolve_data); info = g_file_query_info_finish (file, result, &error); if (error) goto error; thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); #if GLIB_CHECK_VERSION (2, 39, 0) thumbnail_is_valid = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID); #else thumbnail_is_valid = TRUE; #endif if (thumbnail_path && thumbnail_is_valid) { gchar *thumbnail_uri = g_filename_to_uri (thumbnail_path, NULL, &error); if (error) goto error; GRL_INFO ("Got thumbnail %s for media: %s", thumbnail_uri, grl_media_get_url (rs->media)); grl_media_set_thumbnail (rs->media, thumbnail_uri); g_free (thumbnail_uri); } else if (thumbnail_path && !thumbnail_is_valid) { GRL_INFO ("Found outdated thumbnail %s for media: %s", thumbnail_path, grl_media_get_url (rs->media)); } else { GRL_INFO ("Could not find thumbnail for media: %s", grl_media_get_url (rs->media)); } flags = get_resolution_flags (rs->keys, priv); if (GRL_IS_MEDIA_AUDIO (rs->media) && !(thumbnail_path && thumbnail_is_valid)) { /* We couldn't get a per-track thumbnail; try for a per-album one, * using libmediaart */ resolve_album_art (resolve_data, flags); } if (flags & FLAG_GIBEST_HASH) { extract_gibest_hash_async (resolve_data, file, cancellable); } else { resolve_data_finish_operation (resolve_data, "image", NULL); } goto exit; error: { GError *new_error = g_error_new (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Failed to resolve: %s"), error->message); resolve_data_finish_operation (resolve_data, "image", new_error); g_error_free (error); g_error_free (new_error); } exit: g_clear_object (&info); }
/** * rb_uri_resolve_symlink: * @uri: the URI to process * @error: returns error information * * Attempts to resolve symlinks in @uri and return a canonical URI for the file * it identifies. * * Return value: resolved URI, or NULL on error */ char * rb_uri_resolve_symlink (const char *uri, GError **error) { GFile *file = NULL; GFileInfo *file_info = NULL; int link_count = 0; char *result = NULL; const char *attr = G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET; GError *l_error = NULL; file = g_file_new_for_uri (uri); while (link_count < MAX_LINK_LEVEL) { GFile *parent; GFile *new_file; const char *target; /* look for a symlink target */ file_info = g_file_query_info (file, attr, G_FILE_QUERY_INFO_NONE, NULL, &l_error); if (l_error != NULL) { /* argh */ result = g_file_get_uri (file); rb_debug ("error querying %s: %s", result, l_error->message); g_free (result); result = NULL; break; } else if (g_file_info_has_attribute (file_info, attr) == FALSE) { /* no symlink, so return the path */ result = g_file_get_uri (file); if (link_count > 0) { rb_debug ("resolved symlinks: %s -> %s", uri, result); } break; } /* resolve it and try again */ new_file = NULL; parent = g_file_get_parent (file); if (parent == NULL) { /* dang */ break; } target = g_file_info_get_attribute_byte_string (file_info, attr); new_file = g_file_resolve_relative_path (parent, target); g_object_unref (parent); g_object_unref (file_info); file_info = NULL; g_object_unref (file); file = new_file; if (file == NULL) { /* dang */ break; } link_count++; } if (file != NULL) { g_object_unref (file); } if (file_info != NULL) { g_object_unref (file_info); } if (result == NULL && error == NULL) { rb_debug ("too many symlinks while resolving %s", uri); l_error = g_error_new (G_IO_ERROR, G_IO_ERROR_TOO_MANY_LINKS, _("Too many symlinks")); } if (l_error != NULL) { g_propagate_error (error, l_error); } return result; }
static gboolean get_sorted_triggers (GPtrArray **out_triggers, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GError *temp_error = NULL; char *triggerdir_path = NULL; GFile *triggerdir = NULL; GFileInfo *file_info = NULL; GFileEnumerator *enumerator = NULL; GPtrArray *ret_triggers = NULL; ret_triggers = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref); triggerdir_path = g_build_filename (LIBEXECDIR, "ostree", "triggers.d", NULL); triggerdir = g_file_new_for_path (triggerdir_path); enumerator = g_file_enumerate_children (triggerdir, "standard::name,standard::type", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error); if (!enumerator) goto out; while ((file_info = g_file_enumerator_next_file (enumerator, cancellable, &temp_error)) != NULL) { const char *name; guint32 type; name = g_file_info_get_attribute_byte_string (file_info, "standard::name"); type = g_file_info_get_attribute_uint32 (file_info, "standard::type"); if (type == G_FILE_TYPE_REGULAR && g_str_has_suffix (name, ".trigger")) { char *child_path; GFile *child; child_path = g_build_filename (triggerdir_path, name, NULL); child = g_file_new_for_path (child_path); g_free (child_path); g_ptr_array_add (ret_triggers, child); } g_clear_object (&file_info); } if (file_info == NULL && temp_error != NULL) { g_propagate_error (error, temp_error); goto out; } g_ptr_array_sort (ret_triggers, compare_files_by_basename); ret = TRUE; if (out_triggers) { *out_triggers = ret_triggers; ret_triggers = NULL; } out: g_free (triggerdir_path); g_clear_object (&triggerdir); g_clear_object (&enumerator); if (ret_triggers) g_ptr_array_unref (ret_triggers); return ret; }
char * gvfs_file_info_marshal (GFileInfo *info, gsize *size) { GOutputStream *memstream; GDataOutputStream *out; GFileAttributeType type; GFileAttributeStatus status; GObject *obj; char **attrs, *attr; char *data; int i; memstream = g_memory_output_stream_new (NULL, 0, g_realloc, NULL); out = g_data_output_stream_new (memstream); g_object_unref (memstream); attrs = g_file_info_list_attributes (info, NULL); g_data_output_stream_put_uint32 (out, g_strv_length (attrs), NULL, NULL); for (i = 0; attrs[i] != NULL; i++) { attr = attrs[i]; type = g_file_info_get_attribute_type (info, attr); status = g_file_info_get_attribute_status (info, attr); put_string (out, attr); g_data_output_stream_put_byte (out, type, NULL, NULL); g_data_output_stream_put_byte (out, status, NULL, NULL); switch (type) { case G_FILE_ATTRIBUTE_TYPE_STRING: put_string (out, g_file_info_get_attribute_string (info, attr)); break; case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: put_string (out, g_file_info_get_attribute_byte_string (info, attr)); break; case G_FILE_ATTRIBUTE_TYPE_STRINGV: put_stringv (out, g_file_info_get_attribute_stringv (info, attr)); break; case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: g_data_output_stream_put_byte (out, g_file_info_get_attribute_boolean (info, attr), NULL, NULL); break; case G_FILE_ATTRIBUTE_TYPE_UINT32: g_data_output_stream_put_uint32 (out, g_file_info_get_attribute_uint32 (info, attr), NULL, NULL); break; case G_FILE_ATTRIBUTE_TYPE_INT32: g_data_output_stream_put_int32 (out, g_file_info_get_attribute_int32 (info, attr), NULL, NULL); break; case G_FILE_ATTRIBUTE_TYPE_UINT64: g_data_output_stream_put_uint64 (out, g_file_info_get_attribute_uint64 (info, attr), NULL, NULL); break; case G_FILE_ATTRIBUTE_TYPE_INT64: g_data_output_stream_put_int64 (out, g_file_info_get_attribute_int64 (info, attr), NULL, NULL); break; case G_FILE_ATTRIBUTE_TYPE_OBJECT: obj = g_file_info_get_attribute_object (info, attr); if (obj == NULL) { g_data_output_stream_put_byte (out, 0, NULL, NULL); } else if (G_IS_ICON (obj)) { char *icon_str; icon_str = g_icon_to_string (G_ICON (obj)); g_data_output_stream_put_byte (out, 1, NULL, NULL); put_string (out, icon_str); g_free (icon_str); } else { g_warning ("Unsupported GFileInfo object type %s\n", g_type_name_from_instance ((GTypeInstance *)obj)); g_data_output_stream_put_byte (out, 0, NULL, NULL); } break; case G_FILE_ATTRIBUTE_TYPE_INVALID: default: break; } } data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (memstream)); *size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (memstream)); g_object_unref (out); g_strfreev (attrs); return data; }
gboolean ostree_create_file_from_input (GFile *dest_file, GFileInfo *finfo, GVariant *xattrs, GInputStream *input, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; const char *dest_path; guint32 uid, gid, mode; ot_lobj GFileOutputStream *out = NULL; if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; if (finfo != NULL) { mode = g_file_info_get_attribute_uint32 (finfo, "unix::mode"); } else { mode = S_IFREG | 0664; } dest_path = ot_gfile_get_path_cached (dest_file); if (S_ISDIR (mode)) { if (mkdir (ot_gfile_get_path_cached (dest_file), mode) < 0) { ot_util_set_error_from_errno (error, errno); goto out; } } else if (S_ISREG (mode)) { out = g_file_create (dest_file, 0, cancellable, error); if (!out) goto out; if (input) { if (g_output_stream_splice ((GOutputStream*)out, input, 0, cancellable, error) < 0) goto out; } if (!g_output_stream_close ((GOutputStream*)out, NULL, error)) goto out; } else if (S_ISLNK (mode)) { const char *target = g_file_info_get_attribute_byte_string (finfo, "standard::symlink-target"); if (symlink (target, dest_path) < 0) { ot_util_set_error_from_errno (error, errno); goto out; } } else if (S_ISCHR (mode) || S_ISBLK (mode)) { guint32 dev = g_file_info_get_attribute_uint32 (finfo, "unix::rdev"); if (mknod (dest_path, mode, dev) < 0) { ot_util_set_error_from_errno (error, errno); goto out; } } else if (S_ISFIFO (mode)) { if (mkfifo (dest_path, mode) < 0) { ot_util_set_error_from_errno (error, errno); goto out; } } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid mode %u", mode); goto out; } if (finfo != NULL) { uid = g_file_info_get_attribute_uint32 (finfo, "unix::uid"); gid = g_file_info_get_attribute_uint32 (finfo, "unix::gid"); if (lchown (dest_path, uid, gid) < 0) { ot_util_set_error_from_errno (error, errno); g_prefix_error (error, "lchown(%u, %u) failed: ", uid, gid); goto out; } } if (!S_ISLNK (mode)) { if (chmod (dest_path, mode) < 0) { ot_util_set_error_from_errno (error, errno); g_prefix_error (error, "chmod(%u) failed: ", mode); goto out; } } if (xattrs != NULL) { if (!ostree_set_xattrs (dest_file, xattrs, cancellable, error)) goto out; } ret = TRUE; out: if (!ret && !S_ISDIR(mode)) { (void) unlink (dest_path); } return ret; }