Exemple #1
0
MuContacts*
mu_contacts_new (const gchar *path)
{
	MuContacts *self;

	g_return_val_if_fail (path, NULL);
	self = g_new0 (MuContacts, 1);

	self->_path = g_strdup (path);
	self->_hash = g_hash_table_new_full
		(g_str_hash, g_str_equal, g_free,
		 (GDestroyNotify)contact_info_destroy);

	self->_ccache  = load_key_file (path);
	if (!self->_ccache || !set_comment (self->_ccache)) {
		mu_contacts_destroy (self);
		return NULL;
	}
	deserialize_cache (self);
	MU_WRITE_LOG("deserialized contacts from cache %s",
		     path);

	self->_dirty = FALSE;
	return self;
}
Exemple #2
0
gboolean
mu_log_init (const char* logfile, MuLogOptions opts)
{
	int fd;

	/* only init once... */
	g_return_val_if_fail (!MU_LOG, FALSE);
	g_return_val_if_fail (logfile, FALSE);

	if (opts & MU_LOG_OPTIONS_BACKUP)
		if (!log_file_backup_maybe(logfile)) {
			g_warning ("failed to backup log file");
			return FALSE;
		}

	fd = open (logfile, O_WRONLY|O_CREAT|O_APPEND, 00600);
	if (fd < 0) {
		g_warning ("%s: open() of '%s' failed: %s",  __FUNCTION__,
			   logfile, strerror(errno));
		return FALSE;
	}

	MU_LOG = g_new0 (MuLog, 1);
	MU_LOG->_fd = fd;

	mu_log_options_set (opts);

	MU_LOG->_old_log_func =
		g_log_set_default_handler ((GLogFunc)log_handler, NULL);

	MU_WRITE_LOG ("logging started");

	return TRUE;
}
Exemple #3
0
void
mu_log_uninit (void)
{
	if (!MU_LOG)
		return;

	MU_WRITE_LOG ("logging stopped");

	try_close (MU_LOG->_fd);
	g_free (MU_LOG);

	MU_LOG = NULL;
}
Exemple #4
0
gchar*
mu_util_guess_mu_homedir (void)
{
	const char* home;

	/* g_get_home_dir use /etc/passwd, not $HOME; this is better,
	 * as HOME may be wrong when using 'sudo' etc.*/
	home = g_get_home_dir ();

	if (!home)
		MU_WRITE_LOG ("failed to determine homedir");

	return g_strdup_printf ("%s%c%s", home ? home : ".", G_DIR_SEPARATOR,
				".mu");
}
Exemple #5
0
MuError
mu_cmd_add (MuStore *store, MuConfig *opts, GError **err)
{
	gboolean allok;
	int i;

	g_return_val_if_fail (store, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_ADD,
			      MU_ERROR_INTERNAL);

	/* note: params[0] will be 'add' */
	if (!opts->params[0] || !opts->params[1]) {
		g_message ("usage: mu add <file> [<files>]");
		g_set_error (err, 0, MU_ERROR_IN_PARAMETERS,
			     "missing source and/or target");
		return MU_ERROR_IN_PARAMETERS;
	}

	for (i = 1, allok = TRUE; opts->params[i]; ++i) {

		const char* src;
		src = opts->params[i];

		if (!check_file_okay (src, TRUE) ||
		    mu_store_add_path (store, src, NULL, err) ==
		    MU_STORE_INVALID_DOCID) {
			MU_WRITE_LOG ("failed to add %s", src);
			allok = FALSE;
		}
	}

	if (!allok) {
		g_set_error (err, 0, MU_ERROR_XAPIAN_STORE_FAILED,
			     "store failed for some message(s)");
		return MU_ERROR_XAPIAN_STORE_FAILED;
	}

	return MU_OK;
}
Exemple #6
0
void
mu_contacts_destroy (MuContacts *self)
{
	if (!self)
		return;

	if (self->_ccache && self->_dirty) {
		serialize_cache (self);
		MU_WRITE_LOG("serialized contacts cache %s",
			     self->_path);
	}

	if (self->_ccache)
		g_key_file_free (self->_ccache);

	g_free (self->_path);

	if (self->_hash)
		g_hash_table_destroy (self->_hash);

	g_free (self);
}
Exemple #7
0
MuError
mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err)
{
	gboolean allok;
	int i;

	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_REMOVE,
			      MU_ERROR_INTERNAL);

	/* note: params[0] will be 'add' */
	if (!opts->params[0] || !opts->params[1]) {
		g_warning ("usage: mu remove <file> [<files>]");
		g_set_error (err, 0, MU_ERROR_IN_PARAMETERS,
				     "missing source and/or target");
		return MU_ERROR_IN_PARAMETERS;
	}

	for (i = 1, allok = TRUE; opts->params[i]; ++i) {

		const char* src;
		src = opts->params[i];

		if (!check_file_okay (src, FALSE) ||
		    !mu_store_remove_path (store, src)) {
			allok = FALSE;
			MU_WRITE_LOG ("failed to remove %s", src);
		}
	}

	if (!allok) {
		g_set_error (err, 0, MU_ERROR_XAPIAN_STORE_FAILED,
			     "remove failed for some message(s)");
		return MU_ERROR_XAPIAN_REMOVE_FAILED;
	}

	return MU_OK;
}
Exemple #8
0
static MuError
on_run_maildir_dir (const char* fullpath, gboolean enter,
		    MuIndexCallbackData *data)
{
	GError *err;
	err = NULL;

	/* xapian stores a per-dir timestamp; we use this timestamp
	 *  to determine whether a message is up-to-data
	 */
	if (enter) {
		data->_dirstamp =
			mu_store_get_timestamp (data->_store, fullpath, &err);
		g_debug ("entering %s (ts==%u)",
			 fullpath, (unsigned)data->_dirstamp);
	} else {
		time_t now;
		now = time (NULL);

		mu_store_set_timestamp (data->_store, fullpath,
					now, &err);
		g_debug ("leaving %s (ts=%u)",
			 fullpath, (unsigned)data->_dirstamp);
	}

	if (data->_idx_dir_cb)
		return data->_idx_dir_cb (fullpath, enter,
					  data->_user_data);

	if (err) {
		MU_WRITE_LOG ("%s: %s", __FUNCTION__, err->message);
		g_clear_error(&err);
	}

	return MU_OK;
}