int extract_rename( struct function *list, char *output_name ) { struct function *f; struct option *o; FILE *file; int count; file = fopen(output_name,"r+"); if(!file) { fprintf(stderr,"\tnothing to rename\n"); return 0; } for( f=list; f; f=f->next ) { o = f->options; fprintf(stderr,"\t%s\t",f->name->text); if(o->linkage==OPTION_LINKAGE_LIBCALL) { char *old_name = f->name->text; char *new_name = upper_string(f->name->text); fprintf(stderr,"%s\t%s -> %s\t",o->library->text,old_name,new_name); count = replace_in_file(file,old_name,new_name); fprintf(stderr,"(%d instances)",count); } fprintf(stderr,"\n"); } fclose(file); return 1; }
static void restore (const gchar *filename, GCancellable *cancellable) { gchar *command; gchar *quotedfname; gboolean is_new_format = FALSE; g_return_if_fail (filename && *filename); if (!check (filename, &is_new_format)) { g_message ("Cannot restore from an incorrect archive '%s'.", filename); goto end; } quotedfname = g_shell_quote (filename); if (g_cancellable_is_cancelled (cancellable)) return; /* FIXME Will the versioned setting always work? */ txt = _("Shutting down Evolution"); run_cmd (EVOLUTION " --quit"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Back up current Evolution data"); run_cmd ("mv $DATADIR $DATADIR_old"); run_cmd ("mv $CONFIGDIR $CONFIGDIR_old"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Extracting files from back up"); if (is_new_format) { GString *dir_fn; gchar *data_dir = NULL; gchar *config_dir = NULL; gchar *restored_version = NULL; const gchar *tar_opts; if (get_filename_is_xz (filename)) tar_opts = "-xJf"; else tar_opts = "-xzf"; command = g_strdup_printf ( "cd $TMP && tar %s %s " EVOLUTION_DIR_FILE, tar_opts, quotedfname); run_cmd (command); g_free (command); dir_fn = replace_variables ("$TMP" G_DIR_SEPARATOR_S EVOLUTION_DIR_FILE, TRUE); if (!dir_fn) { g_warning ("Failed to create evolution's dir filename"); goto end; } /* data_dir and config_dir are quoted inside extract_backup_data */ extract_backup_data ( dir_fn->str, &restored_version, &data_dir, &config_dir); g_unlink (dir_fn->str); g_string_free (dir_fn, TRUE); if (!data_dir || !config_dir) { g_warning ( "Failed to get old data_dir (%p)/" "config_dir (%p)", data_dir, config_dir); g_free (data_dir); g_free (config_dir); goto end; } g_mkdir_with_parents (e_get_user_data_dir (), 0700); g_mkdir_with_parents (e_get_user_config_dir (), 0700); command = g_strdup_printf ( "cd $DATADIR && tar --strip-components %d %s %s %s", get_dir_level (data_dir), tar_opts, quotedfname, data_dir); run_cmd (command); g_free (command); command = g_strdup_printf ( "cd $CONFIGDIR && tar --strip-components %d %s %s %s", get_dir_level (config_dir), tar_opts, quotedfname, config_dir); run_cmd (command); g_free (command); /* If the back file had version information, set the last * used version in GSettings before restarting Evolution. */ if (restored_version != NULL && *restored_version != '\0') { GSettings *settings; settings = e_util_ref_settings ("org.gnome.evolution"); g_settings_set_string ( settings, "version", restored_version); g_object_unref (settings); } g_free (data_dir); g_free (config_dir); g_free (restored_version); } else { const gchar *decr_opts; if (get_filename_is_xz (filename)) decr_opts = "xz -cd"; else decr_opts = "gzip -cd"; run_cmd ("mv $HOME/.evolution $HOME/.evolution_old"); command = g_strdup_printf ( "cd $HOME && %s %s | tar xf -", decr_opts, quotedfname); run_cmd (command); g_free (command); } g_free (quotedfname); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Loading Evolution settings"); if (is_new_format) { /* new format has it in DATADIR... */ GString *file = replace_variables (EVOLUTION_DIR ANCIENT_GCONF_DUMP_FILE, TRUE); if (file && g_file_test (file->str, G_FILE_TEST_EXISTS)) { unset_eds_migrated_flag (); /* ancient backup */ replace_in_file ( EVOLUTION_DIR ANCIENT_GCONF_DUMP_FILE, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); run_cmd ("gconftool-2 --load " EVOLUTION_DIR ANCIENT_GCONF_DUMP_FILE); /* give a chance to GConf to save what was loaded into a disk */ g_usleep (G_USEC_PER_SEC * 5); /* do not forget to convert GConf keys into GSettings */ run_cmd ("gsettings-data-convert"); run_cmd ("rm " EVOLUTION_DIR ANCIENT_GCONF_DUMP_FILE); } else { replace_in_file ( EVOLUTION_DIR DCONF_DUMP_FILE_EDS, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); run_cmd ("cat " EVOLUTION_DIR DCONF_DUMP_FILE_EDS " | dconf load " DCONF_PATH_EDS); run_cmd ("rm " EVOLUTION_DIR DCONF_DUMP_FILE_EDS); replace_in_file ( EVOLUTION_DIR DCONF_DUMP_FILE_EVO, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); run_cmd ("cat " EVOLUTION_DIR DCONF_DUMP_FILE_EVO " | dconf load " DCONF_PATH_EVO); run_cmd ("rm " EVOLUTION_DIR DCONF_DUMP_FILE_EVO); } g_string_free (file, TRUE); } else { gchar *gconf_dump_file; unset_eds_migrated_flag (); /* ... old format in ~/.evolution */ gconf_dump_file = g_build_filename ( "$HOME", ".evolution", ANCIENT_GCONF_DUMP_FILE, NULL); replace_in_file ( gconf_dump_file, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); command = g_strconcat ( "gconftool-2 --load ", gconf_dump_file, NULL); run_cmd (command); g_free (command); /* give a chance to GConf to save what was loaded into a disk */ g_usleep (G_USEC_PER_SEC * 5); /* do not forget to convert GConf keys into GSettings */ run_cmd ("gsettings-data-convert"); command = g_strconcat ("rm ", gconf_dump_file, NULL); run_cmd (command); g_free (command); g_free (gconf_dump_file); } if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Removing temporary back up files"); run_cmd ("rm -rf $DATADIR_old"); run_cmd ("rm -rf $CONFIGDIR_old"); run_cmd ("rm $DATADIR/.running"); if (!is_new_format) run_cmd ("rm -rf $HOME/.evolution_old"); if (g_cancellable_is_cancelled (cancellable)) return; /* Make full-restart background processes after restore */ run_cmd (EVOLUTION " --force-shutdown"); txt = _("Reloading registry service"); /* wait few seconds, till changes settle */ g_usleep (G_USEC_PER_SEC * 5); command = get_source_manager_reload_command (); /* This runs migration routines on the newly-restored data. */ run_cmd (command); g_free (command); end: if (restart_arg) { if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Restarting Evolution"); /* wait 5 seconds before restarting evolution, thus any * changes being done are updated in source registry too */ g_usleep (G_USEC_PER_SEC * 5); run_evolution_no_wait (); } }
static void backup (const gchar *filename, GCancellable *cancellable) { gchar *command; gchar *quotedfname; gboolean use_xz; g_return_if_fail (filename && *filename); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Shutting down Evolution"); /* FIXME Will the versioned setting always work? */ run_cmd (EVOLUTION " --quit"); run_cmd ("rm $DATADIR/.running"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Backing Evolution accounts and settings"); run_cmd ("dconf dump " DCONF_PATH_EDS " >" EVOLUTION_DIR DCONF_DUMP_FILE_EDS); run_cmd ("dconf dump " DCONF_PATH_EVO " >" EVOLUTION_DIR DCONF_DUMP_FILE_EVO); replace_in_file ( EVOLUTION_DIR DCONF_DUMP_FILE_EDS, e_get_user_data_dir (), EVOUSERDATADIR_MAGIC); replace_in_file ( EVOLUTION_DIR DCONF_DUMP_FILE_EVO, e_get_user_data_dir (), EVOUSERDATADIR_MAGIC); write_dir_file (); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Backing Evolution data (Mails, Contacts, Calendar, Tasks, Memos)"); quotedfname = g_shell_quote (filename); use_xz = get_filename_is_xz (filename); command = g_strdup_printf ( "cd $HOME && tar chf - $STRIPDATADIR " "$STRIPCONFIGDIR " EVOLUTION_DIR_FILE " | " "%s > %s", use_xz ? "xz -z" : "gzip", quotedfname); run_cmd (command); g_free (command); g_free (quotedfname); run_cmd ("rm $HOME/" EVOLUTION_DIR_FILE); txt = _("Back up complete"); if (restart_arg) { if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Restarting Evolution"); run_evolution_no_wait (); } }
static void restore (const gchar *filename, GCancellable *cancellable) { gchar *command; gchar *quotedfname; gboolean is_new_format = FALSE; g_return_if_fail (filename && *filename); if (!check (filename, &is_new_format)) { g_message ("Cannot restore from an incorrect archive '%s'.", filename); goto end; } quotedfname = g_shell_quote (filename); if (g_cancellable_is_cancelled (cancellable)) return; /* FIXME Will the versioned setting always work? */ txt = _("Shutting down Evolution"); run_cmd (EVOLUTION " --quit"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Back up current Evolution data"); run_cmd ("mv $DATADIR $DATADIR_old"); run_cmd ("mv $CONFIGDIR $CONFIGDIR_old"); run_cmd ("mv $HOME/.camel_certs $HOME/.camel_certs_old"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Extracting files from back up"); if (is_new_format) { GString *dir_fn; gchar *data_dir = NULL, *config_dir = NULL; command = g_strdup_printf ( "cd $TMP && tar xzf %s " EVOLUTION_DIR_FILE, quotedfname); run_cmd (command); g_free (command); dir_fn = replace_variables ("$TMP" G_DIR_SEPARATOR_S EVOLUTION_DIR_FILE); if (!dir_fn) { g_warning ("Failed to create evolution's dir filename"); goto end; } /* data_dir and config_dir are quoted inside extract_backup_dirs */ extract_backup_dirs (dir_fn->str, &data_dir, &config_dir); g_unlink (dir_fn->str); g_string_free (dir_fn, TRUE); if (!data_dir || !config_dir) { g_warning ("Failed to get old data_dir (%p)/config_dir (%p)", data_dir, config_dir); g_free (data_dir); g_free (config_dir); goto end; } g_mkdir_with_parents (e_get_user_data_dir (), 0700); g_mkdir_with_parents (e_get_user_config_dir (), 0700); command = g_strdup_printf ( "cd $DATADIR && tar xzf %s %s --strip-components=%d", quotedfname, data_dir, get_dir_level (data_dir)); run_cmd (command); g_free (command); command = g_strdup_printf ( "cd $CONFIGDIR && tar xzf %s %s --strip-components=%d", quotedfname, config_dir, get_dir_level (config_dir)); run_cmd (command); g_free (command); command = g_strdup_printf ( "cd $HOME && tar xzf %s .camel_certs", quotedfname); run_cmd (command); g_free (command); g_free (data_dir); g_free (config_dir); } else { run_cmd ("mv $HOME/.evolution $HOME/.evolution_old"); command = g_strdup_printf ( "cd $HOME && gzip -cd %s | tar xf -", quotedfname); run_cmd (command); g_free (command); } g_free (quotedfname); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Loading Evolution settings"); if (is_new_format) { /* new format has it in DATADIR... */ replace_in_file ( EVOLUTION_DIR GCONF_DUMP_FILE, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); run_cmd ("gconftool-2 --load " EVOLUTION_DIR GCONF_DUMP_FILE); run_cmd ("rm " EVOLUTION_DIR GCONF_DUMP_FILE); } else { gchar *gconf_dump_file; /* ... old format in ~/.evolution */ gconf_dump_file = g_build_filename ( "$HOME", ".evolution", GCONF_DUMP_FILE, NULL); replace_in_file ( gconf_dump_file, EVOUSERDATADIR_MAGIC, e_get_user_data_dir ()); command = g_strconcat ( "gconftool-2 --load ", gconf_dump_file, NULL); run_cmd (command); g_free (command); command = g_strconcat ("rm ", gconf_dump_file, NULL); run_cmd (command); g_free (command); g_free (gconf_dump_file); } if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Removing temporary back up files"); run_cmd ("rm -rf $DATADIR_old"); run_cmd ("rm -rf $CONFIGDIR_old"); run_cmd ("rm -rf $HOME/.camel_certs_old"); run_cmd ("rm $DATADIR/.running"); if (!is_new_format) run_cmd ("rm -rf $HOME/.evolution_old"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Ensuring local sources"); end: if (restart_arg) { if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Restarting Evolution"); run_evolution_no_wait (); } }
static void backup (const gchar *filename, GCancellable *cancellable) { gchar *command; gchar *quotedfname; g_return_if_fail (filename && *filename); quotedfname = g_shell_quote (filename); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Shutting down Evolution"); /* FIXME Will the versioned setting always work? */ run_cmd (EVOLUTION " --quit"); run_cmd ("rm $DATADIR/.running"); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Backing Evolution accounts and settings"); run_cmd ("gconftool-2 --dump " GCONF_DIR " > " EVOLUTION_DIR GCONF_DUMP_FILE); replace_in_file ( EVOLUTION_DIR GCONF_DUMP_FILE, e_get_user_data_dir (), EVOUSERDATADIR_MAGIC); write_dir_file (); if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Backing Evolution data (Mails, Contacts, Calendar, Tasks, Memos)"); /* FIXME stay on this file system ,other options?" */ /* FIXME compression type?" */ /* FIXME date/time stamp?" */ /* FIXME backup location?" */ command = g_strdup_printf ( "cd $HOME && tar chf - $STRIPDATADIR " "$STRIPCONFIGDIR .camel_certs " EVOLUTION_DIR_FILE " | " "gzip > %s", quotedfname); run_cmd (command); g_free (command); g_free (quotedfname); run_cmd ("rm $HOME/" EVOLUTION_DIR_FILE); txt = _("Back up complete"); if (restart_arg) { if (g_cancellable_is_cancelled (cancellable)) return; txt = _("Restarting Evolution"); run_evolution_no_wait (); } }