static void base_rename (GthFileSource *file_source, GFile *file, GFile *new_file, ReadyCallback callback, gpointer data) { GFile *source; GFile *destination; GError *error = NULL; source = gth_file_source_to_gio_file (file_source, file); destination = gth_file_source_to_gio_file (file_source, new_file); if (g_file_move (source, destination, 0, NULL, NULL, NULL, &error)) { GthMonitor *monitor; monitor = gth_main_get_default_monitor (); gth_monitor_file_renamed (monitor, file, new_file); } object_ready_with_error (file_source, callback, data, error); g_object_unref (destination); g_object_unref (source); }
gboolean vfs_backend_move_file (const gchar *cURI, const gchar *cDirectoryURI) { g_return_val_if_fail (cURI != NULL, FALSE); cd_message (" %s -> %s", cURI, cDirectoryURI); GFile *pFile = (*cURI == '/' ? g_file_new_for_path (cURI) : g_file_new_for_uri (cURI)); gchar *cFileName = g_file_get_basename (pFile); gchar *cNewFileURI = g_strconcat (cDirectoryURI, "/", cFileName, NULL); // un peu moyen mais bon... GFile *pDestinationFile = (*cNewFileURI == '/' ? g_file_new_for_path (cNewFileURI) : g_file_new_for_uri (cNewFileURI)); g_free (cNewFileURI); g_free (cFileName); GError *erreur = NULL; gboolean bSuccess = g_file_move (pFile, pDestinationFile, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, // GFileProgressCallback NULL, // data &erreur); if (erreur != NULL) { cd_warning ("Attention : %s", erreur->message); g_error_free (erreur); } g_object_unref (pFile); g_object_unref (pDestinationFile); return bSuccess; }
/* Finish up the user's Release command by choosing a location to store the project. This is a callback and the GDK lock is held when entering this function. */ void i7_story_save_compiler_output(I7Story *story, const gchar *dialog_title) { I7_STORY_USE_PRIVATE(story, priv); GFile *file = NULL; if(priv->copy_blorb_dest_file == NULL) { /* ask the user for a release file name if cBlorb didn't provide one */ /* Create a file chooser */ GtkFileFilter *filter = gtk_file_filter_new(); if(i7_story_get_story_format(story) == I7_STORY_FORMAT_GLULX) { gtk_file_filter_set_name(filter, _("Glulx games (.ulx,.gblorb)")); gtk_file_filter_add_pattern(filter, "*.ulx"); gtk_file_filter_add_pattern(filter, "*.gblorb"); } else { gtk_file_filter_set_name(filter, _("Z-code games (.z?,.zblorb)")); gtk_file_filter_add_pattern(filter, "*.z?"); gtk_file_filter_add_pattern(filter, "*.zblorb"); } GtkWidget *dialog = gtk_file_chooser_dialog_new(dialog_title, GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); char *curfilename = g_file_get_basename(priv->compiler_output_file); gchar *title = i7_document_get_display_name(I7_DOCUMENT(story)); char *extension = strrchr(curfilename, '.'); /* not allocated */ char *suggestname; if(title != NULL) { *(strrchr(title, '.')) = '\0'; suggestname = g_strconcat(title, extension, NULL); g_free(title); } else { suggestname = g_strconcat("Untitled", extension, NULL); } g_free(curfilename); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggestname); g_free(suggestname); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter); if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog)); gtk_widget_destroy(dialog); } else { file = g_object_ref(priv->copy_blorb_dest_file); } if(file) { /* Move the finished file to the release location */ GError *err = NULL; if(!g_file_move(priv->compiler_output_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &err)) { IO_ERROR_DIALOG(GTK_WINDOW(story), file, err, _("copying compiler output")); } g_object_unref(file); } }
static char * rb_find_user_file (const char *dir, const char *name, GError **error) { GError *temp_err = NULL; char *srcpath; char *destpath; GFile *src; GFile *dest; char *use_path; /* if the file exists in the target dir, return the path */ destpath = g_build_filename (dir, name, NULL); dest = g_file_new_for_path (destpath); if (g_file_query_exists (dest, NULL) == TRUE) { g_object_unref (dest); rb_debug ("found user dir path for '%s': %s", name, destpath); return destpath; } /* doesn't exist in the target dir, so try to move it from the .gnome2 dir */ srcpath = g_build_filename (rb_dot_dir (), name, NULL); src = g_file_new_for_path (srcpath); if (g_file_query_exists (src, NULL)) { g_file_move (src, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &temp_err); if (temp_err != NULL) { rb_debug ("failed to move user file '%s' from .gnome2 dir, returning .gnome2 path %s: %s", name, srcpath, temp_err->message); use_path = g_file_get_path (src); g_set_error (error, temp_err->domain, temp_err->code, _("Unable to move %s to %s: %s"), srcpath, destpath, temp_err->message); g_error_free (temp_err); } else { rb_debug ("moved user file '%s' from .gnome2 dir, returning user dir path %s", name, destpath); use_path = g_file_get_path (dest); } } else { rb_debug ("no existing file for '%s', returning user dir path %s", name, destpath); use_path = g_file_get_path (dest); } g_free (srcpath); g_free (destpath); g_object_unref (src); g_object_unref (dest); return use_path; }
gboolean copyThemesDir(const gchar *path) { const gchar *file; gchar *fullPath, *childPath, *oldFilename, *newFilename; GDir *dir; GFile *oldFile, *newFile; fullPath = g_build_filename(g_get_home_dir(), ".themes", OBS_NAME, path, NULL); dir = g_dir_open(fullPath, 0, NULL); file = g_dir_read_name(dir); while (file != NULL){ if (g_file_test(file, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { childPath = g_build_filename(fullPath, file, NULL); if (g_mkdir_with_parents(childPath, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) { g_free(fullPath); g_free(childPath); g_dir_close(dir); return FALSE; } childPath = g_build_filename(path, file, NULL); if (!copyThemesDir(childPath)) { g_free(fullPath); g_free(childPath); g_dir_close(dir); return FALSE; } g_free(childPath); } else { oldFilename = g_build_filename(fullPath, file, NULL); oldFile = g_file_new_for_path(oldFilename); newFilename = g_build_filename(g_get_user_data_dir(), OBS_NAME, "themes", path, file, NULL); newFile = g_file_new_for_path(newFilename); if (!g_file_move(oldFile, newFile, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL)) { g_free(fullPath); g_dir_close(dir); g_free(oldFilename); g_free(newFilename); g_object_unref(oldFile); g_object_unref(newFile); return FALSE; } g_free(oldFilename); g_free(newFilename); g_object_unref(oldFile); g_object_unref(newFile); } file = g_dir_read_name(dir); } g_free(fullPath); g_dir_close(dir); return TRUE; }
static void change_filename(GFile* src, const char* dst_name, GtkWidget* parent_window) { char* src_name; GFile* parent; GFile* dst; gboolean res; GError* error = NULL; if (dst_name == NULL) return; src_name = g_file_get_basename(src); if (strcmp(src_name, dst_name) != 0) { parent = g_file_get_parent(src); dst = g_file_get_child(parent, dst_name); res = g_file_move(src, dst, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, &error); if (!res) { GtkWidget* dialog; char* display_name; gboolean do_free = FALSE;; if (g_utf8_validate(src_name, -1, NULL)) { display_name = src_name; } else { display_name = get_display_name(src_name); do_free = TRUE; } dialog = gtk_message_dialog_new_with_markup(GTK_WINDOW(parent_window), GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("<span size=\"larger\" weight=\"bold\">There was an error renaming \"%s\" to \"%s\"</span>"), display_name, dst_name); gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), "%s", error->message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); g_error_free(error); if (do_free) g_free(display_name); } g_object_unref(G_OBJECT(dst)); } g_free(src_name); }
/* 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 strip_components_into (GFile *dest, GFile *src, int level, GError **error) { g_autoptr(GFileEnumerator) dir_enum = NULL; g_autoptr(GFileInfo) child_info = NULL; GError *temp_error = NULL; dir_enum = g_file_enumerate_children (src, "standard::name,standard::type", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, error); if (!dir_enum) return FALSE; while ((child_info = g_file_enumerator_next_file (dir_enum, NULL, &temp_error))) { g_autoptr(GFile) child = NULL; g_autoptr(GFile) dest_child = NULL; child = g_file_enumerator_get_child (dir_enum, child_info); if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY && level > 0) { if (!strip_components_into (dest, child, level - 1, error)) return FALSE; g_clear_object (&child_info); continue; } dest_child = g_file_get_child (dest, g_file_info_get_name (child_info)); if (!g_file_move (child, dest_child, G_FILE_COPY_NONE, NULL, NULL, NULL, error)) return FALSE; g_clear_object (&child_info); } if (temp_error != NULL) { g_propagate_error (error, temp_error); return FALSE; } return g_file_delete (src, NULL, error); }
static void strip_semicolons_from_keymap(const char *path) { char pathtmp[PATH_MAX] = { 0 }; FILE *fin = g_fopen(path, "rb"); FILE *fout; int i; int c = '\0'; if(!fin) return; snprintf(pathtmp, sizeof(pathtmp), "%s_tmp", path); fout = g_fopen(pathtmp, "wb"); if(!fout) { fclose(fin); return; } // First ignoring the first three lines for(i = 0; i < 3; i++) { while(c != '\n' && c != '\r' && c != EOF) c = fgetc(fin); while(c == '\n' || c == '\r') c = fgetc(fin); } // Then ignore the first two characters of each line, copying the rest out while(c != EOF) { fseek(fin, 2, SEEK_CUR); do { c = fgetc(fin); if(c != EOF) fputc(c, fout); } while(c != '\n' && c != '\r' && c != EOF); } fclose(fin); fclose(fout); GFile *gpath = g_file_new_for_path(path); GFile *gpathtmp = g_file_new_for_path(pathtmp); g_file_delete(gpath, NULL, NULL); g_file_move(gpathtmp, gpath, 0, NULL, NULL, NULL, NULL); g_object_unref(gpath); g_object_unref(gpathtmp); }
static void migrate_config_file (const gchar *old_filename, const gchar* new_filename) { GFile *old_file, *new_file; GError *error = NULL; if (!g_file_test (old_filename, G_FILE_TEST_IS_REGULAR)) return; old_file = g_file_new_for_path (old_filename); new_file = g_file_new_for_path (new_filename); if (!g_file_move (old_file, new_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) { g_warning ("Could not migrate config file %s: %s\n", old_filename, error->message); g_error_free (error); } g_object_unref (new_file); g_object_unref (old_file); }
static void migrate_from_14plus (const gchar *oldBaseDir, nodePtr node) { GFile *sourceDbFile, *targetDbFile; gchar *newConfigDir, *newCacheDir, *newDataDir, *oldCacheDir, *filename; g_print("Performing %s -> XDG cache migration...\n", oldBaseDir); /* 1.) Close already loaded DB */ db_deinit (); /* 2.) Copy all files */ newCacheDir = g_build_filename (g_get_user_cache_dir(), "liferea", NULL); newConfigDir = g_build_filename (g_get_user_config_dir(), "liferea", NULL); newDataDir = g_build_filename (g_get_user_data_dir(), "liferea", NULL); oldCacheDir = g_build_filename (oldBaseDir, "cache", NULL); migrate_copy_dir (oldBaseDir, newConfigDir, ""); migrate_copy_dir (oldCacheDir, newCacheDir, G_DIR_SEPARATOR_S "favicons"); migrate_copy_dir (oldCacheDir, newCacheDir, G_DIR_SEPARATOR_S "plugins"); /* 3.) Move DB to from new config dir to cache dir instead (this is caused by the batch copy in step 2.) */ sourceDbFile = g_file_new_for_path (g_build_filename (newConfigDir, "liferea.db", NULL)); targetDbFile = g_file_new_for_path (g_build_filename (newDataDir, "liferea.db", NULL)); g_file_move (sourceDbFile, targetDbFile, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); g_object_unref (sourceDbFile); g_object_unref (targetDbFile); /* 3.) And reopen the copied DB */ db_init (); /* 4.) Migrate file feed list into DB */ filename = common_create_config_filename ("feedlist.opml"); if (!import_OPML_feedlist (filename, node, FALSE, TRUE)) g_error ("Fatal: Feed list migration failed!"); g_free (filename); g_free (newConfigDir); g_free (newCacheDir); g_free (oldCacheDir); }
static gboolean git_mirror_repo (const char *repo_location, gboolean update, const char *ref, BuilderContext *context, GError **error) { g_autoptr(GFile) mirror_dir = NULL; g_autofree char *current_commit = NULL; mirror_dir = git_get_mirror_dir (repo_location, context); if (!g_file_query_exists (mirror_dir, NULL)) { g_autofree char *filename = g_file_get_basename (mirror_dir); g_autoptr(GFile) parent = g_file_get_parent (mirror_dir); g_autofree char *filename_tmp = g_strconcat (filename, ".clone_tmp", NULL); g_autoptr(GFile) mirror_dir_tmp = g_file_get_child (parent, filename_tmp); g_print ("Cloning git repo %s\n", repo_location); if (!git (parent, NULL, error, "clone", "--mirror", repo_location, filename_tmp, NULL) || !g_file_move (mirror_dir_tmp, mirror_dir, 0, NULL, NULL, NULL, error)) return FALSE; } else if (update) { g_print ("Fetching git repo %s\n", repo_location); if (!git (mirror_dir, NULL, error, "fetch", "-p", NULL)) return FALSE; } current_commit = git_get_current_commit (mirror_dir, ref, context, error); if (current_commit == NULL) return FALSE; if (!git_mirror_submodules (repo_location, update, mirror_dir, current_commit, context, error)) return FALSE; return TRUE; }
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(); }
void renameFile(FmFileInfo *file, QWidget *parent) { FmPath* path = fm_file_info_get_path(file); FilenameDialog dlg(parent); dlg.setWindowTitle(QObject::tr("Rename File")); dlg.setLabelText(QObject::tr("Please enter a new name:")); // FIXME: what's the best way to handle non-UTF8 filename encoding here? QString old_name = QString::fromLocal8Bit(fm_path_get_basename(path)); dlg.setTextValue(old_name); if(fm_file_info_is_dir(file)) // select filename extension for directories dlg.setSelectExtension(true); if(dlg.exec() != QDialog::Accepted) return; QString new_name = dlg.textValue(); if(new_name == old_name) return; GFile* gf = fm_path_to_gfile(path); GFile* parent_gf = g_file_get_parent(gf); GFile* dest = g_file_get_child(G_FILE(parent_gf), new_name.toLocal8Bit().data()); g_object_unref(parent_gf); GError* err = NULL; if(!g_file_move(gf, dest, GFileCopyFlags(G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NO_FALLBACK_FOR_MOVE | G_FILE_COPY_NOFOLLOW_SYMLINKS), NULL, /* make this cancellable later. */ NULL, NULL, &err)) { QMessageBox::critical(parent, QObject::tr("Error"), err->message); g_error_free(err); } g_object_unref(dest); g_object_unref(gf); }
void migrateConfigToXdgDir(void) { gchar *oldFilename, *newFilename, *xdgPath; GFile *oldFile, *newFile; xdgPath = g_build_filename(g_get_user_config_dir(), OBS_NAME, NULL); if (g_file_test(xdgPath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { g_free(xdgPath); return; } oldFilename = g_build_filename(g_get_home_dir(), ".obshutdown.rc", NULL); if (!g_file_test(oldFilename, G_FILE_TEST_EXISTS)) { g_free(xdgPath); g_free(oldFilename); return; } if (g_mkdir_with_parents(xdgPath, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) { printMessage(MSG_WARN,"Failed to create %s\n", xdgPath); g_free(xdgPath); g_free(oldFilename); return; } newFilename = g_build_filename(xdgPath, "obshutdown.rc", NULL); oldFile = g_file_new_for_path(oldFilename); newFile = g_file_new_for_path(newFilename); if (!g_file_move(oldFile, newFile, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL)) { printMessage(MSG_WARN,"Failed to migrate configuration file\n"); } g_free(xdgPath); g_free(oldFilename); g_free(newFilename); g_object_unref(oldFile); g_object_unref(newFile); }
static void migrate_options_directory (void) { char *old_directory_path; GFile *old_directory; GFile *new_directory; old_directory_path = get_home_relative_path (".gnome2/file-roller/options"); old_directory = g_file_new_for_path (old_directory_path); new_directory = _g_file_new_user_config_subdir (ADD_FOLDER_OPTIONS_DIR, FALSE); if (g_file_query_exists (old_directory, NULL) && ! g_file_query_exists (new_directory, NULL)) { GFile *parent; parent = g_file_get_parent (new_directory); if (_g_file_make_directory_tree (parent, 0700, NULL)) g_file_move (old_directory, new_directory, 0, NULL, NULL, NULL, NULL); g_object_unref (parent); } g_object_unref (new_directory); g_object_unref (old_directory); g_free (old_directory_path); }
static void migrate_config_to_xdg_dir (void) { gchar *xdg_dir, *old_dir, *xdg_filename, *old_filename; int i; GFile *xdg_file, *old_file; static const gchar* filenames[] = { "geometry.ini", "irc-networks.xml", "chatrooms.xml", "contact-groups.xml", "status-presets.xml", "accels.txt", NULL }; xdg_dir = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); if (g_file_test (xdg_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { /* xdg config dir already exists */ g_free (xdg_dir); return; } old_dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME, NULL); if (!g_file_test (old_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { /* old config dir didn't exist */ g_free (xdg_dir); g_free (old_dir); return; } if (g_mkdir_with_parents (xdg_dir, (S_IRUSR | S_IWUSR | S_IXUSR)) == -1) { DEBUG ("Failed to create configuration directory; aborting migration"); g_free (xdg_dir); g_free (old_dir); return; } for (i = 0; filenames[i]; i++) { old_filename = g_build_filename (old_dir, filenames[i], NULL); if (!g_file_test (old_filename, G_FILE_TEST_EXISTS)) { g_free (old_filename); continue; } xdg_filename = g_build_filename (xdg_dir, filenames[i], NULL); old_file = g_file_new_for_path (old_filename); xdg_file = g_file_new_for_path (xdg_filename); if (!g_file_move (old_file, xdg_file, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL)) DEBUG ("Failed to migrate %s", filenames[i]); g_free (old_filename); g_free (xdg_filename); g_object_unref (old_file); g_object_unref (xdg_file); } g_free (xdg_dir); g_free (old_dir); }
static void deja_dup_recursive_move_real_handle_file (DejaDupRecursiveOp* base) { DejaDupRecursiveMove * self; GFileType _tmp0_; GError * _inner_error_ = NULL; self = (DejaDupRecursiveMove*) base; _tmp0_ = ((DejaDupRecursiveOp*) self)->dst_type; if (_tmp0_ == G_FILE_TYPE_DIRECTORY) { { GFile* _tmp1_; GFile* _tmp2_; _tmp1_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp2_ = _tmp1_; g_file_delete (_tmp2_, NULL, &_inner_error_); if (_inner_error_ != NULL) { goto __catch32_g_error; } } goto __finally32; __catch32_g_error: { GError* e = NULL; GFile* _tmp3_; GFile* _tmp4_; GFile* _tmp5_; GFile* _tmp6_; GError* _tmp7_; const gchar* _tmp8_; e = _inner_error_; _inner_error_ = NULL; _tmp3_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp4_ = _tmp3_; _tmp5_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp6_ = _tmp5_; _tmp7_ = e; _tmp8_ = _tmp7_->message; g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp4_, _tmp6_, _tmp8_); _g_error_free0 (e); return; } __finally32: 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; } } { GFile* _tmp9_; GFile* _tmp10_; GFile* _tmp11_; GFile* _tmp12_; _tmp9_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp10_ = _tmp9_; _tmp11_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp12_ = _tmp11_; g_file_move (_tmp10_, _tmp12_, (G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NOFOLLOW_SYMLINKS) | G_FILE_COPY_OVERWRITE, NULL, _deja_dup_recursive_move_progress_callback_gfile_progress_callback, self, &_inner_error_); if (_inner_error_ != NULL) { if (g_error_matches (_inner_error_, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED)) { goto __catch33_g_io_error_permission_denied; } goto __catch33_g_error; } } goto __finally33; __catch33_g_io_error_permission_denied: { GError* e = NULL; e = _inner_error_; _inner_error_ = NULL; { GFile* _tmp13_; GFile* _tmp14_; GFile* _tmp15_; GFile* _tmp16_; _tmp13_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp14_ = _tmp13_; _tmp15_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp16_ = _tmp15_; g_file_copy (_tmp14_, _tmp16_, (G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NOFOLLOW_SYMLINKS) | G_FILE_COPY_OVERWRITE, NULL, _deja_dup_recursive_move_progress_callback_gfile_progress_callback, self, &_inner_error_); if (_inner_error_ != NULL) { goto __catch34_g_error; } } goto __finally34; __catch34_g_error: { GError* e = NULL; GFile* _tmp17_; GFile* _tmp18_; GFile* _tmp19_; GFile* _tmp20_; GError* _tmp21_; const gchar* _tmp22_; e = _inner_error_; _inner_error_ = NULL; _tmp17_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp18_ = _tmp17_; _tmp19_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp20_ = _tmp19_; _tmp21_ = e; _tmp22_ = _tmp21_->message; g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp18_, _tmp20_, _tmp22_); _g_error_free0 (e); } __finally34: if (_inner_error_ != NULL) { _g_error_free0 (e); _g_error_free0 (e); g_critical ("file %s: line %d: unexpected 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; } _g_error_free0 (e); } goto __finally33; __catch33_g_error: { GError* e = NULL; GFile* _tmp23_; GFile* _tmp24_; GFile* _tmp25_; GFile* _tmp26_; GError* _tmp27_; const gchar* _tmp28_; e = _inner_error_; _inner_error_ = NULL; _tmp23_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self); _tmp24_ = _tmp23_; _tmp25_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self); _tmp26_ = _tmp25_; _tmp27_ = e; _tmp28_ = _tmp27_->message; g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp24_, _tmp26_, _tmp28_); _g_error_free0 (e); } __finally33: 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; } }
static void xdg_cache_cache_copy_or_move_file (TumblerCache *cache, TumblerThumbnailFlavor *flavor, gboolean do_copy, const gchar *from_uri, const gchar *to_uri, guint64 mtime) { GFile *from_file; GFile *temp_file; gchar *temp_path; gchar *dest_path; gchar *from_path; gboolean result; GFile *dest_file; from_file = xdg_cache_cache_get_file (from_uri, flavor); temp_file = xdg_cache_cache_get_temp_file (to_uri, flavor); if (do_copy) { result = g_file_copy (from_file, temp_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); } else { result = g_file_move (from_file, temp_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); } if (result) { temp_path = g_file_get_path (temp_file); if (xdg_cache_cache_write_thumbnail_info (temp_path, to_uri, mtime, NULL, NULL)) { dest_file = xdg_cache_cache_get_file (to_uri, flavor); dest_path = g_file_get_path (dest_file); if (g_rename (temp_path, dest_path) != 0) g_unlink (temp_path); g_free (dest_path); g_object_unref (dest_file); } else { g_unlink (temp_path); } g_free (temp_path); } else if (!do_copy) { /* if the move failed, drop the old cache file */ from_path = g_file_get_path (from_file); g_unlink (from_path); g_free (from_path); } g_object_unref (temp_file); g_object_unref (from_file); }
/* This only supports migrating from v0.5's config file */ gboolean migrate_config(gmpv_handle *ctx) { gchar *config_file = get_config_file_path(); gboolean result = FALSE; if(g_file_test(config_file, G_FILE_TEST_EXISTS)) { const gchar *key_list[] = { "csd-enable", "dark-theme-enable", "mpv-input-config-enable", "mpv-config-enable", "mpv-input-config-file", "mpv-config-file", "mpv-options", NULL }; GSettingsBackend *backend; GSettings *keyfile_settings; GSettings *default_settings; const gchar **iter; backend = g_keyfile_settings_backend_new ( config_file, "/org/gnome-mpv/gnome-mpv/", "main" ); keyfile_settings = g_settings_new_with_backend( CONFIG_ROOT, backend ); default_settings = g_settings_new(CONFIG_ROOT); iter = key_list; while(*iter) { GVariant *value; value = g_settings_get_value(keyfile_settings, *iter); g_settings_set_value(default_settings, *iter, value); iter++; g_variant_unref(value); } g_object_unref(backend); g_object_unref(keyfile_settings); g_object_unref(default_settings); /* Rename the old config file */ gchar *backup_config_file = g_strconcat( config_file, ".bak", NULL ); GFile *src = g_file_new_for_path(config_file); GFile *dest = g_file_new_for_path(backup_config_file); result = g_file_move( src, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, NULL ); g_free(backup_config_file); g_object_unref(src); g_object_unref(dest); } g_free(config_file); return result; }
gboolean libre_impuesto_file_switch_temp_file (GFile *file_dest, GFile *file_temp) { char *file_dest_path, *file_temp_path; char *backup_path; gboolean dest_exists; gboolean retval = TRUE; GFile *backup_file; file_dest_path = g_file_get_path (file_dest); file_temp_path = g_file_get_path (file_temp); dest_exists = g_file_test (file_dest_path, G_FILE_TEST_EXISTS); backup_path = g_strconcat (file_dest_path, ".old", NULL); backup_file = g_file_new_for_path (backup_path); if (dest_exists) { if (g_file_move (file_dest, backup_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL) == FALSE) { g_warning ("Failed to backup %s to %s", file_dest_path, backup_path); retval = FALSE; goto failed; } } if (g_file_move (file_temp, file_dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL) == FALSE) { g_warning ("Failed to replace %s with %s", file_temp_path, file_dest_path); if (g_file_move (backup_file, file_dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL) == FALSE) { g_warning ("Failed to restore %s from %s", file_dest_path, file_temp_path); } retval = FALSE; goto failed; } if (dest_exists) { if (g_file_delete (backup_file, NULL, NULL) == FALSE) { g_warning ("Failed to delete old file %s", backup_path); } } failed: g_free (file_dest_path); g_free (file_temp_path); g_free (backup_path); g_object_unref (backup_file); return retval; }
static gboolean save_playlist (RBGenericPlayerPlaylistSource *source) { TotemPlParser *parser; TotemPlParserType playlist_type; RhythmDBQueryModel *query_model; char *name; char *temp_uri; GError *error = NULL; RBGenericPlayerPlaylistSourcePrivate *priv = GET_PRIVATE (source); priv->save_playlist_id = 0; playlist_type = rb_generic_player_source_get_playlist_format (priv->player_source); g_object_get (source, "name", &name, "base-query-model", &query_model, NULL); /* if we don't already have a name for this playlist, make one now */ if (priv->playlist_path == NULL) { char *playlist_dir; char *mount_uri; char *filename; const char *ext; GFile *dir; GFile *playlist; ext = playlist_format_extension (playlist_type); if (name == NULL || name[0] == '\0') { /* now what? */ filename = g_strdup_printf ("unnamed%s", ext); } else { filename = g_strdup_printf ("%s%s", name, ext); } playlist_dir = rb_generic_player_source_get_playlist_path (priv->player_source); mount_uri = rb_generic_player_source_get_mount_path (priv->player_source); dir = g_file_new_for_uri (mount_uri); if (playlist_dir != NULL) { GFile *pdir; pdir = g_file_resolve_relative_path (dir, playlist_dir); g_object_unref (dir); dir = pdir; } playlist = g_file_resolve_relative_path (dir, filename); priv->playlist_path = g_file_get_path (playlist); g_free (mount_uri); g_free (playlist_dir); g_object_unref (dir); } temp_uri = g_strdup_printf ("%s%06X", priv->playlist_path, g_random_int_range (0, 0xFFFFFF)); parser = totem_pl_parser_new (); if (rb_debug_matches ("totem_pl_parser_write_with_title", "totem-pl-parser.c")) { g_object_set (parser, "debug", TRUE, NULL); } if (totem_pl_parser_write_with_title (parser, GTK_TREE_MODEL (query_model), (TotemPlParserIterFunc) save_playlist_entry, temp_uri, name, playlist_type, source, &error) == FALSE) { /* XXX report this more usefully */ g_warning ("Playlist save failed: %s", error->message); } else { GFile *dest; GFile *src; dest = g_file_new_for_path (priv->playlist_path); src = g_file_new_for_path (temp_uri); g_file_move (src, dest, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NO_FALLBACK_FOR_MOVE, NULL, NULL, NULL, &error); if (error != NULL) { /* XXX report this more usefully */ g_warning ("Replacing playlist failed: %s", error->message); } g_object_unref (dest); g_object_unref (src); } g_clear_error (&error); g_free (name); g_free (temp_uri); g_object_unref (query_model); return FALSE; }
static void on_file_downloaded (SummerWebBackend *web, gchar *saved_path, gchar *saved_data, GError *error, gpointer data) { g_return_if_fail (SUMMER_IS_DOWNLOAD_YOUTUBE (data)); g_return_if_fail (saved_data == NULL); SummerDownload *self = SUMMER_DOWNLOAD (data); SummerDownloadYoutubePrivate *priv = SUMMER_DOWNLOAD_YOUTUBE (self)->priv; if (g_error_matches (error, SUMMER_WEB_BACKEND_ERROR, SUMMER_WEB_BACKEND_ERROR_REMOTE)) { priv->quality--; if (priv->quality < 0) { GError *error = g_error_new ( SUMMER_DOWNLOAD_ERROR, SUMMER_DOWNLOAD_ERROR_INPUT, "Download Failed"); g_signal_emit_by_name (self, "download-error", error); g_object_unref (self); g_object_unref (web); return; } SummerItemData *item; g_object_get (self, "item", &item, NULL); summer_download_set_filename (self, g_strdup_printf ("%s.%s", summer_item_data_get_title (item), quality[priv->quality][1])); g_object_unref (item); GError *e = NULL; g_object_set (web, "url", create_youtube_url (SUMMER_DOWNLOAD_YOUTUBE (self)), NULL); summer_web_backend_fetch (web, &e); if (e != NULL) { g_signal_emit_by_name (self, "download-error", e); g_object_unref (self); } return; } else if (error != NULL) { g_signal_emit_by_name (self, "download-error", error); g_object_unref (self); return; } GFile *src = g_file_new_for_path (saved_path); gchar *destpath = summer_download_get_save_path (self); GFile *dest = g_file_new_for_path (destpath); g_free (destpath); destpath = NULL; GError *e = NULL; gchar *save_dir = summer_download_get_save_dir (self); GFile *destdir = g_file_new_for_path (save_dir); g_free (save_dir); save_dir = NULL; if (!g_file_query_exists (destdir, NULL)) { if (!g_file_make_directory_with_parents (destdir, NULL, &e)) { GError *e2 = g_error_new ( SUMMER_DOWNLOAD_ERROR, SUMMER_DOWNLOAD_ERROR_OUTPUT, "Couldn't create output directory: %s", e->message); g_signal_emit_by_name (self, "download-error", e2); g_object_unref (self); g_clear_error (&e); g_object_unref (src); g_object_unref (dest); g_object_unref (destdir); return; } } g_object_unref (destdir); if (!g_file_move (src, dest, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &e)) { GError *e2 = g_error_new ( SUMMER_DOWNLOAD_ERROR, SUMMER_DOWNLOAD_ERROR_OUTPUT, "Couldn't move download to it's final destination: %s", e->message); g_signal_emit_by_name (self, "download-error", e2); g_object_unref (self); g_clear_error (&e); g_object_unref (src); g_object_unref (dest); return; } g_object_unref (src); g_object_unref (dest); g_free (save_dir); SummerItemData *item; g_object_get (self, "item", &item, NULL); SummerFeedCache *cache = summer_feed_cache_get (); summer_feed_cache_add_new_item (cache, item); g_object_unref (G_OBJECT (cache)); g_object_unref (item); g_object_unref (web); g_signal_emit_by_name (self, "download-complete"); g_signal_emit_by_name (self, "download-done"); g_object_unref (self); }
static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback, GPtrArray *values, TrackerSparqlConnection *connection, GCancellable *cancellable, GError **error) { TrackerWritebackFileClass *writeback_file_class; gboolean retval; GFile *file, *tmp_file; GFileInfo *file_info; GStrv row; const gchar * const *content_types; const gchar *mime_type; guint n; GError *n_error = NULL; writeback_file_class = TRACKER_WRITEBACK_FILE_GET_CLASS (writeback); if (!writeback_file_class->update_file_metadata) { g_critical ("%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } if (!writeback_file_class->content_types) { g_critical ("%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } /* Get the file from the row */ row = g_ptr_array_index (values, 0); file = g_file_new_for_uri (row[0]); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_UNIX_MODE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (!file_info) { g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't exist", row[0]); return FALSE; } if (!g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { g_object_unref (file_info); g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s not writable", row[0]); return FALSE; } mime_type = g_file_info_get_content_type (file_info); content_types = (writeback_file_class->content_types) (TRACKER_WRITEBACK_FILE (writeback)); retval = FALSE; for (n = 0; content_types[n] != NULL; n++) { if (g_strcmp0 (mime_type, content_types[n]) == 0) { retval = TRUE; break; } } if (!retval) { /* module does not support writeback for this file */ g_object_unref (file_info); g_object_unref (file); g_set_error_literal (error, TRACKER_DBUS_ERROR, TRACKER_DBUS_ERROR_UNSUPPORTED, "Module does not support writeback for this file"); return FALSE; } /* Copy to a temporary file so we can perform an atomic write on move */ tmp_file = create_temporary_file (file, file_info, &n_error); if (!tmp_file) { g_object_unref (file); g_propagate_error (error, n_error); g_object_unref (file_info); return FALSE; } retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback), tmp_file, values, connection, cancellable, &n_error); if (!retval) { /* Delete the temporary file and preserve original */ g_file_delete (tmp_file, NULL, NULL); } else { GError *m_error = NULL; /* Move back the modified file to the original location */ g_file_move (tmp_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); /* Set file attributes on tmp_file using file_info of original file */ g_file_set_attributes_from_info (tmp_file, file_info, 0, NULL, &m_error); if (m_error) { g_warning ("Can't restore permissions of original file for %s", row[0]); g_error_free (m_error); } } g_object_unref (file_info); g_object_unref (tmp_file); g_object_unref (file); if (n_error) { g_propagate_error (error, n_error); } return retval; }
static void migrate_log_files_in_dir (const gchar *dirname) { GDir *dir; const gchar *subdir; gchar *new_name; gchar *full_path; GError *error = NULL; dir = g_dir_open (dirname, 0, &error); if (dir == NULL) { DEBUG ("Failed to open dir: %s", error->message); g_error_free (error); return; } while ((subdir = g_dir_read_name (dir)) != NULL) { GFile *old_gfile, *new_gfile; if (!tp_strdiff (subdir, "chatrooms")) continue; if (g_str_has_suffix (subdir, "#1")) { new_name = g_strndup (subdir, (strlen (subdir) - 2)); } else if (g_str_has_suffix (subdir, "#32")) { gchar *tmp; tmp = g_strndup (subdir, (strlen (subdir) - 3)); new_name = g_strdup_printf ("%s#yahoo", tmp); g_free (tmp); } else { continue; } full_path = g_build_filename (dirname, subdir, NULL); old_gfile = g_file_new_for_path (full_path); g_free (full_path); full_path = g_build_filename (dirname, new_name, NULL); new_gfile = g_file_new_for_path (full_path); g_free (full_path); if (!g_file_move (old_gfile, new_gfile, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) { DEBUG ("Failed to move file: %s", error->message); g_clear_error (&error); } else { DEBUG ("Successfully migrated logs for %s", new_name); } g_free (new_name); g_object_unref (old_gfile); g_object_unref (new_gfile); } g_dir_close (dir); }
static gboolean save_playlist (RBGenericPlayerPlaylistSource *source) { TotemPlParser *parser; TotemPlParserType playlist_type; RhythmDBQueryModel *query_model; char *name; char *temp_path; GError *error = NULL; RBGenericPlayerPlaylistSourcePrivate *priv = GET_PRIVATE (source); GFile *file; gboolean result; SavePlaylistData data; priv->save_playlist_id = 0; playlist_type = rb_generic_player_source_get_playlist_format (priv->player_source); g_object_get (source, "name", &name, "base-query-model", &query_model, NULL); /* if we don't already have a name for this playlist, make one now */ if (priv->playlist_path == NULL) { char *playlist_dir; char *mount_uri; char *filename; const char *ext; GFile *dir; GFile *playlist; ext = playlist_format_extension (playlist_type); if (name == NULL || name[0] == '\0') { /* now what? */ filename = g_strdup_printf ("unnamed%s", ext); } else { filename = g_strdup_printf ("%s%s", name, ext); } playlist_dir = rb_generic_player_source_get_playlist_path (priv->player_source); mount_uri = rb_generic_player_source_get_mount_path (priv->player_source); dir = g_file_new_for_uri (mount_uri); if (playlist_dir != NULL) { GFile *pdir; pdir = g_file_resolve_relative_path (dir, playlist_dir); g_object_unref (dir); dir = pdir; } playlist = g_file_resolve_relative_path (dir, filename); priv->playlist_path = g_file_get_path (playlist); g_free (mount_uri); g_free (playlist_dir); g_object_unref (dir); } temp_path = g_strdup_printf ("%s%06X", priv->playlist_path, g_random_int_range (0, 0xFFFFFF)); file = g_file_new_for_path (temp_path); parser = totem_pl_parser_new (); data.source = source; data.playlist_type = playlist_type; #if TOTEM_PL_PARSER_CHECK_VERSION(2,29,1) data.playlist = totem_pl_playlist_new (); gtk_tree_model_foreach (GTK_TREE_MODEL (query_model), (GtkTreeModelForeachFunc) save_playlist_foreach, &data); if (rb_debug_matches ("totem_pl_parser_save", "totem-pl-parser.c")) { g_object_set (parser, "debug", TRUE, NULL); } result = totem_pl_parser_save (parser, data.playlist, file, name, playlist_type, &error); g_object_unref (data.playlist); data.playlist = NULL; #else if (rb_debug_matches ("totem_pl_parser_write_with_title", "totem-pl-parser.c")) { g_object_set (parser, "debug", TRUE, NULL); } result = totem_pl_parser_write_with_title (parser, GTK_TREE_MODEL (query_model), (TotemPlParserIterFunc) save_playlist_entry, temp_path, name, playlist_type, &data, &error); #endif if (result == FALSE) { /* XXX report this more usefully */ g_warning ("Playlist save failed: %s", error ? error->message : "<no error>"); } else { GFile *dest; dest = g_file_new_for_path (priv->playlist_path); g_file_move (file, dest, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NO_FALLBACK_FOR_MOVE, NULL, NULL, NULL, &error); if (error != NULL) { /* XXX report this more usefully */ g_warning ("moving %s => %s failed: %s", temp_path, priv->playlist_path, error->message); } g_object_unref (dest); } g_clear_error (&error); g_free (name); g_free (temp_path); g_object_unref (query_model); g_object_unref (parser); g_object_unref (file); return FALSE; }
static gboolean backup_job (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data) { BackupInfo *info = user_data; const gchar *src_path; GFile *parent_file, *temp_file; gchar *temp_path; sqlite3 *src_db = NULL; sqlite3 *temp_db = NULL; sqlite3_backup *backup = NULL; src_path = tracker_db_manager_get_file (TRACKER_DB_METADATA); parent_file = g_file_get_parent (info->destination); temp_file = g_file_get_child (parent_file, TRACKER_DB_BACKUP_META_FILENAME_T); g_file_delete (temp_file, NULL, NULL); temp_path = g_file_get_path (temp_file); if (sqlite3_open_v2 (src_path, &src_db, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Could not open sqlite3 database:'%s'", src_path); } if (!info->error && sqlite3_open (temp_path, &temp_db) != SQLITE_OK) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Could not open sqlite3 database:'%s'", temp_path); } if (!info->error) { backup = sqlite3_backup_init (temp_db, "main", src_db, "main"); if (!backup) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to initialize sqlite3 backup from '%s' to '%s'", src_path, temp_path); } } if (!info->error && sqlite3_backup_step (backup, -1) != SQLITE_DONE) { g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to complete sqlite3 backup"); } if (backup) { if (sqlite3_backup_finish (backup) != SQLITE_OK) { if (info->error) { /* sqlite3_backup_finish can provide more detailed error message */ g_clear_error (&info->error); } g_set_error (&info->error, TRACKER_DB_BACKUP_ERROR, TRACKER_DB_BACKUP_ERROR_UNKNOWN, "Unable to finish sqlite3 backup: %s", sqlite3_errmsg (temp_db)); } backup = NULL; } if (temp_db) { sqlite3_close (temp_db); temp_db = NULL; } if (src_db) { sqlite3_close (src_db); src_db = NULL; } if (!info->error) { g_file_move (temp_file, info->destination, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &info->error); } g_free (temp_path); g_object_unref (temp_file); g_object_unref (parent_file); g_idle_add_full (G_PRIORITY_DEFAULT, perform_callback, info, backup_info_free); return FALSE; }
/* * NOTE: the retval has been hacked to please frontend. * it's not consistent with other hook functions. * use with care. */ static gboolean _move_files_async (GFile* src, gpointer data) { g_debug ("begin _move_files_async"); gboolean retval = TRUE; TDData* _data = (TDData*) data; GError* error = NULL; GCancellable* _move_cancellable = NULL; GFile* dest = NULL; _move_cancellable = _data->cancellable; dest = _data->dest_file; if (!_cmp_files (src, dest)) //src==dest return FALSE; g_file_move (src, dest, G_FILE_COPY_NOFOLLOW_SYMLINKS, _move_cancellable, NULL, NULL, &error); GFileType type = g_file_query_file_type (src, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL); if (error != NULL) { // g_cancellable_cancel (_move_cancellable); g_warning ("_move_files_async: %s", error->message); //TEST: if (g_prompt == TRUE) { FileOpsResponse* response = NULL; if (g_move_response != NULL && g_move_response->apply_to_all) { response = fileops_response_dup (g_move_response); //FIXME:reduce dup calls } else { response = fileops_move_copy_error_show_dialog (_("move"), error, src, dest, NULL); if (response != NULL && response->apply_to_all) g_move_response = fileops_response_dup (response); } if(response != NULL) { switch (response->response_id) { case GTK_RESPONSE_CANCEL: //cancel all operations g_debug ("response : Cancel"); retval = FALSE; break; case CONFLICT_RESPONSE_SKIP: //skip, imediately return. g_debug ("response : Skip"); retval = FALSE; break; case CONFLICT_RESPONSE_RENAME: //rename, redo operations g_debug ("response : Rename"); GFile* dest_parent = g_file_get_parent (dest); GFile* new_dest = g_file_get_child (dest_parent, response->file_name); g_object_unref (dest_parent); g_object_unref (dest); _data->dest_file = new_dest; retval = _move_files_async (src, _data); break; case CONFLICT_RESPONSE_REPLACE: if (type == G_FILE_TYPE_DIRECTORY) { //Merge: g_debug ("response : Merge"); retval = TRUE; } else { //replace g_debug ("response : Replace"); retval = _delete_files_async (dest, _data); if (retval == TRUE) { retval = _move_files_async (src, _data); } } retval = TRUE; break; default: retval = FALSE; break; } fileops_response_free (response); } } else // g_prompt == FALSE { retval = FALSE; } g_error_free (error); g_debug ("move_async: error handling end"); } #if 1 else { char* src_uri = g_file_get_uri (src); char* dest_uri = g_file_get_uri (dest); g_debug ("_move_files_async: move %s to %s", src_uri, dest_uri); g_free (src_uri); g_free (dest_uri); } #endif return retval; }
static gboolean write_theme_to_disk (MateThemeMetaInfo *theme_info, const gchar *theme_name, const gchar *theme_description, gboolean save_background, GError **error) { gchar* dir; gchar* theme_name_dir; GFile* tmp_file; GFile* target_file; GOutputStream* output; gchar* str; gchar* current_background; GSettings* settings; const gchar* theme_header = "" "[Desktop Entry]\n" "Name=%s\n" "Type=X-GNOME-Metatheme\n" "Comment=%s\n" "\n" "[X-GNOME-Metatheme]\n" "GtkTheme=%s\n" "MetacityTheme=%s\n" "IconTheme=%s\n"; theme_name_dir = str_remove_slash (theme_name); dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme~", NULL); g_free (theme_name_dir); tmp_file = g_file_new_for_path (dir); dir [strlen (dir) - 1] = '\000'; target_file = g_file_new_for_path (dir); g_free (dir); /* start making the theme file */ str = g_strdup_printf(theme_header, theme_name, theme_description, theme_info->gtk_theme_name, theme_info->marco_theme_name, theme_info->icon_theme_name); output = G_OUTPUT_STREAM (g_file_replace (tmp_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL)); g_output_stream_write (output, str, strlen (str), NULL, NULL); g_free (str); if (theme_info->gtk_color_scheme) { gchar *a, *tmp; tmp = g_strdup (theme_info->gtk_color_scheme); for (a = tmp; *a != '\0'; a++) if (*a == '\n') *a = ','; str = g_strdup_printf ("GtkColorScheme=%s\n", tmp); g_output_stream_write (output, str, strlen (str), NULL, NULL); g_free (str); g_free (tmp); } if (theme_info->cursor_theme_name) { #ifdef HAVE_XCURSOR str = g_strdup_printf ("CursorTheme=%s\n" "CursorSize=%i\n", theme_info->cursor_theme_name, theme_info->cursor_size); #else str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name); #endif g_output_stream_write (output, str, strlen (str), NULL, NULL); g_free (str); } if (theme_info->notification_theme_name) { str = g_strdup_printf ("NotificationTheme=%s\n", theme_info->notification_theme_name); g_output_stream_write (output, str, strlen (str), NULL, NULL); g_free (str); } if (save_background) { settings = g_settings_new (WP_SCHEMA); current_background = g_settings_get_string (settings, WP_FILE_KEY); if (current_background != NULL) { str = g_strdup_printf ("BackgroundImage=%s\n", current_background); g_output_stream_write (output, str, strlen (str), NULL, NULL); g_free (current_background); g_free (str); } g_object_unref (settings); } g_file_move (tmp_file, target_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); g_output_stream_close (output, NULL, NULL); g_object_unref (tmp_file); g_object_unref (target_file); return TRUE; }
/* * Write Flac tag, using the level 2 flac interface */ gboolean flac_tag_write_file_tag (const ET_File *ETFile, GError **error) { const File_Tag *FileTag; GFile *file; GFileIOStream *iostream; EtFlacWriteState state; FLAC__IOCallbacks callbacks = { et_flac_read_func, et_flac_write_func, et_flac_seek_func, et_flac_tell_func, et_flac_eof_func, et_flac_write_close_func }; const gchar *filename; const gchar *filename_utf8; const gchar *flac_error_msg; FLAC__Metadata_Chain *chain; FLAC__Metadata_Iterator *iter; FLAC__StreamMetadata_VorbisComment_Entry vce_field_vendor_string; // To save vendor string gboolean vce_field_vendor_string_found = FALSE; g_return_val_if_fail (ETFile != NULL && ETFile->FileTag != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); FileTag = (File_Tag *)ETFile->FileTag->data; filename = ((File_Name *)ETFile->FileNameCur->data)->value; filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8; /* libFLAC is able to detect (and skip) ID3v2 tags by itself */ /* Create a new chain instance to get all blocks in one time. */ chain = FLAC__metadata_chain_new (); if (chain == NULL) { flac_error_msg = FLAC__Metadata_ChainStatusString[FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR]; g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Error while opening file ‘%s’ as FLAC: %s"), filename_utf8, flac_error_msg); return FALSE; } file = g_file_new_for_path (filename); state.file = file; state.error = NULL; /* TODO: Fallback to an in-memory copy of the file for non-local files, * where creation of the GFileIOStream may fail. */ iostream = g_file_open_readwrite (file, NULL, &state.error); if (iostream == NULL) { FLAC__metadata_chain_delete (chain); g_propagate_error (error, state.error); g_object_unref (file); return FALSE; } state.istream = G_FILE_INPUT_STREAM (g_io_stream_get_input_stream (G_IO_STREAM (iostream))); state.ostream = G_FILE_OUTPUT_STREAM (g_io_stream_get_output_stream (G_IO_STREAM (iostream))); state.seekable = G_SEEKABLE (iostream); state.iostream = iostream; if (!FLAC__metadata_chain_read_with_callbacks (chain, &state, callbacks)) { const FLAC__Metadata_ChainStatus status = FLAC__metadata_chain_status (chain); flac_error_msg = FLAC__Metadata_ChainStatusString[status]; FLAC__metadata_chain_delete (chain); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Error while opening file ‘%s’ as FLAC: %s"), filename_utf8, flac_error_msg); et_flac_write_close_func (&state); return FALSE; } /* Create a new iterator instance for the chain. */ iter = FLAC__metadata_iterator_new (); if (iter == NULL) { flac_error_msg = FLAC__Metadata_ChainStatusString[FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR]; g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Error while opening file ‘%s’ as FLAC: %s"), filename_utf8, flac_error_msg); FLAC__metadata_chain_delete (chain); et_flac_write_close_func (&state); return FALSE; } FLAC__metadata_iterator_init (iter, chain); while (FLAC__metadata_iterator_next (iter)) { const FLAC__MetadataType block_type = FLAC__metadata_iterator_get_block_type (iter); /* TODO: Modify the blocks directly, rather than deleting and * recreating. */ if (block_type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { // Delete the VORBIS_COMMENT block and convert to padding. But before, save the original vendor string. /* Get block data. */ FLAC__StreamMetadata *block = FLAC__metadata_iterator_get_block(iter); FLAC__StreamMetadata_VorbisComment *vc = &block->data.vorbis_comment; if (vc->vendor_string.entry != NULL) { // Get initial vendor string, to don't alterate it by FLAC__VENDOR_STRING when saving file vce_field_vendor_string.entry = (FLAC__byte *)g_strdup ((gchar *)vc->vendor_string.entry); vce_field_vendor_string.length = strlen ((gchar *)vce_field_vendor_string.entry); vce_field_vendor_string_found = TRUE; } /* Free block data. */ FLAC__metadata_iterator_delete_block (iter, true); } else if (block_type == FLAC__METADATA_TYPE_PICTURE) { /* Delete all the PICTURE blocks, and convert to padding. */ FLAC__metadata_iterator_delete_block (iter, true); } } // // Create and insert a new VORBISCOMMENT block // { FLAC__StreamMetadata *vc_block; // For vorbis comments GList *l; // Allocate a block for Vorbis comments vc_block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT); // Set the original vendor string, else will be use the version of library if (vce_field_vendor_string_found) { // must set 'copy' param to false, because the API will reuse the pointer of an empty // string (yet still return 'true', indicating it was copied); the string is free'd during // metadata_chain_delete routine FLAC__metadata_object_vorbiscomment_set_vendor_string(vc_block, vce_field_vendor_string, /*copy=*/false); } /********* * Title * *********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_TITLE, FileTag->title, g_settings_get_boolean (MainSettings, "ogg-split-title")); /********** * Artist * **********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_ARTIST, FileTag->artist, g_settings_get_boolean (MainSettings, "ogg-split-artist")); /**************** * Album Artist * ****************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_ALBUM_ARTIST, FileTag->album_artist, g_settings_get_boolean (MainSettings, "ogg-split-artist")); /********* * Album * *********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_ALBUM, FileTag->album, g_settings_get_boolean (MainSettings, "ogg-split-album")); /****************************** * Disc Number and Disc Total * ******************************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_DISC_NUMBER, FileTag->disc_number, FALSE); vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_DISC_TOTAL, FileTag->disc_total, FALSE); /******** * Year * ********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_DATE, FileTag->year, FALSE); /************************* * Track and Total Track * *************************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_TRACK_NUMBER, FileTag->track, FALSE); vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_TRACK_TOTAL, FileTag->track_total, FALSE); /********* * Genre * *********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_GENRE, FileTag->genre, g_settings_get_boolean (MainSettings, "ogg-split-genre")); /*********** * Comment * ***********/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_DESCRIPTION, FileTag->comment, g_settings_get_boolean (MainSettings, "ogg-split-comment")); /************ * Composer * ************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_COMPOSER, FileTag->composer, g_settings_get_boolean (MainSettings, "ogg-split-composer")); /******************* * Original artist * *******************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_PERFORMER, FileTag->orig_artist, g_settings_get_boolean (MainSettings, "ogg-split-original-artist")); /************* * Copyright * *************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_COPYRIGHT, FileTag->copyright, FALSE); /******* * URL * *******/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_CONTACT, FileTag->url, FALSE); /************** * Encoded by * **************/ vc_block_append_tag (vc_block, ET_VORBIS_COMMENT_FIELD_ENCODED_BY, FileTag->encoded_by, FALSE); /************************** * Set unsupported fields * **************************/ for (l = FileTag->other; l != NULL; l = g_list_next (l)) { vc_block_append_other_tag (vc_block, (gchar *)l->data); } // Add the block to the the chain (so we don't need to free the block) FLAC__metadata_iterator_insert_block_after(iter, vc_block); } // // Create and insert PICTURE blocks // /*********** * Picture * ***********/ { EtPicture *pic = FileTag->picture; while (pic) { /* TODO: Can this ever be NULL? */ if (pic->bytes) { const gchar *violation; FLAC__StreamMetadata *picture_block; // For picture data Picture_Format format; gconstpointer data; gsize data_size; // Allocate block for picture data picture_block = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE); // Type picture_block->data.picture.type = pic->type; // Mime type format = Picture_Format_From_Data(pic); /* Safe to pass a const string, according to the FLAC API * reference. */ FLAC__metadata_object_picture_set_mime_type(picture_block, (gchar *)Picture_Mime_Type_String(format), TRUE); // Description if (pic->description) { FLAC__metadata_object_picture_set_description(picture_block, (FLAC__byte *)pic->description, TRUE); } // Resolution picture_block->data.picture.width = pic->width; picture_block->data.picture.height = pic->height; picture_block->data.picture.depth = 0; /* Picture data. */ data = g_bytes_get_data (pic->bytes, &data_size); /* Safe to pass const data, if the last argument (copy) is * TRUE, according the the FLAC API reference. */ FLAC__metadata_object_picture_set_data (picture_block, (FLAC__byte *)data, (FLAC__uint32)data_size, true); if (!FLAC__metadata_object_picture_is_legal (picture_block, &violation)) { g_critical ("Created an invalid picture block: ‘%s’", violation); FLAC__metadata_object_delete (picture_block); } else { // Add the block to the the chain (so we don't need to free the block) FLAC__metadata_iterator_insert_block_after(iter, picture_block); } } pic = pic->next; } } FLAC__metadata_iterator_delete (iter); // // Prepare for writing tag // FLAC__metadata_chain_sort_padding (chain); /* Write tag. */ if (FLAC__metadata_chain_check_if_tempfile_needed (chain, true)) { EtFlacWriteState temp_state; GFile *temp_file; GFileIOStream *temp_iostream; GError *temp_error = NULL; temp_file = g_file_new_tmp ("easytag-XXXXXX", &temp_iostream, &temp_error); if (temp_file == NULL) { FLAC__metadata_chain_delete (chain); g_propagate_error (error, temp_error); et_flac_write_close_func (&state); return FALSE; } temp_state.file = temp_file; temp_state.error = NULL; temp_state.istream = G_FILE_INPUT_STREAM (g_io_stream_get_input_stream (G_IO_STREAM (temp_iostream))); temp_state.ostream = G_FILE_OUTPUT_STREAM (g_io_stream_get_output_stream (G_IO_STREAM (temp_iostream))); temp_state.seekable = G_SEEKABLE (temp_iostream); temp_state.iostream = temp_iostream; if (!FLAC__metadata_chain_write_with_callbacks_and_tempfile (chain, true, &state, callbacks, &temp_state, callbacks)) { const FLAC__Metadata_ChainStatus status = FLAC__metadata_chain_status (chain); flac_error_msg = FLAC__Metadata_ChainStatusString[status]; FLAC__metadata_chain_delete (chain); et_flac_write_close_func (&temp_state); et_flac_write_close_func (&state); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to write comments to file ‘%s’: %s"), filename_utf8, flac_error_msg); return FALSE; } if (!g_file_move (temp_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &state.error)) { FLAC__metadata_chain_delete (chain); et_flac_write_close_func (&temp_state); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to write comments to file ‘%s’: %s"), filename_utf8, state.error->message); et_flac_write_close_func (&state); return FALSE; } et_flac_write_close_func (&temp_state); } else { if (!FLAC__metadata_chain_write_with_callbacks (chain, true, &state, callbacks)) { const FLAC__Metadata_ChainStatus status = FLAC__metadata_chain_status (chain); flac_error_msg = FLAC__Metadata_ChainStatusString[status]; FLAC__metadata_chain_delete (chain); et_flac_write_close_func (&state); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Failed to write comments to file ‘%s’: %s"), filename_utf8, flac_error_msg); return FALSE; } } FLAC__metadata_chain_delete (chain); et_flac_write_close_func (&state); #ifdef ENABLE_MP3 { // Delete the ID3 tags (create a dummy ETFile for the Id3tag_... function) ET_File *ETFile_tmp = ET_File_Item_New(); File_Name *FileName_tmp = et_file_name_new (); File_Tag *FileTag_tmp = et_file_tag_new (); // Same file... FileName_tmp->value = g_strdup(filename); FileName_tmp->value_utf8 = g_strdup(filename_utf8); // Not necessary to fill 'value_ck' ETFile_tmp->FileNameList = g_list_append(NULL,FileName_tmp); ETFile_tmp->FileNameCur = ETFile_tmp->FileNameList; // With empty tag... ETFile_tmp->FileTagList = g_list_append(NULL,FileTag_tmp); ETFile_tmp->FileTag = ETFile_tmp->FileTagList; id3tag_write_file_tag (ETFile_tmp, NULL); ET_Free_File_List_Item(ETFile_tmp); } #endif return TRUE; }