Esempio n. 1
0
gboolean
e_shell_migrate_attempt (EShell *shell)
{
	gint major, minor, micro;

	g_return_val_if_fail (E_IS_SHELL (shell), FALSE);

	shell_migrate_get_version (shell, &major, &minor, &micro);

	/* Abort all migration if the user downgraded. */
	if (shell_migrate_downgraded (major, minor, micro))
		return TRUE;

	/* This sets the folder permissions to S_IRWXU if needed */
	if (major <= 2 && minor <= 30)
		fix_folder_permissions (e_get_user_data_dir ());

	/* Attempt to run migration all the time and let the backend
	 * make the choice */
	if (!shell_migrate_attempt (shell, major, minor, micro))
		_exit (EXIT_SUCCESS);

	/* We want our handler to run last, hence g_signal_connect_after(). */
	g_signal_connect_after (
		shell, "event::ready-to-start",
		G_CALLBACK (shell_migrate_ready_to_start_event_cb), NULL);

	return TRUE;
}
GList *
e_composer_autosave_find_orphans (GError **error)
{
	GDir *dir;
	const gchar *dirname;
	const gchar *basename;
	GList *orphans = NULL;

	dirname = e_get_user_data_dir ();
	dir = g_dir_open (dirname, 0, error);
	if (dir == NULL)
		return NULL;

	/* Scan the user directory for autosave files. */
	while ((basename = g_dir_read_name (dir)) != NULL) {
		const gchar *errmsg;
		gchar *filename;
		struct stat st;

		/* Is this an autosave file? */
		if (!g_str_has_prefix (basename, AUTOSAVE_PREFIX))
			continue;

		/* Is this an orphaned autosave file? */
		if (composer_autosave_registry_lookup (basename) != NULL)
			continue;

		filename = g_build_filename (dirname, basename, NULL);

		/* Try to examine the autosave file.  Failure here
		 * is non-fatal; just emit a warning and move on. */
		errno = 0;
		if (g_stat (filename, &st) < 0) {
			errmsg = g_strerror (errno);
			g_warning ("%s: %s", filename, errmsg);
			g_free (filename);
			continue;
		}

		/* If the file is empty, delete it.  Failure here
		 * is non-fatal; just emit a warning and move on. */
		if (st.st_size == 0) {
			errno = 0;
			if (g_unlink (filename) < 0) {
				errmsg = g_strerror (errno);
				g_warning ("%s: %s", filename, errmsg);
			}
			g_free (filename);
			continue;
		}

		orphans = g_list_prepend (orphans, filename);
	}

	g_dir_close (dir);

	return g_list_reverse (orphans);
}
Esempio n. 3
0
void
e_convert_local_mail (EShell *shell)
{
	CamelSession *session;
	ESource *mbox_source;
	const gchar *user_data_dir;
	const gchar *user_cache_dir;
	gchar *mail_data_dir;
	gchar *mail_cache_dir;
	gchar *local_store;
	gint response;

	user_data_dir = e_get_user_data_dir ();
	user_cache_dir = e_get_user_cache_dir ();

	mail_data_dir = g_build_filename (user_data_dir, "mail", NULL);
	mail_cache_dir = g_build_filename (user_cache_dir, "mail", NULL);

	if (!mail_to_maildir_migration_needed (mail_data_dir))
		goto exit;

	response = e_alert_run_dialog_for_args (
		e_shell_get_active_window (NULL),
		"mail:ask-migrate-store", NULL);

	if (response == GTK_RESPONSE_CANCEL)
		exit (EXIT_SUCCESS);

	mbox_source = e_source_new (NULL, NULL, NULL);

	rename_mbox_dir (mbox_source, mail_data_dir);

	local_store = g_build_filename (mail_data_dir, "local", NULL);

	if (!g_file_test (local_store, G_FILE_TEST_EXISTS))
		g_mkdir_with_parents (local_store, 0700);

	g_free (local_store);

	session = g_object_new (
		CAMEL_TYPE_SESSION,
		"online", FALSE,
		"user-data-dir", mail_data_dir,
		"user-cache-dir", mail_cache_dir,
		NULL);

	migrate_mbox_to_maildir (shell, session, mbox_source);

	g_object_unref (session);

	g_object_unref (mbox_source);

exit:
	g_free (mail_data_dir);
	g_free (mail_cache_dir);
}
Esempio n. 4
0
static GString *
replace_variables (const gchar *str,
                   gboolean remove_dir_sep)
{
	GString *res = NULL, *use;
	const gchar *strip_datadir, *strip_configdir;

	g_return_val_if_fail (str != NULL, NULL);

	strip_datadir = strip_home_dir (e_get_user_data_dir ());
	strip_configdir = strip_home_dir (e_get_user_config_dir ());

	#define repl(_find, _replace)							\
		use = e_str_replace_string (res ? res->str : str, _find, _replace);	\
		g_return_val_if_fail (use != NULL, NULL);				\
		if (res)								\
			g_string_free (res, TRUE);					\
		res = use;

	repl ("$HOME", g_get_home_dir ());
	repl ("$TMP", g_get_tmp_dir ());
	repl ("$DATADIR", e_get_user_data_dir ());
	repl ("$CONFIGDIR", e_get_user_config_dir ());
	repl ("$STRIPDATADIR", strip_datadir);
	repl ("$STRIPCONFIGDIR", strip_configdir);
	repl ("$DBUSDATADIR", DBUS_SERVICES_DIR);

	#undef repl

	g_return_val_if_fail (res != NULL, NULL);

	if (remove_dir_sep) {
		/* remove trailing dir separator */
		while (res->len > 0 && res->str[res->len - 1] == G_DIR_SEPARATOR) {
			g_string_truncate (res, res->len - 1);
		}
	}

	return res;
}
Esempio n. 5
0
static GFile *
create_snapshot_file (EMsgComposer *composer,
                      GError **error)
{
	GFile *snapshot_file;
	const gchar *user_data_dir;
	gchar *path;
	gint fd;

	snapshot_file = e_composer_get_snapshot_file (composer);

	if (G_IS_FILE (snapshot_file))
		return snapshot_file;

	user_data_dir = e_get_user_data_dir ();
	path = g_build_filename (user_data_dir, SNAPSHOT_FILE_SEED, NULL);

	/* g_mkstemp() modifies the XXXXXX part of the
	 * template string to form the actual filename. */
	errno = 0;
	fd = g_mkstemp (path);
	if (fd == -1) {
		g_set_error (
			error, G_FILE_ERROR,
			g_file_error_from_errno (errno),
			"%s", g_strerror (errno));
		g_free (path);
		return NULL;
	}

	close (fd);

	snapshot_file = g_file_new_for_path (path);

	/* Save the GFile for subsequent snapshots. */
	g_object_set_data_full (
		G_OBJECT (composer),
		SNAPSHOT_FILE_KEY, snapshot_file,
		(GDestroyNotify) delete_snapshot_file);

	g_free (path);

	return snapshot_file;
}
Esempio n. 6
0
static void
impl_upgradeFromVersion (PortableServer_Servant servant, const short major, const short minor, const short revision, CORBA_Environment *ev)
{
	MailComponent *component;
	CamelException ex;

	component = mail_component_peek ();

	camel_exception_init (&ex);
	if (em_migrate (e_get_user_data_dir (), major, minor, revision, &ex) == -1) {
		GNOME_Evolution_Component_UpgradeFailed *failedex;

		failedex = GNOME_Evolution_Component_UpgradeFailed__alloc();
		failedex->what = CORBA_string_dup(_("Failed upgrading Mail settings or folders."));
		failedex->why = CORBA_string_dup(ex.desc);
		CORBA_exception_set(ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Component_UpgradeFailed, failedex);
	}

	camel_exception_clear (&ex);
}
Esempio n. 7
0
static const gchar *
test_new_system_memos (void)
{
#if 0  /* ACCOUNT_MGMT */
	const gchar *user_data_dir;
	gchar *filename;
	gboolean created;

	e_cal_new_system_memos ();

	user_data_dir = e_get_user_data_dir ();
	filename = g_build_filename (
		user_data_dir, "memos", "system", "journal.ics", NULL);
	created = g_file_test (filename, G_FILE_TEST_EXISTS);
	g_free (filename);

	mu_assert ("Test creation of default system memos : Failed", created);
#endif /* ACCOUNT_MGMT */

	return NULL;
}
static gboolean
composer_autosave_state_open (AutosaveState *state,
                              GError **error)
{
	if (state->filename != NULL)
		return TRUE;

	state->filename = g_build_filename (
		e_get_user_data_dir (), AUTOSAVE_SEED, NULL);

	errno = 0;
	if ((state->fd = g_mkstemp (state->filename)) >= 0)
		return TRUE;

	g_set_error (
		error, G_FILE_ERROR,
		g_file_error_from_errno (errno),
		"%s: %s", state->filename, g_strerror (errno));

	g_free (state->filename);
	state->filename = NULL;

	return FALSE;
}
Esempio n. 9
0
static void
shell_xdg_migrate_data_dir (EShell *shell,
                            const gchar *old_base_dir)
{
	GDir *dir;
	GHashTable *corrections;
	const gchar *basename;
	const gchar *old_data_dir;
	const gchar *new_data_dir;
	gchar *src_directory;
	gchar *dst_directory;

	g_print ("Migrating local user data\n");

	old_data_dir = old_base_dir;
	new_data_dir = e_get_user_data_dir ();

	/* The mail hierarchy is complex and Camel doesn't distinguish
	 * between user data files and disposable cache files, so just
	 * move everything to the data directory for now.  We'll sort
	 * it out sometime down the road. */

	src_directory = g_build_filename (old_data_dir, "mail", NULL);
	dst_directory = g_build_filename (new_data_dir, "mail", NULL);

	dir = g_dir_open (src_directory, 0, NULL);
	if (dir == NULL)
		goto skip_mail;

	/* This is to avoid removing directories while we're iterating
	 * over the parent directory.  POSIX says the outcome of that
	 * is unspecified. */
	corrections = g_hash_table_new_full (
		g_str_hash, g_str_equal,
		(GDestroyNotify) g_free,
		(GDestroyNotify) g_free);

	/* Iterate over the base CamelProvider directories. */
	while ((basename = g_dir_read_name (dir)) != NULL) {
		gchar *provider_src_directory;
		gchar *provider_dst_directory;

		provider_src_directory =
			g_build_filename (src_directory, basename, NULL);
		provider_dst_directory =
			g_build_filename (dst_directory, basename, NULL);

		if (!g_file_test (provider_src_directory, G_FILE_TEST_IS_DIR)) {
			g_free (provider_src_directory);
			g_free (provider_dst_directory);
			continue;
		}

		shell_xdg_migrate_move_contents (
			provider_src_directory, provider_dst_directory);

		g_hash_table_insert (corrections, provider_src_directory, NULL);
		g_free (provider_dst_directory);
	}

	g_dir_close (dir);

	/* Remove the old base CamelProvider directories. */
	shell_xdg_migrate_process_corrections (corrections);
	g_hash_table_destroy (corrections);

skip_mail:

	g_free (src_directory);
	g_free (dst_directory);

	/* We don't want to move the source directory directly because the
	 * destination directory may already exist with content.  Instead
	 * we want to merge the content of the source directory into the
	 * destination directory.
	 *
	 * For example, given:
	 *
	 *    $(src_directory)/A   and   $(dst_directory)/B
	 *    $(src_directory)/C
	 *
	 * we want to end up with:
	 *
	 *    $(dst_directory)/A
	 *    $(dst_directory)/B
	 *    $(dst_directory)/C
	 *
	 * Any name collisions will be left in the source directory.
	 */

	src_directory = g_build_filename (old_data_dir, "signatures", NULL);
	dst_directory = g_build_filename (new_data_dir, "signatures", NULL);

	shell_xdg_migrate_move_contents (src_directory, dst_directory);
	shell_xdg_migrate_rmdir (src_directory);

	g_free (src_directory);
	g_free (dst_directory);

	/* Move all remaining regular files to the new data directory. */

	dir = g_dir_open (old_data_dir, 0, NULL);
	if (dir == NULL)
		return;

	/* This is to avoid renaming files while we're iterating over the
	 * directory.  POSIX says the outcome of that is unspecified. */
	corrections = g_hash_table_new_full (
		g_str_hash, g_str_equal,
		(GDestroyNotify) g_free,
		(GDestroyNotify) g_free);

	while ((basename = g_dir_read_name (dir)) != NULL) {
		gchar *old_filename;
		gchar *new_filename;

		old_filename = g_build_filename (old_data_dir, basename, NULL);
		new_filename = g_build_filename (new_data_dir, basename, NULL);

		/* If we encounter a directory, try removing it.  This
		 * will only work if the directory is empty, so there's
		 * no risk of data loss. */
		if (g_file_test (old_filename, G_FILE_TEST_IS_DIR)) {
			shell_xdg_migrate_rmdir (old_filename);
			g_free (old_filename);
			g_free (new_filename);
			continue;
		}

		g_hash_table_insert (corrections, old_filename, new_filename);
	}

	g_dir_close (dir);

	shell_xdg_migrate_process_corrections (corrections);
	g_hash_table_destroy (corrections);
}
Esempio n. 10
0
static gboolean
shell_xdg_migrate_rename_files (const gchar *src_directory,
                                const gchar *dst_directory)
{
	GDir *dir;
	GHashTable *corrections;
	const gchar *basename;
	const gchar *home_dir;
	gchar *old_base_dir;
	gchar *new_base_dir;

	dir = g_dir_open (src_directory, 0, NULL);
	if (dir == NULL)
		return FALSE;

	/* This is to avoid renaming files which we're iterating over the
	 * directory.  POSIX says the outcome of that is unspecified. */
	corrections = g_hash_table_new_full (
		g_str_hash, g_str_equal,
		(GDestroyNotify) g_free,
		(GDestroyNotify) g_free);

	g_mkdir_with_parents (dst_directory, 0700);

	home_dir = g_get_home_dir ();
	old_base_dir = g_build_filename (home_dir, ".evolution", NULL);
	e_filename_make_safe (old_base_dir);
	new_base_dir = g_strdup (e_get_user_data_dir ());
	e_filename_make_safe (new_base_dir);

	while ((basename = g_dir_read_name (dir)) != NULL) {
		GString *buffer;
		gchar *old_filename;
		gchar *new_filename;
		gchar *cp;

		buffer = g_string_new (basename);

		if ((cp = strstr (basename, old_base_dir)) != NULL) {
			g_string_erase (
				buffer, cp - basename,
				strlen (old_base_dir));
			g_string_insert (
				buffer, cp - basename, new_base_dir);
		}

		old_filename = g_build_filename (
			src_directory, basename, NULL);
		new_filename = g_build_filename (
			dst_directory, buffer->str, NULL);

		g_string_free (buffer, TRUE);

		g_hash_table_insert (corrections, old_filename, new_filename);
	}

	g_free (old_base_dir);
	g_free (new_base_dir);

	g_dir_close (dir);

	shell_xdg_migrate_process_corrections (corrections);
	g_hash_table_destroy (corrections);

	/* It's tempting to want to remove the source directory here.
	 * Don't.  We might be iterating over the source directory's
	 * parent directory, and removing the source directory would
	 * screw up the iteration. */

	return TRUE;
}
Esempio n. 11
0
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 ();
	}
}
Esempio n. 12
0
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 ();
	}

}
static void
migrate_to_user_data_dir (const gchar *old_base_dir)
{
	const gchar *new_data_dir;
	gchar *src_directory;
	gchar *dst_directory;

	new_data_dir = e_get_user_data_dir ();

	g_print ("Migrating local backend data\n");

	/* We don't want to move the source directory directly because the
	 * destination directory may already exist with content.  Instead
	 * we want to merge the content of the source directory into the
	 * destination directory.
	 *
	 * For example, given:
	 *
	 *    $(src_directory)/A   and   $(dst_directory)/B
	 *    $(src_directory)/C
	 *
	 * we want to end up with:
	 *
	 *    $(dst_directory)/A
	 *    $(dst_directory)/B
	 *    $(dst_directory)/C
	 *
	 * Any name collisions will be left in the source directory.
	 */

	src_directory = g_build_filename (old_base_dir, "calendar", "local", NULL);
	dst_directory = g_build_filename (new_data_dir, "calendar", NULL);

	migrate_move_contents (src_directory, dst_directory);
	migrate_rmdir (src_directory);

	g_free (src_directory);
	g_free (dst_directory);

	src_directory = g_build_filename (old_base_dir, "memos", "local", NULL);
	dst_directory = g_build_filename (new_data_dir, "memos", NULL);

	migrate_move_contents (src_directory, dst_directory);
	migrate_rmdir (src_directory);

	g_free (src_directory);
	g_free (dst_directory);

	src_directory = g_build_filename (old_base_dir, "tasks", "local", NULL);
	dst_directory = g_build_filename (new_data_dir, "tasks", NULL);

	migrate_move_contents (src_directory, dst_directory);
	migrate_rmdir (src_directory);

	g_free (src_directory);
	g_free (dst_directory);

	/* XXX This is not really the right place to be migrating
	 *     exchange data, but since we already cleaned out the
	 *     cached attachment files from this directory, may as
	 *     well move the user accounts too while we're at it. */

	src_directory = g_build_filename (old_base_dir, "exchange", NULL);
	dst_directory = g_build_filename (new_data_dir, "exchange", NULL);

	migrate_move_contents (src_directory, dst_directory);
	migrate_rmdir (src_directory);

	g_free (src_directory);
	g_free (dst_directory);
}
Esempio n. 14
0
static gchar *
get_filename (void)
{
	return g_build_filename (e_get_user_data_dir (), "faces", NULL);
}
enum OpenAB_Storage::Storage::eInit EDSCalendarStorage::init()
{
  LOG_FUNC() << "DB: " << database<<std::endl;

  GError *gerror = NULL;

  // 1. Get access to all databases in EDS.
  registry = e_source_registry_new_sync(NULL, &gerror);
  if (!registry)
  {
    LOG_ERROR() << "e_source_registry not found " << GERROR_MESSAGE(gerror)<<std::endl;
    GERROR_FREE(gerror);
    return eInitFail;
  }

  // 2. Look up one particular database.
  // special use case - "system" db - use system storage
  std::string dbName = database;
  if (dbName == "system")
  {
    if (OpenAB::eEvent == getItemType())
    {
      source = e_source_registry_ref_default_calendar(registry);
    }
    else if (OpenAB::eTask == getItemType())
    {
      source = e_source_registry_ref_default_task_list(registry);
    }
  }
  else
  {
    source = e_source_registry_ref_source(registry, dbName.c_str());
  }

  if (!source)
  {
    LOG_ERROR() << "e_source not found"<<std::endl;
    GERROR_FREE(gerror);
    return eInitFail;
  }

  GERROR_FREE(gerror);

  const gchar *userDataDir = NULL;
  userDataDir = e_get_user_data_dir();
  gchar* dirname = NULL;

  if (OpenAB::eEvent == getItemType())
  {
    client = (ECalClient *) e_cal_client_connect_sync(source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL, &gerror);
    dirname = g_build_filename(userDataDir, "calendar", dbName.c_str(), "calendar.ics", NULL);

  }
  else
  {
    client = (ECalClient *) e_cal_client_connect_sync(source, E_CAL_CLIENT_SOURCE_TYPE_TASKS, NULL, &gerror);
    dirname = g_build_filename(userDataDir, "tasks", dbName.c_str(), "tasks.ics", NULL);
  }

  databaseFileName = dirname;
  g_free(dirname);

  if (gerror)
  {
    LOG_ERROR() << "Error e_cal_client_connect_sync results: " << GERROR_MESSAGE(gerror)<<std::endl;
    GERROR_FREE(gerror);
    return eInitFail;
  }
  LOG_VERBOSE() << "e_cal_client_connect_sync\n"<<std::endl;

  return eInitOk;
}
Esempio n. 16
0
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 ();
	}

}
Esempio n. 17
0
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 ();
	}
}
Esempio n. 18
0
static gchar *
key_file_get_filename (void)
{
	return g_build_filename (e_get_user_data_dir (), "printing.ini", NULL);
}