Ejemplo n.º 1
0
static void
mp_save_uids(GHashTable *old_uids, GHashTable *new_uids, const char *prefix)
{
    gchar *fname = g_strconcat(g_get_home_dir(), "/.balsa/pop-uids", NULL);
    FILE *f;

    libbalsa_assure_balsa_dir();
    f = fopen(fname, "w");
    g_free(fname);
    if(f) {
        struct save_uid_data data;
        struct flock lck;

        memset (&lck, 0, sizeof (struct flock));
        lck.l_type = F_WRLCK; lck.l_whence = SEEK_SET;
        data.file = f; data.exclude_prefix = prefix;
        g_hash_table_foreach(old_uids, mp_save_uid, &data);
        data.exclude_prefix = NULL;
        g_hash_table_foreach(new_uids, mp_save_uid, &data);
        lck.l_type = F_UNLCK;
        fcntl(fileno(f), F_SETLK, &lck);
        fclose(f);
    } /* else COULD NOT SAVE UIDS! SHOUT! */
    return;
}
Ejemplo n.º 2
0
static void
lbc_init(LibBalsaConf * conf, const gchar * filename,
         const gchar * old_dir)
{
    struct stat buf;
    GError *error = NULL;
    gint rc;

    if (!conf->path)
        conf->path =
            g_build_filename(g_get_home_dir(), ".balsa", filename, NULL);
    rc = stat(conf->path, &buf);
    if (conf->key_file) {
        if (rc >= 0 && buf.st_mtime <= conf->mtime)
            /* found the config file, and it hasn't been touched since
             * we loaded it */
            return;
    } else {
        conf->key_file = g_key_file_new();
        if (rc < 0)
            /* no config file--must be first time startup */
            return;
    }
    conf->mtime = buf.st_mtime;

    libbalsa_assure_balsa_dir();
    if (!g_key_file_load_from_file
        (conf->key_file, conf->path, G_KEY_FILE_NONE, &error)) {
        gchar *old_path;
        gchar *buf;
        static gboolean warn = TRUE;

        old_path =
            g_build_filename(g_get_home_dir(), old_dir, "balsa", NULL);
#if DEBUG
        g_message("Could not load config from \"%s\":\n %s\n"
                  " trying \"%s\"", conf->path, error->message, old_path);
#endif                          /* DEBUG */
        g_clear_error(&error);

        buf = lbc_readfile(old_path);
        if (buf) {
            /* GnomeConfig used ' ' as the list separator... */
            g_key_file_set_list_separator(conf->key_file, ' ');
            g_key_file_load_from_data(conf->key_file, buf, -1,
                                      G_KEY_FILE_KEEP_COMMENTS, &error);
            g_free(buf);
            /* ...but GKeyFile doesn't handle it properly, so we'll
             * revert to the default ';'. */
            g_key_file_set_list_separator(conf->key_file, ';');
        }
        if (!buf || error) {
#if DEBUG
            g_message("Could not load key file from file \"%s\": %s",
                      old_path,
                      error ? error->message : g_strerror(errno));
#endif                          /* DEBUG */
            g_clear_error(&error);
            warn = FALSE;
        }
        g_free(old_path);
        if (warn)
            libbalsa_information(LIBBALSA_INFORMATION_WARNING,
                                 _("Your Balsa configuration "
                                   "is now stored in "
                                   "\"~/.balsa/config\"."));
    }
}