/** * katja_dl_real_collect_cache_info: **/ GSList *katja_dl_real_collect_cache_info(KatjaPkgtools *pkgtools, const gchar *tmpl) { CURL *curl = NULL; gchar **source_dest; GSList *file_list = NULL; GFile *tmp_dir, *repo_tmp_dir; /* Create the temporary directory for the repository */ tmp_dir = g_file_new_for_path(tmpl); repo_tmp_dir = g_file_get_child(tmp_dir, pkgtools->name->str); g_file_make_directory(repo_tmp_dir, NULL, NULL); /* There is no ChangeLog yet to check if there are updates or not. Just mark the index file for download */ source_dest = g_malloc_n(3, sizeof(gchar *)); source_dest[0] = g_strdup(KATJA_DL(pkgtools)->index_file->str); source_dest[1] = g_build_filename(tmpl, pkgtools->name->str, "IndexFile", NULL); source_dest[2] = NULL; /* Check if the remote file can be found */ if (katja_pkgtools_get_file(&curl, source_dest[0], NULL)) g_strfreev(source_dest); else file_list = g_slist_append(file_list, source_dest); g_object_unref(repo_tmp_dir); g_object_unref(tmp_dir); if (curl) curl_easy_cleanup(curl); return file_list; }
void filebrowser_backend_create_dir(FilebrowserBackend *filebackend, gchar *filename, gchar *name, gboolean isdir){ FilebrowserBackendDetails *directory = FILEBROWSER_BACKEND_GET_PRIVATE(filebackend); GFile *config; GError *error=NULL; gchar *filename_int; if (isdir){ gchar *parent=filename_parent_uri(filename); filename_int= g_strdup_printf("%s/%s",parent,name); g_free(parent); config= g_file_new_for_commandline_arg(filename_int); } else { gchar *parent; if (filename) { parent=filename_parent_uri(filename); } else { parent=g_strdup(directory->current_folder); } filename_int= g_build_path (G_DIR_SEPARATOR_S, parent, name, NULL); g_free(parent); config=g_file_new_for_commandline_arg(filename_int); } gphpedit_debug_message(DEBUG_FILEBROWSER, "New directory:%s",filename_int); g_free(filename_int); if (!g_file_make_directory (config, directory->cancellable, &error)){ g_print(_("Error creating folder. GIO error:%s\n"), error->message); g_error_free (error); } g_object_unref(config); filebrowser_backend_refresh_folder (filebackend); }
static gboolean prepare_root_ssh (GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GFile *root_ssh_path = g_file_new_for_path ("/root/.ssh"); if (!g_file_query_exists (root_ssh_path, NULL)) { if (!g_file_make_directory (root_ssh_path, cancellable, error)) goto out; if (!gs_file_chmod (root_ssh_path, 0700, cancellable, error)) goto out; /* Ignore errors here to be simple, otherwise we'd have to link * to libselinux etc. */ (void) gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL, cancellable, error, "restorecon", gs_file_get_path_cached (root_ssh_path), NULL); } ret = TRUE; out: return ret; }
/* save preferences values in a 'spectrum3drc' preferences file */ void print_rc_file(){ printf("Saving preferences :\n"); int i = 0; GError *error = NULL; char rcDirectoryPath[100] = ""; /* Preference file ('spectrum3drc') is in the /HOME/.spectrum3d/ directory; this directory will be created first if it doesn't exist; if it cannot be created, error message will be generated */ sprintf(rcDirectoryPath, "%s/.spectrum3d/", g_get_home_dir()); printf(" - Looking for '/HOME/.spectrum3d' directory ... "); GFile *rcDirectory = g_file_new_for_path (rcDirectoryPath); if (g_file_make_directory (rcDirectory, NULL, &error)){ printf("doesn't exist -> creating\n"); } else { if (error != NULL){ if (error->code == G_FILE_ERROR_ACCES){ printf("OK\n"); } else { gchar message[500]; sprintf(message, "\nUnable to create directory '%s' : %s\n", rcDirectoryPath, error->message); printf ("%s\n", message); error_message_window(message); } g_error_free (error); } else { gchar *message = "\nUnable to create directory, but GError is NULL\n"; printf("%s\n", message); error_message_window(message); } } /* Preferences file will be open to be written with preferences values */ rcFile = fopen(rcPath, "w+"); /* Check if opening was succefull, then write current values to the file, then close it */ if (rcFile != NULL){ int result = 0; printf(" - Opening rc file and writing preferences values"); fprintf(rcFile, "# This is an spectrum3drc file autogenerated by Spectrum3d \n"); for (i = 0; i < sizeofPrefInt ; i++){ result = fprintf(rcFile, "# %s \n%d\n", preferenceInt[i].name, *preferenceInt[i].var); ERROR_MESSAGE_PRINT_IN_RCFILE() } for (i = 0; i < sizeofPrefGLFloat ; i++){ fprintf(rcFile, "# %s \n%f\n", preferenceGLFloat[i].name, *preferenceGLFloat[i].var); ERROR_MESSAGE_PRINT_IN_RCFILE() } for (i = 0; i < sizeofPrefGbool ; i++){ fprintf(rcFile, "# %s \n%d\n", preferenceGbool[i].name, *preferenceGbool[i].var); ERROR_MESSAGE_PRINT_IN_RCFILE() } /*for (i = 0; i < sizeofPrefString ; i++){ fprintf(rcFile, "# %s \n%s\n", prefStringPossibleValue[i][0], preferenceString[i]); ERROR_MESSAGE_PRINT_IN_RCFILE() }*/ fclose(rcFile); printf("... OK\n"); }
JS_EXPORT_API GFile* desktop_new_directory(const char* name_add_before) { GFile* dir = _get_useable_file_templates(_("New directory"),name_add_before); g_file_make_directory(dir, NULL, NULL); //TODO: detect create status.. return dir; }
int main (int argc, char *argv[]) { GError *error; GOptionContext *context; GFile *file; setlocale (LC_ALL, ""); g_type_init (); error = NULL; context = g_option_context_new ("- delete files"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (error != NULL) { g_printerr ("Error parsing commandline options: %s\n", error->message); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); g_error_free(error); return 1; } if (argc > 1) { int i; for (i = 1; i < argc; i++) { file = g_file_new_for_commandline_arg (argv[i]); error = NULL; if (parent) { if (!g_file_make_directory_with_parents (file, NULL, &error)) { g_print ("Error creating directory: %s\n", error->message); g_error_free (error); } } else { if (!g_file_make_directory (file, NULL, &error)) { g_print ("Error creating directory: %s\n", error->message); g_error_free (error); } g_object_unref (file); } } } return 0; }
void subversion_ivcs_checkout (IAnjutaVcs *obj, const gchar *repository_location, GFile *dest, GCancellable *cancel, AnjutaAsyncNotify *notify, GError **err) { GError *error; gchar *path; SvnCheckoutCommand *checkout_command; Subversion *plugin; error = NULL; g_file_make_directory (dest, NULL, &error); if (error) { if (error->code != G_IO_ERROR_EXISTS) { g_propagate_error (err, error); return; } g_error_free (error); } path = g_file_get_path (dest); checkout_command = svn_checkout_command_new (repository_location, path); plugin = ANJUTA_PLUGIN_SUBVERSION (obj); g_free (path); create_message_view (plugin); g_signal_connect (G_OBJECT (checkout_command), "data-arrived", G_CALLBACK (on_command_info_arrived), plugin); g_signal_connect (G_OBJECT (checkout_command), "command-finished", G_CALLBACK (g_object_unref), NULL); if (cancel) { g_signal_connect_swapped (G_OBJECT (cancel), "cancelled", G_CALLBACK (anjuta_command_cancel), checkout_command); } if (notify) { g_signal_connect_swapped (G_OBJECT (checkout_command), "command-finished", G_CALLBACK (anjuta_async_notify_notify_finished), notify); } anjuta_command_start (ANJUTA_COMMAND (checkout_command)); }
/* Tests the function for a directory containing one directory */ static void test_directory_one_file (void) { g_autoptr (GFile) root = NULL; g_autoptr (GFile) parent_dir = NULL; g_autoptr (GFile) child_file = NULL; root = g_file_new_for_path (g_get_tmp_dir ()); parent_dir = g_file_get_child (root, "parent_dir"); g_assert_true (parent_dir != NULL); g_file_make_directory (parent_dir, NULL, NULL); child_file = g_file_get_child (parent_dir, "child_file"); g_assert_true (child_file != NULL); g_file_make_directory (child_file, NULL, NULL); g_assert_true (dir_has_files (parent_dir)); g_assert_true (g_file_delete (child_file, NULL, NULL)); g_assert_true (g_file_delete (parent_dir, NULL, NULL)); }
/** * ai_generate_create_icon_directories: **/ static gboolean ai_generate_create_icon_directories (const gchar *directory) { gboolean ret; GError *error = NULL; GFile *file; gchar *path; guint i; /* create main directory */ ret = g_file_test (directory, G_FILE_TEST_IS_DIR); if (!ret) { file = g_file_new_for_path (directory); ret = g_file_make_directory (file, NULL, &error); g_object_unref (file); if (!ret) { egg_warning ("cannot create %s: %s", directory, error->message); g_error_free (error); goto out; } } /* make sub directories */ for (i=0; icon_sizes[i] != NULL; i++) { path = g_build_filename (directory, icon_sizes[i], NULL); ret = g_file_test (path, G_FILE_TEST_IS_DIR); if (!ret) { egg_debug ("creating %s", path); file = g_file_new_for_path (path); ret = g_file_make_directory (file, NULL, &error); if (!ret) { egg_warning ("cannot create %s: %s", path, error->message); g_clear_error (&error); } g_object_unref (file); } g_free (path); } out: return ret; }
/* First cancel timeout * this func is most probably stupid it might exists (move file) */ gboolean biji_note_obj_trash (BijiNoteObj *note_to_kill) { GFile *to_trash, *parent, *trash, *backup_file; gchar *note_name, *parent_path, *trash_path, *backup_path; GError *error = NULL; gboolean result; biji_timeout_cancel (note_to_kill->priv->timeout); to_trash = biji_note_id_get_file (note_to_kill->priv->id); note_name = g_file_get_basename (to_trash); parent = g_file_get_parent (to_trash); /* Create the trash directory * No matter if already exists */ parent_path = g_file_get_path (parent); trash_path = g_build_filename (parent_path, ".Trash", NULL); g_free (parent_path); g_object_unref (parent); trash = g_file_new_for_path (trash_path); g_file_make_directory (trash, NULL, NULL); /* Move the note to trash */ backup_path = g_build_filename (trash_path, note_name, NULL); g_free (trash_path); backup_file = g_file_new_for_path (backup_path); g_free (note_name); g_free (backup_path); result = g_file_move (to_trash, backup_file, G_FILE_COPY_NONE, NULL, // cancellable NULL, // progress callback NULL, // progress_callback_data, &error); if (error) { g_message (error->message); g_error_free (error); error = NULL; } /* Say goodbye however */ g_object_unref (trash); g_object_unref (backup_file); biji_note_delete_from_tracker (note_to_kill); g_signal_emit (G_OBJECT (note_to_kill), biji_obj_signals[NOTE_DELETED], 0); g_clear_object (¬e_to_kill); return result; }
static gboolean dl_sync_dir(mega_node* node, GFile* file, const gchar* remote_path) { GError *local_err = NULL; gchar* local_path = g_file_get_path(file); if (!g_file_query_exists(file, NULL)) { g_print("D %s\n", local_path); if (!opt_dryrun) { if (!g_file_make_directory(file, NULL, &local_err)) { g_printerr("ERROR: Can't create local directory %s: %s\n", local_path, local_err->message); g_clear_error(&local_err); return FALSE; } } } else { if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) != G_FILE_TYPE_DIRECTORY) { g_printerr("ERROR: Can't create local directory %s: file exists\n", local_path); return FALSE; } } // sync children GSList* children = mega_session_get_node_chilren(s, node), *i; for (i = children; i; i = i->next) { mega_node* child = i->data; gchar* child_remote_path = g_strconcat(remote_path, "/", child->name, NULL); GFile* child_file = g_file_get_child(file, child->name); if (child->type == MEGA_NODE_FILE) { dl_sync_file(child, child_file, child_remote_path); } else { dl_sync_dir(child, child_file, child_remote_path); } g_object_unref(child_file); g_free(child_remote_path); } g_slist_free(children); return TRUE; }
GFile * create_gpg_keys_directory (GFile *containing_directory, const gchar *source_gpg_home_path) { gsize i; const gchar * const gpg_home_files[] = { "C1EB8F4E.asc", "keyid", "pubring.gpg", "random_seed", "secring.gpg", }; g_autoptr(GError) error = NULL; g_autoptr(GFile) gpg_home = g_file_get_child (containing_directory, "gpghome"); g_file_make_directory (gpg_home, NULL, &error); g_assert_no_error (error); g_file_set_attribute_uint32 (gpg_home, G_FILE_ATTRIBUTE_UNIX_MODE, 0700, G_FILE_QUERY_INFO_NONE, NULL, &error); g_assert_no_error (error); /* Copy the GPG files from the source directory into the fixture directory, * as running GPG with them as its homedir might alter them; we don’t want * that to happen in the source directory, which might be read-only (and in * any case, we want determinism). */ for (i = 0; i < G_N_ELEMENTS (gpg_home_files); i++) { g_autofree gchar *source_path = NULL; g_autoptr (GFile) source = NULL, destination = NULL; source_path = g_build_filename (source_gpg_home_path, gpg_home_files[i], NULL); source = g_file_new_for_path (source_path); destination = g_file_get_child (gpg_home, gpg_home_files[i]); g_file_copy (source, destination, G_FILE_COPY_NONE, NULL, NULL, NULL, &error); g_assert_no_error (error); g_file_set_attribute_uint32 (destination, G_FILE_ATTRIBUTE_UNIX_MODE, 0600, G_FILE_QUERY_INFO_NONE, NULL, &error); g_assert_no_error (error); } return g_steal_pointer (&gpg_home); }
/*Recursively copy the source file/folder to the destination.*/ void codeslayer_utils_file_copy (GFile *source, GFile *destination, GError **error) { GFileInfo *source_file_info; GFileEnumerator *enumerator; source_file_info = g_file_query_info (source, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (g_file_info_get_file_type (source_file_info) == G_FILE_TYPE_DIRECTORY) g_file_make_directory (destination, NULL, NULL); else g_file_copy (source, destination, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL); g_object_unref (source_file_info); enumerator = g_file_enumerate_children (source, "standard::*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (enumerator != NULL) { GFileInfo *file_info; while ((file_info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) { GFile *source_child; GFile *destination_child; const char *file_name = g_file_info_get_name (file_info); source_child = g_file_get_child (source, file_name); destination_child = g_file_get_child (destination, file_name); if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY) codeslayer_utils_file_copy (source_child, destination_child, NULL); else g_file_copy (source_child, destination_child, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL); g_object_unref (source_child); g_object_unref (destination_child); g_object_unref (file_info); } g_object_unref (enumerator); } }
JS_EXPORT_API GFile* desktop_create_rich_dir(ArrayContainer fs) { char* group_name = dentry_get_rich_dir_group_name(fs); char* temp_name = g_strconcat (DEEPIN_RICH_DIR, _(group_name), NULL); g_free(group_name); g_debug ("create_rich_dir: %s", temp_name); GFile* dir = _get_useable_file(temp_name); g_free(temp_name); g_file_make_directory(dir, NULL, NULL); dentry_move(fs, dir, TRUE); return dir; }
/* Tests the function for an empty directory */ static void test_empty_directory (void) { g_autoptr (GFile) root = NULL; g_autoptr (GFile) child = NULL; root = g_file_new_for_path (g_get_tmp_dir ()); child = g_file_get_child (root, "empty_dir"); g_assert_true (child != NULL); g_file_make_directory (child, NULL, NULL); g_assert_false (dir_has_files (child)); g_assert_true (g_file_delete (child, NULL, NULL)); }
/** * gs_file_ensure_directory: * @dir: Path to create as directory * @with_parents: Also create parent directories * @cancellable: a #GCancellable * @error: a #GError * * Like g_file_make_directory(), except does not throw an error if the * directory already exists. */ gboolean gs_file_ensure_directory (GFile *dir, gboolean with_parents, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GError *temp_error = NULL; GFile *parent = NULL; if (!g_file_make_directory (dir, cancellable, &temp_error)) { if (with_parents && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { parent = g_file_get_parent (dir); if (parent) { g_clear_error (&temp_error); if (!glnx_shutil_mkdir_p_at (AT_FDCWD, gs_file_get_path_cached (parent), 0777, cancellable, error)) goto out; } if (!gs_file_ensure_directory (dir, FALSE, cancellable, error)) goto out; } else if (!g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, temp_error); goto out; } else g_clear_error (&temp_error); } ret = TRUE; out: g_clear_object (&parent); return ret; }
static void biji_note_book_constructed (GObject *object) { BijiNoteBook *self; BijiNoteBookPrivate *priv; BijiProvider *provider; gchar *filename; GFile *cache; GError *error; G_OBJECT_CLASS (biji_note_book_parent_class)->constructed (object); self = BIJI_NOTE_BOOK (object); priv = self->priv; error = NULL; /* If tracker fails for some reason, * do not attempt anything */ priv->connection = tracker_sparql_connection_get (NULL, &error); if (error) { g_warning ("%s", error->message); g_error_free (error); priv->error = g_error_new (BIJI_ERROR, BIJI_ERROR_TRACKER, "Tracker is not available"); return; } priv->log = biji_zeitgeist_init (); /* Ensure cache directory for icons */ filename = g_build_filename (g_get_user_cache_dir (), g_get_application_name (), NULL); cache = g_file_new_for_path (filename); g_free (filename); g_file_make_directory (cache, NULL, NULL); g_object_unref (cache); provider = biji_local_provider_new (self, self->priv->location); _add_provider (self, provider); }
static gboolean create_parent_dirs (GFile *file, GError **error) { gboolean ret; GFile *parent; ret = check_file_is_directory (file, error); if (ret == TRUE || *error != NULL) { return ret; } parent = g_file_get_parent (file); ret = create_parent_dirs (parent, error); g_object_unref (parent); if (ret == FALSE) { return FALSE; } return g_file_make_directory (file, NULL, error); }
static void shell_global_init (ShellGlobal *global) { const char *datadir = g_getenv ("GNOME_SHELL_DATADIR"); char *imagedir; GFile *conf_dir; if (!datadir) datadir = GNOME_SHELL_DATADIR; global->datadir = datadir; /* We make sure imagedir ends with a '/', since the JS won't have * access to g_build_filename() and so will end up just * concatenating global.imagedir to a filename. */ imagedir = g_build_filename (datadir, "images/", NULL); if (g_file_test (imagedir, G_FILE_TEST_IS_DIR)) global->imagedir = imagedir; else { g_free (imagedir); global->imagedir = g_strdup_printf ("%s/", datadir); } /* Ensure config dir exists for later use */ global->configdir = g_build_filename (g_get_home_dir (), ".gnome2", "shell", NULL); conf_dir = g_file_new_for_path (global->configdir); g_file_make_directory (conf_dir, NULL, NULL); g_object_unref (conf_dir); global->grab_notifier = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); g_signal_connect (global->grab_notifier, "grab-notify", G_CALLBACK (grab_notify), global); global->gtk_grab_active = FALSE; global->root_pixmap = NULL; global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL; global->last_change_screen_width = 0; global->last_change_screen_height = 0; }
int32 MakeDir(ExtensionString path, int mode) { const char *pathStr = path.c_str(); GFile *file; GError *gerror = NULL; int32 error = NO_ERROR; if (g_file_test(pathStr, G_FILE_TEST_EXISTS)) { return ERR_FILE_EXISTS; } file = g_file_new_for_path(pathStr); mode = mode | 0777; if (!g_file_make_directory(file, NULL, &gerror)) { error = GErrorToErrorCode(gerror); } g_object_unref(file); return error; }
static gboolean amp_group_node_save (AmpNode *group, AmpNode *parent, AmpProject *project, GError **error) { AnjutaTokenFile *tfile; AnjutaProjectNode *child; gboolean ok = TRUE; GFile *directory; /* Check if Makefile.am is missing, it happens in po directory by example */ if (AMP_GROUP_NODE (group)->makefile == NULL) return FALSE; /* Create directory */ directory = g_file_get_parent (AMP_GROUP_NODE (group)->makefile); g_file_make_directory (directory, NULL, NULL); g_object_unref (directory); /* Save group */ tfile = AMP_GROUP_NODE (group)->tfile; if (tfile == NULL) { /* Create an empty makefile */ g_file_replace_contents (AMP_GROUP_NODE (group)->makefile, "", 0, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL); return TRUE; } if (anjuta_token_file_is_dirty (tfile)) { if (!anjuta_token_file_save (tfile, error)) return FALSE; } /* Save all children */ for (child = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (group)); child != NULL; child = anjuta_project_node_next_sibling (child)) { /* Try to save all children even if some fail */ if (!amp_node_save (AMP_NODE (child), group, project, error)) ok = FALSE; } return ok; }
gboolean ot_gfile_ensure_directory (GFile *dir, gboolean with_parents, GError **error) { gboolean ret = FALSE; GError *temp_error = NULL; if (!g_file_make_directory (dir, NULL, &temp_error)) { if (with_parents && g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { ot_lobj GFile *parent = NULL; g_clear_error (&temp_error); parent = g_file_get_parent (dir); if (parent) { if (!ot_gfile_ensure_directory (parent, TRUE, error)) goto out; } if (!ot_gfile_ensure_directory (dir, FALSE, error)) goto out; } else if (!g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, temp_error); goto out; } else g_clear_error (&temp_error); } ret = TRUE; out: return ret; }
/** * anjuta_profile_sync: * @profile: a #AnjutaProfile object. * @error: error propagation and reporting. * * Save the current plugins list in the xml file set with anjuta_profile_set_sync_file(). * * Return value: TRUE on success, FALSE otherwise. */ gboolean anjuta_profile_sync (AnjutaProfile *profile, GError **error) { gboolean ok; gchar *xml_buffer; AnjutaProfilePriv *priv; GError* file_error = NULL; g_return_val_if_fail (ANJUTA_IS_PROFILE (profile), FALSE); priv = profile->priv; if (!priv->sync_file) return FALSE; xml_buffer = anjuta_profile_to_xml (profile); ok = g_file_replace_contents (priv->sync_file, xml_buffer, strlen(xml_buffer), NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &file_error); if (!ok && g_error_matches (file_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { /* Try to create parent directory */ GFile* parent = g_file_get_parent (priv->sync_file); if (g_file_make_directory (parent, NULL, NULL)) { g_clear_error (&file_error); ok = g_file_replace_contents (priv->sync_file, xml_buffer, strlen(xml_buffer), NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, &file_error); } g_object_unref (parent); } g_free (xml_buffer); if (file_error != NULL) g_propagate_error (error, file_error); return ok; }
int handle_mkdir (int argc, char *argv[], gboolean do_help) { GOptionContext *context; gchar *param; GError *error = NULL; GFile *file; int retval = 0; int i; g_set_prgname ("gio mkdir"); /* Translators: commandline placeholder */ param = g_strdup_printf ("%s...", _("LOCATION")); context = g_option_context_new (param); g_free (param); g_option_context_set_help_enabled (context, FALSE); g_option_context_set_summary (context, _("Create directories.")); g_option_context_set_description (context, _("gio mkdir is similar to the traditional mkdir utility, but using GIO\n" "locations instead of local files: for example, you can use something\n" "like smb://server/resource/mydir as location.")); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (do_help) { show_help (context, NULL); return 0; } if (!g_option_context_parse (context, &argc, &argv, &error)) { show_help (context, error->message); g_error_free (error); return 1; } if (argc < 2) { show_help (context, _("No locations gives")); return 1; } g_option_context_free (context); for (i = 1; i < argc; i++) { file = g_file_new_for_commandline_arg (argv[i]); error = NULL; if (parent) { if (!g_file_make_directory_with_parents (file, NULL, &error)) { print_file_error (file, error->message); g_error_free (error); retval = 1; } } else { if (!g_file_make_directory (file, NULL, &error)) { print_file_error (file, error->message); g_error_free (error); retval = 1; } g_object_unref (file); } } return retval; }
static void gth_metadata_provider_comment_write (GthMetadataProvider *self, GthMetadataWriteFlags flags, GthFileData *file_data, const char *attributes, GCancellable *cancellable) { GthComment *comment; GthMetadata *metadata; const char *text; char *data; gsize length; GthStringList *categories; GFile *comment_file; GFile *comment_folder; comment = gth_comment_new (); /* caption */ text = NULL; metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::title"); if (metadata != NULL) text = gth_metadata_get_raw (metadata); gth_comment_set_caption (comment, text); /* comment */ text = NULL; metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description"); if (metadata != NULL) text = gth_metadata_get_raw (metadata); gth_comment_set_note (comment, text); /* location */ text = NULL; metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::location"); if (metadata != NULL) text = gth_metadata_get_raw (metadata); gth_comment_set_place (comment, text); /* time */ text = NULL; metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::datetime"); if (metadata != NULL) text = gth_metadata_get_raw (metadata); gth_comment_set_time_from_exif_format (comment, text); /* keywords */ metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::tags"); categories = gth_metadata_get_string_list (metadata); if (categories != NULL) { GList *list; GList *scan; list = gth_string_list_get_list (categories); for (scan = list; scan; scan = scan->next) gth_comment_add_category (comment, (char *) scan->data); } /* rating */ metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::rating"); if (metadata != NULL) { int rating; sscanf (gth_metadata_get_raw (metadata), "%d", &rating); gth_comment_set_rating (comment, rating); } data = gth_comment_to_data (comment, &length); comment_file = gth_comment_get_comment_file (file_data->file); comment_folder = g_file_get_parent (comment_file); g_file_make_directory (comment_folder, NULL, NULL); _g_file_write (comment_file, FALSE, 0, data, length, cancellable, NULL); g_object_unref (comment_folder); g_object_unref (comment_file); g_free (data); g_object_unref (comment); }
static gboolean gtk_hotkey_key_file_registry_real_store_hotkey (GtkHotkeyRegistry *base, GtkHotkeyInfo *info, GError **error) { GKeyFile *keyfile; GFile *file, *home; GError *tmp_error; gchar *file_path, *group; g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); /* Make sure we have our root dir */ home = get_hotkey_home (); if (!g_file_query_exists(home, NULL)) { tmp_error = NULL; if (!g_file_make_directory (home, NULL, &tmp_error)) { g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR, GTK_HOTKEY_REGISTRY_ERROR_IO, "Failed to create hotkey configuration dir " HOTKEY_HOME": %s", tmp_error->message); g_error_free (tmp_error); g_object_unref (home); return FALSE; } } /* Now load any old contents of the keyfile */ file = get_hotkey_file (gtk_hotkey_info_get_application_id (info)); file_path = g_file_get_path (file); keyfile = g_key_file_new (); tmp_error = NULL; if (!g_key_file_load_from_file (keyfile, file_path, 0, &tmp_error)) { if (tmp_error->code == G_KEY_FILE_ERROR_PARSE) { g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR, GTK_HOTKEY_REGISTRY_ERROR_MALFORMED_MEDIUM, "The file %s is not in a valid key-file format: %s", file_path, tmp_error->message); goto clean_up; } /* Ignore other errors */ g_error_free (tmp_error); } /* Prepare keyfile data */ group = g_strconcat (HOTKEY_GROUP, gtk_hotkey_info_get_key_id (info), NULL); g_key_file_set_string (keyfile, group, "Owner", gtk_hotkey_info_get_application_id (info)); g_key_file_set_string (keyfile, group, "Signature", gtk_hotkey_info_get_signature (info)); if (gtk_hotkey_info_get_description (info)) g_key_file_set_string (keyfile, group, "Description", gtk_hotkey_info_get_description (info)); if (gtk_hotkey_info_get_app_info (info)) { GAppInfo *ai = gtk_hotkey_info_get_app_info (info); g_key_file_set_string (keyfile, group, "AppInfo", g_app_info_get_id (ai)); } gsize size; gchar *contents; tmp_error = NULL; contents = g_key_file_to_data (keyfile, &size, &tmp_error); if (tmp_error) { g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR, GTK_HOTKEY_REGISTRY_ERROR_UNKNOWN, "Failed to generate keyfile contents: %s", tmp_error->message); goto clean_up; } /* Write the actual data */ g_file_set_contents (file_path, contents, size, &tmp_error); if (tmp_error) { g_set_error (error, GTK_HOTKEY_REGISTRY_ERROR, GTK_HOTKEY_REGISTRY_ERROR_IO, "Failed to write keyfile '%s': %s", file_path, tmp_error->message); goto clean_up; } clean_up: if (tmp_error) g_error_free (tmp_error); g_free (file_path); if (group) g_free (group); g_key_file_free (keyfile); g_object_unref (file); g_object_unref (home); if (*error) return FALSE; g_return_val_if_fail (GTK_HOTKEY_IS_INFO (info), FALSE); gtk_hotkey_registry_hotkey_stored (base, info); return TRUE; }
gboolean flatpak_builtin_build_init (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) var_deploy_files = NULL; g_autoptr(GFile) base = NULL; g_autoptr(GFile) files_dir = NULL; g_autoptr(GFile) usr_dir = NULL; g_autoptr(GFile) var_dir = NULL; g_autoptr(GFile) var_tmp_dir = NULL; g_autoptr(GFile) var_run_dir = NULL; g_autoptr(GFile) metadata_file = NULL; g_autoptr(GString) metadata_contents = NULL; g_autoptr(GError) my_error = NULL; const char *app_id; const char *directory; const char *sdk; const char *runtime; const char *branch = "master"; g_autofree char *runtime_ref = NULL; g_autofree char *var_ref = NULL; g_autofree char *sdk_ref = NULL; int i; context = g_option_context_new (_("DIRECTORY APPNAME SDK RUNTIME [BRANCH] - Initialize a directory for building")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 5) return usage_error (context, _("RUNTIME must be specified"), error); if (argc > 6) return usage_error (context, _("Too many arguments"), error); directory = argv[1]; app_id = argv[2]; sdk = argv[3]; runtime = argv[4]; if (argc >= 6) branch = argv[5]; if (!flatpak_is_valid_name (app_id, &my_error)) return flatpak_fail (error, _("'%s' is not a valid application name: %s"), app_id, my_error->message); if (!flatpak_is_valid_name (runtime, &my_error)) return flatpak_fail (error, _("'%s' is not a valid runtime name: %s"), runtime, my_error->message); if (!flatpak_is_valid_name (sdk, &my_error)) return flatpak_fail (error, _("'%s' is not a valid sdk name: %s"), sdk, my_error->message); if (!flatpak_is_valid_branch (branch, &my_error)) return flatpak_fail (error, _("'%s' is not a valid branch name: %s"), branch, my_error->message); runtime_ref = flatpak_build_untyped_ref (runtime, branch, opt_arch); sdk_ref = flatpak_build_untyped_ref (sdk, branch, opt_arch); base = g_file_new_for_commandline_arg (directory); if (!flatpak_mkdir_p (base, cancellable, error)) return FALSE; files_dir = g_file_get_child (base, "files"); if (opt_sdk_dir) usr_dir = g_file_get_child (base, opt_sdk_dir); else usr_dir = g_file_get_child (base, "usr"); var_dir = g_file_get_child (base, "var"); var_tmp_dir = g_file_get_child (var_dir, "tmp"); var_run_dir = g_file_get_child (var_dir, "run"); metadata_file = g_file_get_child (base, "metadata"); if (!opt_update && g_file_query_exists (files_dir, cancellable)) return flatpak_fail (error, _("Build directory %s already initialized"), directory); if (opt_writable_sdk) { g_autofree char *full_sdk_ref = g_strconcat ("runtime/", sdk_ref, NULL); g_autoptr(GFile) sdk_deploy_files = NULL; g_autoptr(FlatpakDeploy) sdk_deploy = NULL; sdk_deploy = flatpak_find_deploy_for_ref (full_sdk_ref, cancellable, error); if (sdk_deploy == NULL) return FALSE; if (!flatpak_rm_rf (usr_dir, NULL, &my_error)) { if (!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { g_propagate_error (error, g_steal_pointer (&my_error)); return FALSE; } g_clear_error (&my_error); } sdk_deploy_files = flatpak_deploy_get_files (sdk_deploy); if (!flatpak_cp_a (sdk_deploy_files, usr_dir, FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; if (opt_sdk_extensions && !copy_extensions (sdk_deploy, branch, opt_sdk_extensions, usr_dir, cancellable, error)) return FALSE; } if (opt_var) { var_ref = flatpak_build_runtime_ref (opt_var, branch, opt_arch); var_deploy_files = flatpak_find_files_dir_for_ref (var_ref, cancellable, error); if (var_deploy_files == NULL) return FALSE; } if (opt_update) return TRUE; if (!g_file_make_directory (files_dir, cancellable, error)) return FALSE; if (opt_base) { const char *base_branch; g_autofree char *base_ref = NULL; g_autoptr(GFile) base_deploy_files = NULL; g_autoptr(FlatpakDeploy) base_deploy = NULL; base_branch = opt_base_version ? opt_base_version : "master"; base_ref = flatpak_build_app_ref (opt_base, base_branch, opt_arch); base_deploy = flatpak_find_deploy_for_ref (base_ref, cancellable, error); if (base_deploy == NULL) return FALSE; base_deploy_files = flatpak_deploy_get_files (base_deploy); if (!flatpak_cp_a (base_deploy_files, files_dir, FLATPAK_CP_FLAGS_MERGE | FLATPAK_CP_FLAGS_NO_CHOWN, cancellable, error)) return FALSE; if (opt_base_extensions && !copy_extensions (base_deploy, base_branch, opt_base_extensions, files_dir, cancellable, error)) return FALSE; } if (var_deploy_files) { if (!flatpak_cp_a (var_deploy_files, var_dir, FLATPAK_CP_FLAGS_NONE, cancellable, error)) return FALSE; } else { if (!g_file_make_directory (var_dir, cancellable, error)) return FALSE; } if (!flatpak_mkdir_p (var_tmp_dir, cancellable, error)) return FALSE; if (!g_file_query_exists (var_run_dir, cancellable) && !g_file_make_symbolic_link (var_run_dir, "/run", cancellable, error)) return FALSE; metadata_contents = g_string_new ("[Application]\n"); g_string_append_printf (metadata_contents, "name=%s\n" "runtime=%s\n" "sdk=%s\n", app_id, runtime_ref, sdk_ref); if (opt_tags != NULL) { g_string_append (metadata_contents, "tags="); for (i = 0; opt_tags[i] != NULL; i++) { g_string_append (metadata_contents, opt_tags[i]); g_string_append_c (metadata_contents, ';'); } g_string_append_c (metadata_contents, '\n'); } if (!g_file_replace_contents (metadata_file, metadata_contents->str, metadata_contents->len, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, cancellable, error)) return FALSE; return TRUE; }
static void new_library_dialog_response_cb (GtkWidget *dialog, int response_id, gpointer user_data) { GthBrowser *browser = user_data; char *name; GthFileData *selected_parent; GFile *parent; GthFileSource *file_source; GFile *gio_parent; GError *error = NULL; GFile *gio_file; if (response_id != GTK_RESPONSE_OK) { gtk_widget_destroy (dialog); return; } name = gth_request_dialog_get_normalized_text (GTH_REQUEST_DIALOG (dialog)); if (_g_utf8_all_spaces (name)) { g_free (name); gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("No name specified")); return; } if (g_regex_match_simple ("/", name, 0, 0)) { char *message; message = g_strdup_printf (_("Invalid name. The following characters are not allowed: %s"), "/"); gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, message); g_free (message); g_free (name); return; } selected_parent = gth_browser_get_folder_popup_file_data (browser); if (selected_parent != NULL) { GthFileSource *file_source; GFileInfo *info; file_source = gth_main_get_file_source (selected_parent->file); info = gth_file_source_get_file_info (file_source, selected_parent->file, GFILE_BASIC_ATTRIBUTES); if (g_file_info_get_attribute_boolean (info, "gthumb::no-child")) parent = g_file_get_parent (selected_parent->file); else parent = g_file_dup (selected_parent->file); g_object_unref (info); g_object_unref (file_source); } else parent = g_file_new_for_uri ("catalog:///"); file_source = gth_main_get_file_source (parent); gio_parent = gth_file_source_to_gio_file (file_source, parent); gio_file = g_file_get_child_for_display_name (gio_parent, name, &error); if ((gio_file != NULL) && g_file_make_directory (gio_file, NULL, &error)) { GFile *file; GList *list; file = gth_catalog_file_from_gio_file (gio_file, NULL); list = g_list_prepend (NULL, file); gth_monitor_folder_changed (gth_main_get_default_monitor (), parent, list, GTH_MONITOR_EVENT_CREATED); g_list_free (list); g_object_unref (file); } if (error != NULL) { if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, _("Name already used")); else gth_request_dialog_set_info_text (GTH_REQUEST_DIALOG (dialog), GTK_MESSAGE_ERROR, error->message); g_clear_error (&error); } else gtk_widget_destroy (dialog); g_object_unref (gio_file); g_object_unref (gio_parent); g_object_unref (file_source); g_free (name); }
/* initialise the gtodo lib */ gboolean gtodo_client_check_file(GTodoClient *cl, GError **error) { GError *tmp_error = NULL; GFile *base_path = NULL; GFileInfo *file_info = NULL; GError *file_error = NULL; /* check if the error is good or wrong. */ g_return_val_if_fail(error == NULL || *error == NULL,FALSE); base_path = g_file_get_parent (cl->xml_file); /* this is dirty.. needs a fix hard * * The client should do this.. so this code should be considert * deprecated. I left it here thinking it wouldnt hurt anybody. */ if(base_path != NULL) { g_file_make_directory (base_path, NULL, NULL); g_object_unref (G_OBJECT(base_path)); } /* Get permission of the file */ /* This also tell's us if it does exists */ file_info = g_file_query_info (cl->xml_file, "access::can-read,access::can-write", G_FILE_QUERY_INFO_NONE, NULL, &file_error); /* If I got the info to check it out */ if(file_error == NULL) { gchar *read_buf = NULL; gboolean read; gboolean write; gsize size; read = g_file_info_get_attribute_boolean (file_info, "access::can-read"); write = g_file_info_get_attribute_boolean (file_info, "access::can-write"); /* If I am not allowed to read the file */ if(!read) { /* save some more info here.. check for some logicol errors and print it. */ g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_NO_PERMISSION, _("No permission to read the file.")); g_propagate_error(error, tmp_error); return FALSE; } cl->read_only = !write; DEBUG_PRINT("trying to read file: %s", g_file_get_parse_name (cl->xml_file)); if (!g_file_load_contents (cl->xml_file, NULL, (char **)&read_buf, &size, NULL, &file_error)) { if (file_error) { g_propagate_error(error, file_error); } else { g_set_error(&tmp_error, LIBGTODO_ERROR, LIBGTODO_ERROR_FAILED, _("Failed to read file")); g_propagate_error(error, tmp_error); } return FALSE; } cl->gtodo_doc = xmlParseMemory(read_buf, size); if(cl->gtodo_doc == NULL) { g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_XML,_("Failed to parse XML structure")); g_propagate_error(error, tmp_error); DEBUG_PRINT("%s", "failed to read the file"); g_free (read_buf); return FALSE; } /* get root element.. this "root" is used in the while program */ cl->root = xmlDocGetRootElement(cl->gtodo_doc); if(cl->root == NULL) { g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_XML,_("Failed to parse XML structure")); g_propagate_error(error, tmp_error); DEBUG_PRINT("%s", "failed to get root node."); g_free (read_buf); return FALSE; } /* check if the name of the root file is ok.. just to make sure :) */ if(!xmlStrEqual(cl->root->name, (const xmlChar *)"gtodo")) { g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_XML,_("File is not a valid gtodo file")); g_propagate_error(error, tmp_error); g_free (read_buf); return FALSE; } g_free (read_buf); } else if ((file_error->domain == G_IO_ERROR) && (file_error->code == G_IO_ERROR_NOT_FOUND)) { xmlNodePtr newn; DEBUG_PRINT ("Trying to create new file\n"); cl->gtodo_doc = xmlNewDoc((xmlChar *)"1.0"); cl->root = xmlNewDocNode(cl->gtodo_doc, NULL, (xmlChar *)"gtodo", NULL); xmlDocSetRootElement(cl->gtodo_doc, cl->root); newn = xmlNewTextChild(cl->root, NULL, (xmlChar *)"category", NULL); xmlNewProp(newn, (xmlChar *)"title", (xmlChar *)_("Personal")); newn = xmlNewTextChild(cl->root, NULL, (xmlChar *)"category", NULL); xmlNewProp(newn, (xmlChar *)"title", (xmlChar *)_("Business")); newn = xmlNewTextChild(cl->root, NULL, (xmlChar *)"category", NULL); xmlNewProp(newn, (xmlChar *)"title", (xmlChar *)_("Unfiled")); if(gtodo_client_save_xml(cl, &tmp_error)) { g_propagate_error(error, tmp_error); return FALSE; } cl->read_only = FALSE; g_error_free (file_error); } else{ /* save some more info here.. check for some logicol errors and print it. */ g_propagate_error(error, file_error); return FALSE; } return TRUE; }
static void deja_dup_recursive_move_real_handle_dir (DejaDupRecursiveOp* base) { DejaDupRecursiveMove * self; gboolean _tmp0_ = FALSE; GFileType _tmp1_; gboolean _tmp3_; GFileType _tmp12_; GError * _inner_error_ = NULL; self = (DejaDupRecursiveMove*) base; _tmp1_ = ((DejaDupRecursiveOp*) self)->dst_type; if (_tmp1_ != G_FILE_TYPE_UNKNOWN) { GFileType _tmp2_; _tmp2_ = ((DejaDupRecursiveOp*) self)->dst_type; _tmp0_ = _tmp2_ != G_FILE_TYPE_DIRECTORY; } else { _tmp0_ = FALSE; } _tmp3_ = _tmp0_; if (_tmp3_) { { GFile* _tmp4_; GFile* _tmp5_; _tmp4_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp5_ = _tmp4_; g_file_delete (_tmp5_, NULL, &_inner_error_); if (_inner_error_ != NULL) { goto __catch35_g_error; } } goto __finally35; __catch35_g_error: { GError* e = NULL; GFile* _tmp6_; GFile* _tmp7_; GFile* _tmp8_; GFile* _tmp9_; GError* _tmp10_; const gchar* _tmp11_; e = _inner_error_; _inner_error_ = NULL; _tmp6_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp7_ = _tmp6_; _tmp8_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp9_ = _tmp8_; _tmp10_ = e; _tmp11_ = _tmp10_->message; g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp7_, _tmp9_, _tmp11_); _g_error_free0 (e); return; } __finally35: 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; } ((DejaDupRecursiveOp*) self)->dst_type = G_FILE_TYPE_UNKNOWN; } _tmp12_ = ((DejaDupRecursiveOp*) self)->dst_type; if (_tmp12_ == G_FILE_TYPE_UNKNOWN) { { GFile* _tmp13_; GFile* _tmp14_; _tmp13_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp14_ = _tmp13_; g_file_make_directory (_tmp14_, NULL, &_inner_error_); if (_inner_error_ != NULL) { goto __catch36_g_error; } } goto __finally36; __catch36_g_error: { GError* e = NULL; GFile* _tmp15_; GFile* _tmp16_; GFile* _tmp17_; GFile* _tmp18_; GError* _tmp19_; const gchar* _tmp20_; e = _inner_error_; _inner_error_ = NULL; _tmp15_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp16_ = _tmp15_; _tmp17_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp18_ = _tmp17_; _tmp19_ = e; _tmp20_ = _tmp19_->message; g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp16_, _tmp18_, _tmp20_); _g_error_free0 (e); return; } __finally36: 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; } } }