static gboolean try_enumerate (GVfsBackend *backend, GVfsJobEnumerate *job, const char *filename, GFileAttributeMatcher *matcher, GFileQueryInfoFlags flags) { GFileInfo *info1, *info2; GList *l; g_print ("try_enumerate (%s)\n", filename); g_vfs_job_succeeded (G_VFS_JOB (job)); info1 = g_file_info_new (); info2 = g_file_info_new (); g_file_info_set_name (info1, "file1"); g_file_info_set_file_type (info1, G_FILE_TYPE_REGULAR); g_file_info_set_name (info2, "file2"); g_file_info_set_file_type (info2, G_FILE_TYPE_REGULAR); l = NULL; l = g_list_append (l, info1); l = g_list_append (l, info2); g_vfs_job_enumerate_add_infos (job, l); g_list_free (l); g_object_unref (info1); g_object_unref (info2); g_vfs_job_enumerate_done (job); return TRUE; }
static void enumerate_cache_updated_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GVfsBackendAfpBrowse *afp_backend = G_VFS_BACKEND_AFP_BROWSE (source_object); GVfsJobEnumerate *job = G_VFS_JOB_ENUMERATE (user_data); GError *err = NULL; guint i; if (!update_cache_finish (afp_backend, res, &err)) { g_vfs_job_failed_from_error (G_VFS_JOB (job), err); g_error_free (err); return; } g_vfs_job_succeeded (G_VFS_JOB (job)); for (i = 0; i < afp_backend->volumes->len; i++) { GVfsAfpVolumeData *vol_data = g_ptr_array_index (afp_backend->volumes, i); GFileInfo *info; info = g_file_info_new (); fill_info (info, vol_data, afp_backend); g_vfs_job_enumerate_add_info (job, info); g_object_unref (info); } g_vfs_job_enumerate_done (job); }
static IdeProjectFile * create_file (IdeContext *context, GFile *file, GFileType file_type) { g_autofree gchar *path = NULL; g_autofree gchar *name = NULL; g_autoptr(GFileInfo) file_info = NULL; IdeVcs *vcs; GFile *workdir; g_assert (IDE_IS_CONTEXT (context)); g_assert (G_IS_FILE (file)); g_assert ((file_type == G_FILE_TYPE_DIRECTORY) || (file_type == G_FILE_TYPE_REGULAR)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); path = g_file_get_relative_path (workdir, file); name = g_file_get_basename (file); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, file_type); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); return g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "file", file, "file-info", file_info, "path", path, "parent", NULL, NULL); }
gboolean ostree_zlib_file_header_parse (GVariant *metadata, GFileInfo **out_file_info, GVariant **out_xattrs, GError **error) { gboolean ret = FALSE; guint64 size; guint32 uid, gid, mode, rdev; const char *symlink_target; ot_lobj GFileInfo *ret_file_info = NULL; ot_lvariant GVariant *ret_xattrs = NULL; g_variant_get (metadata, "(tuuuu&s@a(ayay))", &size, &uid, &gid, &mode, &rdev, &symlink_target, &ret_xattrs); size = GUINT64_FROM_BE (size); uid = GUINT32_FROM_BE (uid); gid = GUINT32_FROM_BE (gid); mode = GUINT32_FROM_BE (mode); rdev = GUINT32_FROM_BE (rdev); ret_file_info = g_file_info_new (); g_file_info_set_size (ret_file_info, size); g_file_info_set_attribute_uint32 (ret_file_info, "standard::type", ot_gfile_type_for_mode (mode)); g_file_info_set_attribute_boolean (ret_file_info, "standard::is-symlink", S_ISLNK (mode)); g_file_info_set_attribute_uint32 (ret_file_info, "unix::uid", uid); g_file_info_set_attribute_uint32 (ret_file_info, "unix::gid", gid); g_file_info_set_attribute_uint32 (ret_file_info, "unix::mode", mode); if (S_ISREG (mode)) { ; } else if (S_ISLNK (mode)) { g_file_info_set_attribute_byte_string (ret_file_info, "standard::symlink-target", symlink_target); } else if (S_ISCHR (mode) || S_ISBLK (mode)) { g_file_info_set_attribute_uint32 (ret_file_info, "unix::rdev", rdev); } else if (S_ISFIFO (mode)) { ; } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Corrupted archive file; invalid mode %u", mode); goto out; } ret = TRUE; ot_transfer_out_value(out_file_info, &ret_file_info); ot_transfer_out_value(out_xattrs, &ret_xattrs); out: return ret; }
static VALUE fileinfo_initialize(VALUE self) { G_INITIALIZE(self, g_file_info_new()); return Qnil; }
static void vfs_file_set_metadata_as_list (NautilusFile *file, const char *key, char **value) { GFile *location; GFileInfo *info; char *gio_key; info = g_file_info_new (); gio_key = g_strconcat ("metadata::", key, NULL); g_file_info_set_attribute_stringv (info, gio_key, value); g_free (gio_key); location = nautilus_file_get_location (file); g_file_set_attributes_async (location, info, 0, G_PRIORITY_DEFAULT, NULL, set_metadata_callback, nautilus_file_ref (file)); g_object_unref (info); g_object_unref (location); }
static GFileInfo * create_root_file_info (GVfsBackendFtp *ftp) { GFileInfo *info; GIcon *icon; char *display_name; info = g_file_info_new (); g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_name (info, "/"); display_name = g_strdup_printf (_("/ on %s"), ftp->host_display_name); g_file_info_set_display_name (info, display_name); g_free (display_name); g_file_info_set_edit_name (info, "/"); g_file_info_set_content_type (info, "inode/directory"); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, "inode/directory"); icon = g_themed_icon_new ("folder-remote"); g_file_info_set_icon (info, icon); g_object_unref (icon); return info; }
/** * gedit_document_set_metadata: * @doc: a #GeditDocument * @first_key: name of the first key to set * @...: (allow-none): value for the first key, followed optionally by more key/value pairs, * followed by %NULL. * * Sets metadata on a document. */ void gedit_document_set_metadata (GeditDocument *doc, const gchar *first_key, ...) { const gchar *key; const gchar *value; va_list var_args; GFileInfo *info; GFile *location; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); g_return_if_fail (first_key != NULL); info = g_file_info_new (); va_start (var_args, first_key); for (key = first_key; key; key = va_arg (var_args, const gchar *)) { value = va_arg (var_args, const gchar *); if (value != NULL) { g_file_info_set_attribute_string (info, key, value); } else { /* Unset the key */ g_file_info_remove_attribute (info, key); } } va_end (var_args); if (doc->priv->metadata_info != NULL) { g_file_info_copy_into (info, doc->priv->metadata_info); } location = gtk_source_file_get_location (doc->priv->file); if (location != NULL) { g_file_set_attributes_async (location, info, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, NULL, (GAsyncReadyCallback) set_attributes_cb, NULL); } g_object_unref (info); }
static void pdf_load_job_cache_set_attributes (PdfLoadJob *job) { GFileInfo *info; GFile *file; if (job->download_file != NULL) { gchar *path; path = g_file_get_path (job->download_file); /* In case the downloaded file is not the final PDF, then we * need to convert it. */ if (g_strcmp0 (path, job->pdf_path) != 0) { /* make the file private */ g_chmod (path, 0600); job->uri = g_file_get_uri (job->download_file); pdf_load_job_from_openoffice (job); g_free (path); return; } g_clear_object (&job->download_file); g_free (path); } /* make the file private */ g_chmod (job->pdf_path, 0600); file = g_file_new_for_path (job->pdf_path); info = g_file_info_new (); g_file_info_set_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED, job->original_file_mtime); g_file_set_attributes_async (file, info, G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, job->cancellable, cache_set_attributes_ready_cb, job); g_object_unref (info); g_object_unref (file); }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = adoptGRef(response.toSoupMessage()); m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url().string(), response.httpStatusText())); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { URL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, overwrite); if (destinationURI.isEmpty()) { #if PLATFORM(GTK) GOwnPtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); String errorMessage = String::fromUTF8(buffer.get()); #else String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); #endif downloadFailed(platformDownloadDestinationError(response, errorMessage)); return; } GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(file.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(platformDownloadDestinationError(response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", response.url().string().utf8().data()); g_file_set_attributes_async(file.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, 0, 0, 0); m_download->didCreateDestination(destinationURI); }
void didFinishLoading(ResourceHandle*, double) { m_outputStream = 0; ASSERT(m_intermediateFile); GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_uri(m_destinationURI.utf8().data())); GOwnPtr<GError> error; if (!g_file_move(m_intermediateFile.get(), destinationFile.get(), G_FILE_COPY_NONE, nullptr, nullptr, nullptr, &error.outPtr())) { downloadFailed(platformDownloadDestinationError(m_response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); CString uri = m_response.url().string().utf8(); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", uri.data()); g_file_info_set_attribute_string(info.get(), "xattr::xdg.origin.url", uri.data()); g_file_set_attributes_async(destinationFile.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, nullptr, nullptr, nullptr); m_download->didFinish(); }
static void build_context (GbProjectTreeBuilder *self, IdeTreeNode *node) { g_autoptr(GbProjectFile) item = NULL; g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *name = NULL; IdeTreeNode *child; IdeContext *context; IdeProject *project; IdeVcs *vcs; GFile *workdir; g_return_if_fail (GB_IS_PROJECT_TREE_BUILDER (self)); g_return_if_fail (IDE_IS_TREE_NODE (node)); context = IDE_CONTEXT (ide_tree_node_get_item (node)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); project = ide_context_get_project (context); file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); name = g_file_get_basename (workdir); g_file_info_set_name (file_info, name); g_file_info_set_display_name (file_info, name); item = g_object_new (GB_TYPE_PROJECT_FILE, "file", workdir, "file-info", file_info, NULL); child = g_object_new (IDE_TYPE_TREE_NODE, "item", item, "icon-name", "folder-symbolic", NULL); g_object_bind_property (project, "name", child, "text", G_BINDING_SYNC_CREATE); ide_tree_node_append (node, child); }
static GFileInfo * g_resource_file_query_filesystem_info (GFile *file, const char *attributes, GCancellable *cancellable, GError **error) { GFileInfo *info; GFileAttributeMatcher *matcher; info = g_file_info_new (); matcher = g_file_attribute_matcher_new (attributes); if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE)) g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, "resource"); if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY)) g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY, TRUE); g_file_attribute_matcher_unref (matcher); return info; }
static GthFileData * create_example_file_data (void) { GFile *file; GFileInfo *info; GthFileData *file_data; GthMetadata *metadata; file = g_file_new_for_uri ("file://home/user/document.txt"); info = g_file_info_new (); file_data = gth_file_data_new (file, info); metadata = g_object_new (GTH_TYPE_METADATA, "raw", "2005:03:09 13:23:51", "formatted", "2005:03:09 13:23:51", NULL); g_file_info_set_attribute_object (info, "Embedded::Photo::DateTimeOriginal", G_OBJECT (metadata)); g_object_unref (metadata); g_object_unref (info); g_object_unref (file); return file_data; }
static void vfs_file_set_metadata (NautilusFile *file, const char *key, const char *value) { GFileInfo *info; GFile *location; char *gio_key; info = g_file_info_new (); gio_key = g_strconcat ("metadata::", key, NULL); if (value != NULL) { g_file_info_set_attribute_string (info, gio_key, value); } else { /* Unset the key */ g_file_info_set_attribute (info, gio_key, G_FILE_ATTRIBUTE_TYPE_INVALID, NULL); } g_free (gio_key); location = nautilus_file_get_location (file); g_file_set_attributes_async (location, info, 0, G_PRIORITY_DEFAULT, NULL, set_metadata_callback, nautilus_file_ref (file)); g_object_unref (location); g_object_unref (info); }
static void gedit_document_init (GeditDocument *doc) { GeditDocumentPrivate *priv; GtkSourceStyleScheme *style_scheme; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (doc); priv->editor_settings = g_settings_new ("org.gnome.gedit.preferences.editor"); priv->untitled_number = get_untitled_number (); priv->content_type = get_default_content_type (); priv->language_set_by_user = FALSE; priv->empty_search = TRUE; g_get_current_time (&priv->time_of_last_save_or_load); priv->file = gtk_source_file_new (); priv->metadata_info = g_file_info_new (); g_signal_connect_object (priv->file, "notify::location", G_CALLBACK (on_location_changed), doc, 0); g_signal_connect_object (priv->file, "notify::read-only", G_CALLBACK (on_readonly_changed), doc, 0); g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_MAX_UNDO_ACTIONS, doc, "max-undo-levels", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY); g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_SYNTAX_HIGHLIGHTING, doc, "highlight-syntax", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY); g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_BRACKET_MATCHING, doc, "highlight-matching-brackets", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY); style_scheme = get_default_style_scheme (priv->editor_settings); if (style_scheme != NULL) { gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); } g_signal_connect (doc, "notify::content-type", G_CALLBACK (on_content_type_changed), NULL); }
static GFileInfo * g_resource_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error) { GResourceFile *resource = G_RESOURCE_FILE (file); GError *my_error = NULL; GFileInfo *info; GFileAttributeMatcher *matcher; gboolean res; gsize size; guint32 resource_flags; char **children; gboolean is_dir; char *base; is_dir = FALSE; children = g_resources_enumerate_children (resource->path, 0, NULL); if (children != NULL) { g_strfreev (children); is_dir = TRUE; } /* root is always there */ if (strcmp ("/", resource->path) == 0) is_dir = TRUE; if (!is_dir) { res = g_resources_get_info (resource->path, 0, &size, &resource_flags, &my_error); if (!res) { if (g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, _("The resource at '%s' does not exist"), resource->path); } else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, my_error->message); g_clear_error (&my_error); return FALSE; } } matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); base = g_resource_file_get_basename (file); g_file_info_set_name (info, base); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_READ, TRUE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_WRITE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_EXECUTE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_DELETE, FALSE); _g_file_info_set_attribute_boolean_by_id (info, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_TRASH, FALSE); if (is_dir) { g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); } else { GBytes *bytes; char *content_type; g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); g_file_info_set_size (info, size); if ((_g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE) || ((~resource_flags & G_RESOURCE_FLAGS_COMPRESSED) && _g_file_attribute_matcher_matches_id (matcher, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE))) && (bytes = g_resources_lookup_data (resource->path, 0, NULL))) { const guchar *data; gsize data_size; data = g_bytes_get_data (bytes, &data_size); content_type = g_content_type_guess (base, data, data_size, NULL); g_bytes_unref (bytes); } else content_type = NULL; if (content_type) { _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_CONTENT_TYPE, content_type); _g_file_info_set_attribute_string_by_id (info, G_FILE_ATTRIBUTE_ID_STANDARD_FAST_CONTENT_TYPE, content_type); g_free (content_type); } } g_free (base); g_file_attribute_matcher_unref (matcher); return info; }
static gboolean project_import_generate_file (AnjutaPluginDescription *backend, ProjectImportDialog *import_dialog, GFile *project_file) { /* Of course we could do some more intelligent stuff here * and check which plugins are really needed */ GFile* source_file = NULL; gchar *backend_id = NULL; GError* error = NULL; if (!anjuta_plugin_description_get_string (backend, "Project", "Supported-Project-Types", &backend_id)) { if (!strcmp (backend_id, "automake")) source_file = g_file_new_for_path (AM_PROJECT_FILE); else if (!strcmp (backend_id, "make")) source_file = g_file_new_for_path (MKFILE_PROJECT_FILE); else if (!strcmp (backend_id, "directory")) source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); } g_free (backend_id); if (source_file != NULL) { /* Use a default project file */ if (!g_file_copy (source_file, project_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) { if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; g_file_copy (source_file, project_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error); } g_free (prjfile); } } if (!error) { time_t ctime = time(NULL); GFileInfo* file_info = g_file_info_new(); g_file_info_set_attribute_uint64(file_info, "time::modified", ctime); g_file_info_set_attribute_uint64(file_info, "time::created", ctime); g_file_info_set_attribute_uint64(file_info, "time::access", ctime); g_file_set_attributes_from_info (project_file, file_info, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (G_OBJECT(file_info));; } } else { /* For unknown project backend we use the directory project file and * replace the backend plugin with the right one */ gchar *content; gsize length; source_file = g_file_new_for_path (DIRECTORY_PROJECT_FILE); if (g_file_load_contents (source_file, NULL, &content, &length, NULL, &error)) { GString *buffer; const gchar *pos; const gchar *plugin; const gchar *end_plugin; gssize len; buffer = g_string_new_len (content, length); pos = buffer->str; len = buffer->len; for (;;) { plugin = g_strstr_len (pos, len, "<plugin "); if (plugin == NULL) break; end_plugin = g_strstr_len (plugin, len - (plugin - pos), "</plugin>"); if (end_plugin == NULL) break; if (g_strstr_len (plugin, end_plugin - plugin, "\"IAnjutaProjectBackend\"") != NULL) break; pos = end_plugin + 9; len -= (end_plugin + 9 - pos); } if ((plugin == NULL) || (end_plugin == NULL)) { g_set_error (&error, ianjuta_project_backend_error_quark(),0, "Unable to find backend plugin"); } else { /* Replace directory backend with right one */ GString *str; GFileOutputStream *stream; gchar *name = NULL; gchar *plugin_id = NULL; anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Name", &name); anjuta_plugin_description_get_string (backend, "Anjuta Plugin", "Location", &plugin_id); str = g_string_new (NULL); g_string_printf (str, "<plugin name= \"%s\"\n" " mandatory=\"yes\">\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Location\"\n" " value=\"%s\"/>\n" " <require group=\"Anjuta Plugin\"\n" " attribute=\"Interfaces\"\n" " value=\"IAnjutaProjectBackend\"/>\n" " ", name, plugin_id); g_string_erase (buffer, plugin - buffer->str, end_plugin - plugin); g_string_insert_len (buffer, plugin - buffer->str, str->str, str->len); g_string_free (str, TRUE); stream = g_file_create (project_file, G_FILE_CREATE_NONE, NULL, &error); if (stream == NULL && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_EXISTS) { gchar *prjfile = g_file_get_parse_name (project_file); if (anjuta_util_dialog_boolean_question (GTK_WINDOW (import_dialog), FALSE, _("A file named \"%s\" already exists. " "Do you want to replace it?"), prjfile)) { g_error_free (error); error = NULL; stream = g_file_replace (project_file, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error); } g_free (prjfile); } if (stream != NULL) { gsize written; g_output_stream_write_all (G_OUTPUT_STREAM (stream), buffer->str, buffer->len, &written, NULL, &error); g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL); } } g_string_free (buffer, TRUE); g_free (content); } } g_object_unref (source_file); if (error) { gchar *prjfile; prjfile = g_file_get_parse_name (project_file); /* show the dialog since it may be hidden */ gtk_widget_show (GTK_WIDGET (import_dialog)); anjuta_util_dialog_error (GTK_WINDOW (import_dialog), _("A file named \"%s\" cannot be written: %s. " "Check if you have write access to the project directory."), prjfile, error->message); g_free (prjfile); g_error_free (error); return FALSE; } return TRUE; }
static GConverterResult g_zlib_decompressor_convert (GConverter *converter, const void *inbuf, gsize inbuf_size, void *outbuf, gsize outbuf_size, GConverterFlags flags, gsize *bytes_read, gsize *bytes_written, GError **error) { GZlibDecompressor *decompressor; int res; decompressor = G_ZLIB_DECOMPRESSOR (converter); decompressor->zstream.next_in = (void *)inbuf; decompressor->zstream.avail_in = inbuf_size; decompressor->zstream.next_out = outbuf; decompressor->zstream.avail_out = outbuf_size; res = inflate (&decompressor->zstream, Z_NO_FLUSH); if (res == Z_DATA_ERROR || res == Z_NEED_DICT) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, _("Invalid compressed data")); return G_CONVERTER_ERROR; } if (res == Z_MEM_ERROR) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Not enough memory")); return G_CONVERTER_ERROR; } if (res == Z_STREAM_ERROR) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Internal error: %s"), decompressor->zstream.msg); return G_CONVERTER_ERROR; } if (res == Z_BUF_ERROR) { if (flags & G_CONVERTER_FLUSH) return G_CONVERTER_FLUSHED; /* Z_FINISH not set, so this means no progress could be made */ /* We do have output space, so this should only happen if we have no input but need some */ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT, _("Need more input")); return G_CONVERTER_ERROR; } g_assert (res == Z_OK || res == Z_STREAM_END); *bytes_read = inbuf_size - decompressor->zstream.avail_in; *bytes_written = outbuf_size - decompressor->zstream.avail_out; #if !defined (G_OS_WIN32) || ZLIB_VERNUM >= 0x1240 if (decompressor->header_data != NULL && decompressor->header_data->gzheader.done == 1) { HeaderData *data = decompressor->header_data; /* So we don't notify again */ data->gzheader.done = 2; data->file_info = g_file_info_new (); g_file_info_set_attribute_uint64 (data->file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED, data->gzheader.time); g_file_info_set_attribute_uint32 (data->file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC, 0); if (data->filename[0] != '\0') g_file_info_set_attribute_byte_string (data->file_info, G_FILE_ATTRIBUTE_STANDARD_NAME, data->filename); g_object_notify (G_OBJECT (decompressor), "file-info"); } #endif /* !G_OS_WIN32 || ZLIB >= 1.2.4 */ if (res == Z_STREAM_END) return G_CONVERTER_FINISHED; return G_CONVERTER_CONVERTED; }
static gboolean fm_file_info_job_run(FmJob* fmjob) { GList* l; FmFileInfoJob* job = (FmFileInfoJob*)fmjob; GError* err = NULL; if(job->file_infos == NULL) return FALSE; for(l = fm_file_info_list_peek_head_link(job->file_infos); !fm_job_is_cancelled(fmjob) && l;) { FmFileInfo* fi = (FmFileInfo*)l->data; GList* next = l->next; FmPath* path = fm_file_info_get_path(fi); if(job->current) fm_path_unref(job->current); job->current = fm_path_ref(path); if(fm_path_is_native(path)) { char* path_str = fm_path_to_str(path); if(!_fm_file_info_job_get_info_for_native_file(fmjob, fi, path_str, &err)) { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_free(path_str); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); g_free(path_str); /* recursively set display names for path parents */ _check_native_display_names(fm_path_get_parent(path)); } else { GFile* gf; gf = fm_path_to_gfile(path); if(!_fm_file_info_job_get_info_for_gfile(fmjob, fi, gf, &err)) { if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_NOT_MOUNTED) { GFileInfo *inf; /* location by link isn't mounted; unfortunately we cannot launch a target if we don't know what kind of target we have; lets make a simplest directory-kind GFIleInfo */ /* FIXME: this may be dirty a bit */ g_error_free(err); err = NULL; inf = g_file_info_new(); g_file_info_set_file_type(inf, G_FILE_TYPE_DIRECTORY); g_file_info_set_name(inf, fm_path_get_basename(path)); g_file_info_set_display_name(inf, fm_path_get_basename(path)); fm_file_info_set_from_g_file_data(fi, gf, inf); g_object_unref(inf); } else { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) { g_object_unref(gf); continue; /* retry */ } fm_file_info_list_delete_link(job->file_infos, l); /* also calls unref */ goto _next; } } else if(G_UNLIKELY(job->flags & FM_FILE_INFO_JOB_EMIT_FOR_EACH_FILE)) fm_job_call_main_thread(fmjob, _emit_current_file, fi); /* recursively set display names for path parents */ _check_gfile_display_names(fm_path_get_parent(path), gf); _next: g_object_unref(gf); } l = next; } return TRUE; }
/* Function implementations */ static void fl_parser_start_node_cb (void *user_data, const char *node_name, const char **attr) { ParserData *data; GFileInfo *info; data = (ParserData *) user_data; data->depth++; d(g_print ("%d: %s\n", data->depth, node_name)); if (data->depth > 2) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'", node_name); return; } else if (data->depth == 1) { if (strcmp (node_name, "folder-listing") != 0) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Expected 'folder-listing', got '%s'", node_name); return; } return; } if (strcmp (node_name, "parent-folder") == 0) { /* Just ignore parent-folder items */ return; } info = g_file_info_new (); if (strcmp (node_name, "file") == 0) { g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); } else if (strcmp (node_name, "folder") == 0) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new ("folder"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } else { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unknown element '%s'", node_name); return; } if (!fl_parser_fill_file_info (info, attr)) { d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n", node_name)); g_object_unref (info); return; } if (g_file_info_get_content_type (info) == NULL) { char *mime_type; mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL); g_file_info_set_content_type (info, mime_type); g_free (mime_type); } if (g_file_info_get_content_type (info) == NULL) { g_file_info_set_content_type (info, "application/octet-stream"); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) { GIcon *icon; const char *content_type; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic"); g_file_info_set_icon (info, icon); g_object_unref (icon); } icon = g_content_type_get_symbolic_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } } /* Permissions on folders in OBEX has different semantics than POSIX. * In POSIX, if a folder is not writable, it means that it's content * can't be removed, whereas in OBEX, it just means that the folder * itself can't be removed. Therefore we must set all folders to RWD and * handle the error when it happens. */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } data->elements = g_list_prepend (data->elements, info); }
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); } }
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; }
void ide_project_files_add_file (IdeProjectFiles *self, IdeProjectFile *file) { IdeProjectItem *item = (IdeProjectItem *)self; g_autoptr(GFile) parent = NULL; g_autofree gchar *path = NULL; IdeContext *context; IdeVcs *vcs; GFile *workdir; GFile *gfile; gchar **parts; gsize i; g_return_if_fail (IDE_IS_PROJECT_FILES (self)); g_return_if_fail (IDE_IS_PROJECT_FILE (file)); context = ide_object_get_context (IDE_OBJECT (self)); vcs = ide_context_get_vcs (context); workdir = ide_vcs_get_working_directory (vcs); gfile = ide_project_file_get_file (file); parent = g_file_get_parent (gfile); path = g_file_get_relative_path (workdir, parent); if (path == NULL) { ide_project_item_append (IDE_PROJECT_ITEM (self), IDE_PROJECT_ITEM (file)); return; } parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0); for (i = 0; parts [i]; i++) { IdeProjectItem *found; found = ide_project_files_find_child (item, parts [i]); if (found == NULL) { g_autoptr(GFileInfo) file_info = NULL; g_autofree gchar *child_path = NULL; IdeProjectItem *child; const gchar *item_path; g_autoptr(GFile) item_file = NULL; file_info = g_file_info_new (); g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY); g_file_info_set_display_name (file_info, parts [i]); g_file_info_set_name (file_info, parts [i]); item_path = ide_project_file_get_path (IDE_PROJECT_FILE (item)); child_path = g_strjoin (G_DIR_SEPARATOR_S, item_path, parts [i], NULL); item_file = g_file_get_child (workdir, child_path); child = g_object_new (IDE_TYPE_PROJECT_FILE, "context", context, "parent", item, "path", path, "file", item_file, "file-info", file_info, NULL); ide_project_item_append (item, child); item = child; } else { item = found; } } ide_project_item_append (item, IDE_PROJECT_ITEM (file)); g_strfreev (parts); }
/** * gedit_document_set_metadata: * @doc: a #GeditDocument * @first_key: name of the first key to set * @...: (allow-none): value for the first key, followed optionally by more key/value pairs, * followed by %NULL. * * Sets metadata on a document. */ void gedit_document_set_metadata (GeditDocument *doc, const gchar *first_key, ...) { GeditDocumentPrivate *priv; GFile *location; const gchar *key; va_list var_args; GFileInfo *info = NULL; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); g_return_if_fail (first_key != NULL); priv = gedit_document_get_instance_private (doc); location = gtk_source_file_get_location (priv->file); /* With the metadata manager, can't set metadata for untitled documents. * With GVFS metadata, if the location is NULL the metadata is stored in * priv->metadata_info, so that it can be saved later if the document is * saved. */ if (!priv->use_gvfs_metadata && location == NULL) { return; } if (priv->use_gvfs_metadata) { info = g_file_info_new (); } va_start (var_args, first_key); for (key = first_key; key; key = va_arg (var_args, const gchar *)) { const gchar *value = va_arg (var_args, const gchar *); if (priv->use_gvfs_metadata) { /* Collect the metadata into @info. */ set_gvfs_metadata (doc, info, key, value); } else { gedit_metadata_manager_set (location, key, value); } } va_end (var_args); if (priv->use_gvfs_metadata && location != NULL) { GError *error = NULL; /* We save synchronously since metadata is always local so it * should be fast. Moreover this function can be called on * application shutdown, when the main loop has already exited, * so an async operation would not terminate. * https://bugzilla.gnome.org/show_bug.cgi?id=736591 */ g_file_set_attributes_from_info (location, info, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { /* Do not complain about metadata if we are closing a * document for a non existing file. */ if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_warning ("Set document metadata failed: %s", error->message); } g_error_free (error); } } g_clear_object (&info); }
static void on_location_changed (GtkSourceFile *file, GParamSpec *pspec, GeditDocument *doc) { GeditDocumentPrivate *priv; GFile *location; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (doc); location = gtk_source_file_get_location (file); if (location != NULL && priv->untitled_number > 0) { release_untitled_number (priv->untitled_number); priv->untitled_number = 0; } if (priv->short_name == NULL) { g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_SHORTNAME]); } /* Load metadata for this location: we load sync since metadata is * always local so it should be fast and we need the information * right after the location was set. */ if (priv->use_gvfs_metadata && location != NULL) { GError *error = NULL; if (priv->metadata_info != NULL) { g_object_unref (priv->metadata_info); } priv->metadata_info = g_file_query_info (location, METADATA_QUERY, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { /* Do not complain about metadata if we are opening a * non existing file. */ if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_ISDIR) && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOTDIR) && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_warning ("%s", error->message); } g_error_free (error); } if (priv->metadata_info == NULL) { priv->metadata_info = g_file_info_new (); } } }
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; }
gboolean nautilus_keyfile_metadata_update_from_keyfile (NautilusFile *file, const char *keyfile_filename, const gchar *name) { gchar **keys, **values; const gchar *actual_values[2]; const gchar *key, *value; gchar *gio_key; gsize length, values_length; GKeyFile *keyfile; GFileInfo *info; gint idx; gboolean res; keyfile = get_keyfile (keyfile_filename); keys = g_key_file_get_keys (keyfile, name, &length, NULL); if (keys == NULL) { return FALSE; } info = g_file_info_new (); for (idx = 0; idx < length; idx++) { key = keys[idx]; values = g_key_file_get_string_list (keyfile, name, key, &values_length, NULL); gio_key = g_strconcat ("metadata::", key, NULL); if (values_length < 1) { continue; } else if (values_length == 1) { g_file_info_set_attribute_string (info, gio_key, values[0]); } else if (values_length == 2) { /* deal with the fact that single-length strv are stored * with an additional terminator in the keyfile string, to differentiate * them from the regular string case. */ value = values[1]; if (g_strcmp0 (value, STRV_TERMINATOR) == 0) { /* if the 2nd value is the terminator, remove it */ actual_values[0] = values[0]; actual_values[1] = NULL; g_file_info_set_attribute_stringv (info, gio_key, (gchar **) actual_values); } else { /* otherwise, set it as a regular strv */ g_file_info_set_attribute_stringv (info, gio_key, values); } } else { g_file_info_set_attribute_stringv (info, gio_key, values); } g_free (gio_key); g_strfreev (values); } res = nautilus_file_update_metadata_from_info (file, info); g_strfreev (keys); g_object_unref (info); return res; }
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 fm_dir_list_job_run_posix(FmDirListJob* job) { FmJob* fmjob = FM_JOB(job); FmFileInfo* fi; GError *err = NULL; char* path_str; GDir* dir; path_str = fm_path_to_str(job->dir_path); fi = _new_info_for_native_file(job, job->dir_path, path_str, NULL); if(fi) { if(! fm_file_info_is_dir(fi)) { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_file_info_unref(fi); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } job->dir_fi = fi; } else { err = g_error_new(G_IO_ERROR, G_IO_ERROR_NOT_DIRECTORY, _("The specified directory '%s' is not valid"), path_str); fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); g_free(path_str); return FALSE; } dir = g_dir_open(path_str, 0, &err); if( dir ) { const char* name; GString* fpath = g_string_sized_new(4096); int dir_len = strlen(path_str); g_string_append_len(fpath, path_str, dir_len); if(fpath->str[dir_len-1] != '/') { g_string_append_c(fpath, '/'); ++dir_len; } while( ! fm_job_is_cancelled(fmjob) && (name = g_dir_read_name(dir)) ) { FmPath* new_path; g_string_truncate(fpath, dir_len); g_string_append(fpath, name); if(job->flags & FM_DIR_LIST_JOB_DIR_ONLY) /* if we only want directories */ { struct stat st; /* FIXME: this results in an additional stat() call, which is inefficient */ if(stat(fpath->str, &st) == -1 || !S_ISDIR(st.st_mode)) continue; } new_path = fm_path_new_child(job->dir_path, name); _retry: fi = _new_info_for_native_file(job, new_path, fpath->str, &err); if (fi == NULL) /* we got a damaged file */ { FmJobErrorAction act = fm_job_emit_error(fmjob, err, FM_JOB_ERROR_MILD); GFile *gf; GFileInfo *inf; gchar *disp_basename; g_error_free(err); err = NULL; if(act == FM_JOB_RETRY) goto _retry; /* bug #3615271: Damaged mountpoint isn't shown let make a simple file info then */ inf = g_file_info_new(); gf = fm_path_to_gfile(new_path); g_file_info_set_file_type(inf, G_FILE_TYPE_UNKNOWN); g_file_info_set_name(inf, name); disp_basename = g_filename_display_basename(fpath->str); g_file_info_set_display_name(inf, disp_basename); g_free(disp_basename); g_file_info_set_content_type(inf, "inode/x-corrupted"); fi = fm_file_info_new_from_g_file_data(gf, inf, new_path); g_object_unref(inf); g_object_unref(gf); } fm_dir_list_job_add_found_file(job, fi); fm_file_info_unref(fi); fm_path_unref(new_path); } g_string_free(fpath, TRUE); g_dir_close(dir); } else { fm_job_emit_error(fmjob, err, FM_JOB_ERROR_CRITICAL); g_error_free(err); } g_free(path_str); return TRUE; }