コード例 #1
0
ファイル: gfrep.c プロジェクト: ddk50/gfarm_v2
static gfarm_error_t
gfarm_hash_to_string_array(struct gfarm_hash_table *hash,
	int *array_lengthp, char ***arrayp)
{
	struct gfarm_hash_iterator iter;
	struct gfarm_hash_entry *entry;
	gfarm_stringlist ls;
	char *ent, **array;
	gfarm_error_t e;

	e = gfarm_stringlist_init(&ls);
	if (e != GFARM_ERR_NO_ERROR)
		return (e);

	for (gfarm_hash_iterator_begin(hash, &iter);
	     !gfarm_hash_iterator_is_end(&iter);
	     gfarm_hash_iterator_next(&iter)) {
		entry = gfarm_hash_iterator_access(&iter);
		if (entry != NULL) {
			ent = strdup(gfarm_hash_entry_key(entry));
			if (ent == NULL)
				e = GFARM_ERR_NO_MEMORY;
			else
				e = gfarm_stringlist_add(&ls, ent);
		}
		if (e != GFARM_ERR_NO_ERROR)
			goto stringlist_free;
	}
	array = gfarm_strings_alloc_from_stringlist(&ls);
	if (array == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		goto stringlist_free;
	}
	*array_lengthp = gfarm_stringlist_length(&ls);
	*arrayp = array;
 stringlist_free:
	if (e == GFARM_ERR_NO_ERROR)
		gfarm_stringlist_free(&ls);
	else
		gfarm_stringlist_free_deeply(&ls);
	return (e);
}
コード例 #2
0
ファイル: gfwhere.c プロジェクト: krichter722/gfarm
int
main(int argc, char **argv)
{
	int argc_save = argc;
	char **argv_save = argv;
	gfarm_error_t e, e_save = GFARM_ERR_NO_ERROR;
	int i, n, ch, opt_recursive = 0;
	gfarm_stringlist paths;
	gfs_glob_t types;

	if (argc >= 1)
		program_name = basename(argv[0]);

	while ((ch = getopt(argc, argv, "rR?")) != -1) {
		switch (ch) {
		case 'r':
		case 'R':
			opt_recursive = 1;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	e = gfarm_initialize(&argc_save, &argv_save);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(1);
	}
	if (argc == 0) {
		usage();
	}

	e = gfarm_stringlist_init(&paths);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}
	e = gfs_glob_init(&types);
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < argc; i++)
		gfs_glob(argv[i], &paths, &types);
	gfs_glob_free(&types);

	n = gfarm_stringlist_length(&paths);
	for (i = 0; i < n; i++) {
		char *p = gfarm_stringlist_elem(&paths, i);
		struct gfs_stat st;

		if ((e = gfs_stat(p, &st)) != GFARM_ERR_NO_ERROR) {
			fprintf(stderr, "%s: %s\n", p, gfarm_error_string(e));
		} else {
			if (GFARM_S_ISREG(st.st_mode)) 
				e = display_replica_catalog(p, &st, NULL);
			else if (opt_recursive)
				e = gfarm_foreach_directory_hierarchy(
					display_replica_catalog, display_name,
					NULL, p, NULL);
			else
				fprintf(stderr, "%s: not a file\n", p);
			gfs_stat_free(&st);
			if (e_save == GFARM_ERR_NO_ERROR)
				e_save = e;
		}
	}

	gfarm_stringlist_free_deeply(&paths);
	e = gfarm_terminate();
	if (e != GFARM_ERR_NO_ERROR) {
		fprintf(stderr, "%s: %s\n", program_name,
		    gfarm_error_string(e));
		exit(1);
	}
	return (e_save == GFARM_ERR_NO_ERROR ? 0 : 1);
}
コード例 #3
0
ファイル: gfrep.c プロジェクト: ddk50/gfarm_v2
int
main(int argc, char *argv[])
{
	char *src_hostfile = NULL, *dst_hostfile = NULL;
	gfarm_stringlist paths;
	gfs_glob_t types;
	int mode_src_ch = 0, mode_dst_ch = 0, parallel = -1;
	int i, ch;
	gfarm_error_t e;
	const char *errmsg, *errmsg2 = NULL;
	struct gfrep_arg gfrep_arg;
	struct flist flist;

	if (argc >= 1)
		program_name = basename(argv[0]);
	memset(&gfrep_arg, 0, sizeof(gfrep_arg));
	memset(&flist, 0, sizeof(flist));
	flist.src_domain = "";
	flist.dst_domain = "";

	e = gfarm_initialize(&argc, &argv);
	error_check(e);

#ifdef _OPENMP
	while ((ch = getopt(argc, argv, "h:j:mnqvxS:D:H:N:?")) != -1) {
#else
	while ((ch = getopt(argc, argv, "h:mnqvxS:D:H:N:?")) != -1) {
#endif
		switch (ch) {
		case 'h':
			src_hostfile = optarg;
			conflict_check(&mode_src_ch, ch);
			break;
#ifdef _OPENMP
		case 'j':
			parallel = strtol(optarg, NULL, 0);
			break;
#endif
		case 'm':
			act = &migrate_mode;
			break;
		case 'n':
			opt_noexec = 1;
			break;
		case 'q':
			opt_quiet = 1;
			break;
		case 'v':
			opt_verbose = 1;
			break;
		case 'x':
			opt_remove = 1;
			break;
		case 'S':
			flist.src_domain = optarg;
			conflict_check(&mode_src_ch, ch);
			break;
		case 'D':
			flist.dst_domain = optarg;
			conflict_check(&mode_dst_ch, ch);
			break;
		case 'H':
			dst_hostfile = optarg;
			conflict_check(&mode_dst_ch, ch);
			break;
		case 'N':
			opt_nrep = strtol(optarg, NULL, 0);
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	/* make writing-to-stderr atomic, for GfarmFS-FUSE log output */
	setvbuf(stderr, NULL, _IOLBF, 0);

	if (!opt_quiet) {
		printf("constructing file list...");
		fflush(stdout);
	}

	e = gfarm_stringlist_init(&paths);
	if (e == GFARM_ERR_NO_ERROR) {
		e = gfs_glob_init(&types);
		if (e == GFARM_ERR_NO_ERROR) {
			for (i = 0; i < argc; i++)
				gfs_glob(argv[i], &paths, &types);
			gfs_glob_free(&types);
		}
	}
	error_check(e);

	e = gfarm_list_init(&flist.slist);
	error_check(e);
	e = gfarm_list_init(&flist.dlist);
	error_check(e);
	flist.srchash = gfarm_hash_table_alloc(HOSTHASH_SIZE,
		gfarm_hash_casefold, gfarm_hash_key_equal_casefold);
	if (flist.srchash == NULL)
		error_check(GFARM_ERR_NO_MEMORY);

	e = create_hosthash_from_file(src_hostfile,
		HOSTHASH_SIZE, &flist.src_hosthash);
	error_check(e);
	e = create_hosthash_from_file(dst_hostfile,
		HOSTHASH_SIZE, &flist.dst_hosthash);
	error_check(e);

	for (i = 0; i < gfarm_stringlist_length(&paths); i++) {
		char *file = gfarm_stringlist_elem(&paths, i), *realpath = NULL;

		e = gfarm_realpath_by_gfarm2fs(file, &realpath);
		if (e == GFARM_ERR_NO_ERROR)
			file = realpath;
		e = gfarm_foreach_directory_hierarchy(
			create_filelist, NULL, NULL, file, &flist);
		free(realpath);
		if (e != GFARM_ERR_NO_ERROR)
			break;
	}
	gfarm_stringlist_free_deeply(&paths);
	error_check(e);

	if (!opt_quiet)
		printf(" done\n");
	if (opt_verbose) {
		printf("files to be replicated\n");
		print_file_list(&flist.slist);
	}
	if (opt_verbose && opt_remove) {
		printf("files having too many replicas\n");
		print_file_list(&flist.dlist);
	}
	if (gfarm_list_length(&flist.slist) <= 0
	    && (!opt_remove || gfarm_list_length(&flist.dlist) <= 0))
		exit(0); /* no file */

	/* replicate files */
	e = gfarm_hash_to_string_array(
		flist.srchash, &gfrep_arg.nsrc, &gfrep_arg.src);
	error_check(e);
	gfarm_hash_table_free(flist.srchash);

	if (!opt_quiet) {
		printf("investigating hosts...");
		fflush(stdout);
	}
	e = create_hostlist_by_domain_and_hash(
		gfarm_list_length(&flist.slist) > 0 ?
		gfarm_list_elem(&flist.slist, 0) :
		gfarm_list_elem(&flist.dlist, 0),
		flist.dst_domain, flist.dst_hosthash,
		&gfrep_arg.ndst, &gfrep_arg.dst, &gfrep_arg.dst_port);
	error_check(e);
	if (!opt_quiet)
		printf(" done\n");

	errmsg = pfor_list(act, &flist.slist, parallel, &gfrep_arg);
	gfarm_list_free(&flist.slist);

	/* remove file replicas */
	if (opt_remove)
		errmsg2 = pfor_list(
			&remove_mode, &flist.dlist, parallel, &gfrep_arg);
	gfarm_list_free(&flist.dlist);
	if (errmsg == NULL)
		errmsg = errmsg2;
	if (errmsg != NULL)
		fprintf(stderr, "%s\n", errmsg), exit(EXIT_FAILURE);

	gfarm_strings_free_deeply(gfrep_arg.nsrc, gfrep_arg.src);
	gfarm_strings_free_deeply(gfrep_arg.ndst, gfrep_arg.dst);
	free(gfrep_arg.dst_port);
	e = gfarm_terminate();
	error_check(e);

	return (0);
}
コード例 #4
0
ファイル: import_help.c プロジェクト: krichter722/gfarm
char *
gfarm_hostlist_read(char *filename,
	int *np, char ***host_table_p, int *error_linep)
{
	gfarm_stringlist host_list;
	FILE *fp;
	int i;
	char *e, line[1024];

	*error_linep = -1;
	e = gfarm_stringlist_init(&host_list);
	if (e != NULL)
		return (e);
	if (strcmp(filename, "-") == 0) {
		fp = stdin;
	} else if ((fp = fopen(filename, "r")) == NULL) {
		gfarm_stringlist_free(&host_list);
		return (GFARM_ERR_NO_SUCH_OBJECT);
	}
	for (i = 0; fgets(line, sizeof(line), fp) != NULL; i++) {
		int l = strlen(line);
		char *s, *t, *host;

		if (l > 0 && line[l - 1] == '\n')
			line[--l] = '\0';
		for (s = line; isspace(*s); s++)
			;
		if (*s == '\0') {
			e = "hostname expected";
			*error_linep = i + 1;
			goto error;
		}
		for (t = s; *t != '\0' && !isspace(*t); t++)
			;
		*t = '\0';
		host = strdup(s);
		if (host == NULL) {
			e = GFARM_ERR_NO_MEMORY;
			*error_linep = i + 1;
			goto error;
		}
		e = gfarm_stringlist_add(&host_list, host);
		if (e != NULL) {
			free(host);
			*error_linep = i + 1;
			goto error;
		}
	}
	if (i == 0) {
		e = "empty file";
		goto error;
	}
	*np = gfarm_stringlist_length(&host_list);
	*host_table_p = gfarm_strings_alloc_from_stringlist(&host_list);
	if (e != NULL)
		goto error;
	/*
	 * do not call gfarm_stringlist_free_deeply() here,
	 * because the strings are passed to *host_table.
	 */
	gfarm_stringlist_free(&host_list);
	if (strcmp(filename, "-") != 0)
		fclose(fp);
	return (NULL);

error:
	if (strcmp(filename, "-") != 0)
		fclose(fp);
	gfarm_stringlist_free_deeply(&host_list);
	return (e);
}
コード例 #5
0
ファイル: import_help.c プロジェクト: krichter722/gfarm
char *
gfarm_import_fragment_config_read(char *config,
	int *np, char ***hosttabp, file_offset_t **sizetabp,
	int *error_linep)
{
	char *e, **host_table, line[1024];
	int i, table_size = TABLE_SIZE_INITIAL;
	file_offset_t *size_table = malloc(sizeof(size_table[0]) * table_size);
	file_offset_t *stab;
	gfarm_stringlist host_list;
	FILE *fp;

	*error_linep = -1;
	if (size_table == NULL)
		return (GFARM_ERR_NO_MEMORY);
	e = gfarm_stringlist_init(&host_list);
	if (e != NULL) {
		free(size_table);
		return (e);
	}
	if (strcmp(config, "-") == 0) {
		fp = stdin;
	} else if ((fp = fopen(config, "r")) == NULL) {
		gfarm_stringlist_free(&host_list);
		free(size_table);
		return (GFARM_ERR_NO_SUCH_OBJECT);
	}
	for (i = 0; fgets(line, sizeof(line), fp) != NULL; i++) {
		int l = strlen(line);
		char *s, *t, *host;
		file_offset_t size;

		if (l > 0 && line[l - 1] == '\n')
			line[--l] = '\0';
		size = string_to_file_offset(line, &s);
		if (s == line) {
			e = "fragment size expected";
			*error_linep = i + 1;
			goto error;
		}
		while (isspace(*s))
			s++;
		if (*s == '\0') {
			e = "fragment hostname expected";
			*error_linep = i + 1;
			goto error;
		}
		for (t = s; *t != '\0' && !isspace(*t); t++)
			;
		*t = '\0';
		host = strdup(s);
		if (host == NULL) {
			e = GFARM_ERR_NO_MEMORY;
			*error_linep = i + 1;
			goto error;
		}
		e = gfarm_stringlist_add(&host_list, host);
		if (e != NULL) {
			*error_linep = i + 1;
			goto error;
		}
		if (i >= table_size) {
			table_size += TABLE_SIZE_DELTA;
			stab = realloc(size_table,
			    sizeof(size_table[0]) * table_size);
			if (stab == NULL) {
				e = GFARM_ERR_NO_MEMORY;
				*error_linep = i + 1;
				goto error;
			}
			size_table = stab;
		}
		size_table[i] = size;
	}
	if (i == 0) {
		e = "empty file";
		goto error;
	}
	host_table = gfarm_strings_alloc_from_stringlist(&host_list);
	if (host_table == NULL) {
		e = GFARM_ERR_NO_MEMORY;
		goto error;
	}
	if (i < table_size) {
		stab = realloc(size_table, sizeof(size_table[0]) * i);
		if (stab == NULL) {
			e = GFARM_ERR_NO_MEMORY;
			goto error;
		}
		memcpy(stab, size_table, sizeof(size_table[0]) * i);
		size_table = stab;
	}

	/*
	 * do not call gfarm_stringlist_free_deeply() here,
	 * because the strings are passed to *host_table.
	 */
	gfarm_stringlist_free(&host_list);
	/* no limit on last fragment */
	size_table[i - 1] = FILE_OFFSET_T_MAX;

	*np = i;
	*hosttabp = host_table;
	*sizetabp = size_table;
	if (strcmp(config, "-") != 0)
		fclose(fp);
	return (NULL);

error:
	if (strcmp(config, "-") != 0)
		fclose(fp);
	gfarm_stringlist_free_deeply(&host_list);
	free(size_table);
	return (e);
}
コード例 #6
0
ファイル: gfrm.c プロジェクト: krichter722/gfarm
static void
remove_cwd_entries()
{
	char *e;
	char cwdbf[PATH_MAX * 2];
	int i;
	GFS_Dir dir;
	struct gfs_dirent *entry;
	gfarm_stringlist entry_list;

	e = gfs_getcwd(cwdbf, sizeof(cwdbf));
	if (e != NULL) {
		fprintf(stderr, "%s\n", e);
		return;
	}
	e = gfs_opendir(".", &dir);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", cwdbf, e);
		return;
	}
	e = gfarm_stringlist_init(&entry_list);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", cwdbf, e);
		return;
	}
	while ((e = gfs_readdir(dir, &entry)) == NULL && entry != NULL) {
		char *p;

		if (entry->d_name[0] == '.' && (entry->d_name[1] == '\0' ||
		    (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
			continue; /* "." or ".." */
	 	p = strdup(entry->d_name);
		if (p == NULL) {
			fprintf(stderr, "%s\n", GFARM_ERR_NO_MEMORY);
			exit (1);
		}
		e = gfarm_stringlist_add(&entry_list, p);
		if (e != NULL) {
			fprintf(stderr, "%s/%s: %s\n",
					cwdbf, entry->d_name, e);
		}
	}
	if (e != NULL)
		fprintf(stderr, "%s: %s\n", cwdbf, e);
	gfs_closedir(dir);
	for (i = 0; i < gfarm_stringlist_length(&entry_list); i++) {
		struct gfs_stat gs;
		char *path = gfarm_stringlist_elem(&entry_list, i);

		e = gfs_stat(path, &gs);
		if (e != NULL) {
			fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
			continue;
		}
		if (GFARM_S_ISREG(gs.st_mode)) {
			char *url;

			url = gfarm_url_prefix_add(path);
			if (url == NULL) {
				fprintf(stderr, "%s\n", GFARM_ERR_NO_MEMORY);
				exit (1);
			}
			e = gfs_unlink(url);
			if (e != NULL)
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
			free(url);
		} else if (GFARM_S_ISDIR(gs.st_mode)) {
			e = gfs_chdir(path);
			if (e != NULL) {
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
				continue;
			}
			remove_cwd_entries();
			e = gfs_chdir("..");
			if (e != NULL) {
				fprintf(stderr, "%s: %s\n", cwdbf, e);
				exit (1);
			}
			e = gfs_rmdir(path);
			if (e != NULL)
				fprintf(stderr, "%s/%s: %s\n", cwdbf, path, e);
		}
		gfs_stat_free(&gs);
	}
	gfarm_stringlist_free_deeply(&entry_list);
}
コード例 #7
0
ファイル: gfwhere.c プロジェクト: krichter722/gfarm
int
main(int argc, char **argv)
{
	extern char *optarg;
	extern int optind;
	int argc_save = argc;
	char **argv_save = argv;
	char *e, *section = NULL;
	int i, ch, error = 0;
	gfarm_stringlist paths;
	gfs_glob_t types;
	int argc_expanded;

	if (argc >= 1)
		program_name = basename(argv[0]);

	while ((ch = getopt(argc, argv, "I:")) != -1) {
		switch (ch) {
		case 'I':
			section = optarg;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	e = gfarm_initialize(&argc_save, &argv_save);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(1);
	}
	if (argc == 0) {
		usage();
	}

	e = gfarm_stringlist_init(&paths);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(EXIT_FAILURE);
	}
	e = gfs_glob_init(&types);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < argc; i++)
		gfs_glob(argv[i], &paths, &types);

	argc_expanded = gfarm_stringlist_length(&paths);
	for (i = 0; i < argc_expanded; i++) {
		char *p = gfarm_stringlist_elem(&paths, i);

		if (argc_expanded > 1)
			printf("%s:\n", p);
		if (display_replica_catalog_section(p, section) != NULL)
			error = 1;
		if (argc_expanded > 1 && i < argc_expanded - 1)
			printf("\n");
	}
	gfs_glob_free(&types);
	gfarm_stringlist_free_deeply(&paths);
	e = gfarm_terminate();
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(1);
	}
	return (error);
}
コード例 #8
0
ファイル: gfsck.c プロジェクト: krichter722/gfarm
int
main(int argc, char *argv[])
{
	extern int optind;
	int c, i, error = 0;
	gfarm_stringlist paths;
	gfs_glob_t types;
	char *e;

	if (argc <= 1)
		usage();
	program_name = basename(argv[0]);

	while ((c = getopt(argc, argv, "hv?")) != EOF) {
		switch (c) {
		case 'v':
			option_verbose = 1;
			break;
		case 'h':
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	e = gfarm_initialize(&argc, &argv);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(1);
	}

	e = gfarm_stringlist_init(&paths);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(EXIT_FAILURE);
	}
	e = gfs_glob_init(&types);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(EXIT_FAILURE);
	}
	for (i = 0; i < argc; i++)
		gfs_glob(argv[i], &paths, &types);

	for (i = 0; i < gfarm_stringlist_length(&paths); i++) {
		char *url = gfarm_stringlist_elem(&paths, i);

		e = gfsck_dir("", url);
		if (e != NULL) {
			fprintf(stderr, "%s: %s\n", url, e);
			error = 1;
		}
	}
	gfs_glob_free(&types);
	gfarm_stringlist_free_deeply(&paths);

	e = gfarm_terminate();
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		exit(1);
	}
	exit(error);
}
コード例 #9
0
ファイル: gfexec.c プロジェクト: krichter722/gfarm
static char *
replicate_so_and_symlink(char *dir, size_t size)
{
	char *canonic_path, *gfarm_url, *so_pat, *lpath;
	char *e, *e_save;
	int i, rv;
	gfarm_stringlist paths;
	gfs_glob_t types;
	static char so_pat_template[] = "/*.so*";

	e = gfs_mntpath_canonicalize(dir, size, &canonic_path);
	if (e != NULL)
		return (e);
	e = gfarm_path_canonical_to_url(canonic_path, &gfarm_url);
	free(canonic_path);
	if (e != NULL)
		return (e);

	so_pat = malloc(strlen(gfarm_url) + sizeof(so_pat_template));
	if (so_pat == NULL) {
		free(gfarm_url);
		return (GFARM_ERR_NO_MEMORY);
	}
	sprintf(so_pat, "%s%s", gfarm_url, so_pat_template);
	free(gfarm_url);

	e_save = gfarm_stringlist_init(&paths);
	if (e_save != NULL)
		goto free_so_pat;
	e_save = gfs_glob_init(&types);
	if (e_save != NULL)
		goto free_paths;
	e_save = gfs_glob(so_pat, &paths, &types);
	if (e_save != NULL)
		goto free_types;

	/* XXX - should replicate so files in parallel */
	for (i = 0; i < gfarm_stringlist_length(&paths); i++) {
		char *gfarm_so, *local_so;

		gfarm_so = gfarm_stringlist_elem(&paths, i);
		if (strcmp(gfarm_so, so_pat) == 0) /* no "*.so*" file in dir */
			break;
		e = gfarm_url_execfile_replicate_to_local(gfarm_so, &lpath);
		if (e != NULL) {
			fprintf(stderr, "%s: %s\n", gfarm_so, e);
			if (e_save == NULL)
				e_save = e;
			if (e == GFARM_ERR_NO_MEMORY)
				break;
			continue;
		}

		/* create a symlink */
		e = gfarm_url_localize(gfarm_so, &local_so);
		if (e != NULL) {
			fprintf(stderr, "%s: %s\n", gfarm_so, e);
			if (e_save == NULL)
				e_save = e;
			if (e == GFARM_ERR_NO_MEMORY)
				break;
			free(lpath);
			continue;
		}
		unlink(local_so);
		rv = symlink(lpath, local_so);
		if (rv == -1) {
			perror(local_so);
			if (e_save == NULL)
				e_save = gfarm_errno_to_error(errno);
		}
		free(local_so);
		free(lpath);
	}
free_types:
	gfs_glob_free(&types);
free_paths:
	gfarm_stringlist_free_deeply(&paths);
free_so_pat:
	free(so_pat);
	return (e_save);
}
コード例 #10
0
ファイル: gfls.c プロジェクト: krichter722/gfarm
char *
list_dir(char *prefix, char *dirname, int *need_newline)
{
	char *e, *s, *path, *e_save = NULL;
	gfarm_stringlist names;
	gfs_glob_t types;
	GFS_Dir dir;
	struct gfs_dirent *entry;
	int len = strlen(prefix) + strlen(dirname);

	path = malloc(len + 1 + 1);
	if (path == NULL)
		return (GFARM_ERR_NO_MEMORY);
	sprintf(path, "%s%s", prefix, dirname);
	e = gfarm_stringlist_init(&names);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		free(path);
		return (e);
	}
	e = gfs_glob_init(&types);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", program_name, e);
		gfarm_stringlist_free(&names);
		free(path);
		return (e);
	}
	e = gfs_opendir(path, &dir);
	if (e != NULL) {
		fprintf(stderr, "%s: %s\n", path, e);
		gfs_glob_free(&types);
		gfarm_stringlist_free(&names);
		free(path);
		return (e);
	}
	while ((e = gfs_readdir(dir, &entry)) == NULL && entry != NULL) {
		s = strdup(entry->d_name);
		if (s == NULL) {
			e = GFARM_ERR_NO_MEMORY;
			break;
		}
		gfarm_stringlist_add(&names, s);
		gfs_glob_add(&types, entry->d_type);
	}
	if (e != NULL) {
		fprintf(stderr, "%s%s: %s\n", prefix, dirname, e);
		e_save = e;
	}
	gfs_closedir(dir);
	if (*gfarm_path_dir_skip(gfarm_url_prefix_skip(path)) != '\0') {
		path[len] = '/';
		path[len + 1] = '\0';
	}
	e = list_files(path, gfarm_stringlist_length(&names),
	    GFARM_STRINGLIST_STRARRAY(names), need_newline);
	if (e_save == NULL)
		e_save = e;
	if (option_recursive) {
		int i;

		for (i = 0; i < gfarm_stringlist_length(&names); i++) {
			s = GFARM_STRINGLIST_STRARRAY(names)[i];
			if (s[0] == '.' && (s[1] == '\0' ||
			    (s[1] == '.' && s[2] == '\0')))
				continue;
			if (gfs_glob_elem(&types, i) == GFS_DT_DIR) {
				e = list_dirs(path, 1, &s, need_newline);
				if (e_save == NULL)
					e_save = e;
			}
		}
	}
	gfs_glob_free(&types);
	gfarm_stringlist_free_deeply(&names);
	free(path);
	return (e_save);
}