Exemplo n.º 1
0
bool folder_select(char* setting, int setting_len)
{
    struct folder *root;
    struct simplelist_info info;
    size_t buf_size;
    /* 32 separate folders should be Enough For Everybody(TM) */
    char *vect[32];
    char copy[setting_len];
    int nb_items;

    /* copy onto stack as split_string() modifies it */
    strlcpy(copy, setting, setting_len);
    nb_items = split_string(copy, ':', vect, ARRAYLEN(vect));

    buffer_front = plugin_get_buffer(&buf_size);
    buffer_end = buffer_front + buf_size;
    root = load_root();

    if (nb_items > 0)
    {
        for(int i = 0; i < nb_items; i++)
            select_paths(root, vect[i]);
    }

    simplelist_info_init(&info, str(LANG_SELECT_FOLDER),
            count_items(root), root);
    info.get_name = folder_get_name;
    info.action_callback = folder_action_callback;
    info.get_icon = folder_get_icon;
    simplelist_show_list(&info);

    /* done editing. check for changes */
    save_folders(root, copy, setting_len);
    if (strcmp(copy, setting))
    {   /* prompt for saving changes and commit if yes */
        if (yesno_pop(ID2P(LANG_SAVE_CHANGES)))
        {
            strcpy(setting, copy);
            settings_save();
            return true;
        }
    }
    return false;
}
Exemplo n.º 2
0
static char *file_chunkdb_ctor(const char *spec, struct chunk_db *chunk_db)
{
	const char *path = spec;
	struct db *db = chunk_db->db_info;
	struct stat st;
	int error;

	db->ro = (chunk_db->mode == CHUNKDB_RO);

	db->fd = open(path, db->ro ? O_RDONLY : O_RDWR|O_CREAT, 0644);
	if (db->fd < 0)
		return sprintf_new("Can't open %s: %s.", path, strerror(errno));

	if (fstat(db->fd, &st))
		goto set_error;

	error = -EINVAL;
	if (!S_ISREG(st.st_mode))
		goto error;

	db->next_nr = st.st_size / CHUNK_SIZE;

	error = load_root(db);
	if (error)
		goto error;

	/*
	 * Tell the OS that it doesn't eed to do read-ahead on this file.
	 */
	posix_fadvise(db->fd, 0, 0, POSIX_FADV_RANDOM);

	return NULL;
set_error:
	error = -errno;
error:
	close(db->fd);
	return sprintf_new("Error loading database file %s: %s.", path,
			strerror(-error));
}