コード例 #1
0
ファイル: mount_mtfs.c プロジェクト: ddn-lixi/mtfs
char *reslove_source_path(const char *origin_source)
{
	int ret = 0;
	struct mount_option *mount_option = NULL;
	mtfs_bindex_t bindex = 0;
	char *path = NULL;
	char *source = NULL;
	char rpath[PATH_MAX] = {'\0'};
	int source_len = 0;

	mount_option = calloc(1, sizeof(*mount_option));
	if (mount_option == NULL) {
		goto out;
	}

	source = strdup(origin_source);
	ret = parse_dir_option(source, mount_option);
	free(source);
	if (ret) {
		source = NULL;
		goto out_free;
	}

	/* TODO: BUG if longer than a page? */
	source_len = mount_option->bnum * (PATH_MAX + 1);
	if (source_len > 4095) {
		source_len = 4095;
	}
	source = calloc(source_len, 1);
	if (source == NULL) {
		goto finit_option;
	}

	for (bindex = 0; bindex < mount_option->bnum; bindex++) {
		path = mount_option->branch[bindex].path;
		if (realpath(path, rpath) == NULL) {
			fprintf(stderr, "Failed to get realpath for '%s' at branch[%d]: %s\n",
			        path, bindex, strerror(errno));
			free(source);
			source = NULL;
			goto finit_option;
		}
		append_dir(source, rpath);
		if (verbose) {
			printf("branch[%d] = %s\n", bindex, rpath);
		}
	}
finit_option:
	mount_option_fini(mount_option);
out_free:
	free(mount_option);
out:
	return source;
}
コード例 #2
0
static gboolean
append_dir(GtkTreeStore* store, GtkTreeIter* parent_iter,
	GFile* dir, const char* encoding)
{
    GtkTreeIter iter;
    GFileInfo* info;
    GFileEnumerator* e;
    gboolean success_all = TRUE;

    e = g_file_enumerate_children(dir,
	    G_FILE_ATTRIBUTE_STANDARD_NAME ","
	    G_FILE_ATTRIBUTE_STANDARD_TYPE,
	    G_FILE_QUERY_INFO_NONE, NULL, NULL);
    if (e == NULL)
	return success_all;

    info = g_file_enumerator_next_file(e, NULL, NULL);
    while (info != NULL) {
	const char* name = g_file_info_get_name(info);
	char* display_name = get_display_name(name);
	char* new_name = get_new_name(name, encoding);
	GFileType ftype;

	file_list_model_append(store, &iter, parent_iter,
		NULL, name, display_name, new_name);

	if (new_name == NULL)
	    success_all = FALSE;

	ftype = g_file_info_get_file_type(info);
	if (ftype == G_FILE_TYPE_DIRECTORY) {
	    gboolean res;
	    GFile* child = g_file_get_child(dir, name);
	    res = append_dir(store, &iter, child, encoding);
	    g_object_unref(child);
	    if (!res)
		success_all = FALSE;
	}

	g_object_unref(info);
	g_free(display_name);
	g_free(new_name);
	
	info = g_file_enumerator_next_file(e, NULL, NULL);
    }
    g_object_unref(e);

    return success_all;
}
コード例 #3
0
static void
repair_dialog_update_file_list_model(GtkDialog* dialog, gboolean async)
{
    GtkTreeStore* store;
    GtkTreeView* treeview;
    GSList* files;
    gboolean include_subdir;
    GtkComboBox* combobox;
    UpdateContext* context;
    gboolean success_all = TRUE;

    store = repair_dialog_get_file_list_model(dialog);
    files = repair_dialog_get_file_list(dialog);
    treeview = repair_dialog_get_file_list_view(dialog);
    include_subdir = repair_dialog_get_include_subdir_flag(dialog);

    combobox = repair_dialog_get_encoding_combo_box(dialog);
    gtk_widget_set_sensitive(GTK_WIDGET(combobox), FALSE);

    gtk_tree_store_clear(store);

    if (async) {
	context = repair_dialog_get_update_context(dialog);
	if (context != NULL) {
	    g_idle_remove_by_data(dialog);
	    update_context_free(context);
	}

	context = update_context_new();
	context->dialog = dialog;
	context->treeview = treeview;
	context->store = store;
	context->file_stack = g_slist_copy(files);
	context->encoding = repair_dialog_get_current_encoding(dialog);
	context->include_subdir = include_subdir;

	g_slist_foreach(context->file_stack, (GFunc)g_object_ref, NULL);

	repair_dialog_set_update_context(dialog, context);

	g_idle_add((GSourceFunc)repair_dialog_on_idle_update, dialog);
    } else {
	char* encoding = repair_dialog_get_current_encoding(dialog);

	while (files != NULL) {
	    GtkTreeIter iter;
	    char* name;
	    char* display_name;
	    char* new_name;
	    GFile* file;

	    file = files->data;
	    name = g_file_get_basename(file);
	    display_name = get_display_name(name);
	    new_name = get_new_name(name, encoding);

	    file_list_model_append(store, &iter, NULL,
		    file, name, display_name, new_name);
	    if (new_name == NULL)
		success_all = FALSE;
	    
	    if (include_subdir) {
		GFileType file_type;
		file_type = g_file_query_file_type(file,
			G_FILE_QUERY_INFO_NONE, NULL);
		if (file_type == G_FILE_TYPE_DIRECTORY) {
		    gboolean res;
		    res = append_dir(store, &iter, file, encoding);
		    if (!res)
			success_all = FALSE;
		}
	    }

	    g_free(name);
	    g_free(display_name);
	    g_free(new_name);

	    files = g_slist_next(files);
	}

	gtk_tree_view_expand_all(treeview);
	g_free(encoding);

	repair_dialog_on_update_end(dialog, success_all);
    }
}