Exemplo n.º 1
0
int webgfarm_api_v1_read_dir(request_rec *r) {
    char *filepath = webgfarm_api_v1_getfilepath(r);
    if (filepath == NULL || strlen(filepath) == 0) {
        return HTTP_FORBIDDEN;
    }

    gfarm_error_t gerr;
    GFS_DirPlus gfs_dirplus;
    // open dir
    gerr = gfs_opendirplus(filepath, &gfs_dirplus);
    if (gerr != GFARM_ERR_NO_ERROR) {
        switch (gerr) {
            case GFARM_ERR_NO_SUCH_FILE_OR_DIRECTORY:
                return HTTP_NOT_FOUND;
                break;
            case GFARM_ERR_PERMISSION_DENIED:
                return HTTP_FORBIDDEN;
                break;
                //FIXEME: Support more error;
            default:
                return HTTP_INTERNAL_SERVER_ERROR;
        }
    }

    // read dir
    struct gfs_dirent *dent;
    struct gfs_stat *st;

    gerr = gfs_readdirplus(gfs_dirplus, &dent, &st);
    while (dent != NULL) {
        if (gerr != GFARM_ERR_NO_ERROR) {
            gerr = gfs_closedirplus(gfs_dirplus);
            return HTTP_INTERNAL_SERVER_ERROR;
        }
        if (dent->d_type == GFS_DT_REG) {
            ap_rprintf(r, "%s\n", dent->d_name);
        } else if (dent->d_type == GFS_DT_DIR) {
            ap_rprintf(r, "%s/\n", dent->d_name);
        }

        gerr = gfs_readdirplus(gfs_dirplus, &dent, &st);
    }

    // close dir
    gerr = gfs_closedirplus(gfs_dirplus);
    if (gerr != GFARM_ERR_NO_ERROR) {
        return HTTP_INTERNAL_SERVER_ERROR;
    } else {
        return OK;
    }
}
Exemplo n.º 2
0
static gfarm_error_t
gfs_closedir_caching_internal(GFS_Dir super)
{
	struct gfs_dir_caching *dir = (struct gfs_dir_caching *)super;
	gfarm_error_t e = gfs_closedirplus(dir->dp);

	free(dir->path);
	free(dir);
	return (e);
}
Exemplo n.º 3
0
gfarm_error_t
gfs_opendir_caching_internal(const char *path, GFS_Dir *dirp)
{
	gfarm_error_t e;
	GFS_DirPlus dp;
	struct gfs_dir_caching *dir;
	char *p;
	static struct gfs_dir_ops ops = {
		gfs_closedir_caching_internal,
		gfs_readdir_caching_internal,
		gfs_seekdir_unimpl,
		gfs_telldir_unimpl
	};

	if ((e = gfs_opendirplus(path, &dp)) != GFARM_ERR_NO_ERROR)
		return (e);

	GFARM_MALLOC(dir);
	if (*gfarm_path_dir_skip(path) != '\0') {
		GFARM_MALLOC_ARRAY(p, strlen(path) + 1 + 1);
		if (p != NULL)
			sprintf(p, "%s/", path);
	} else {
		GFARM_MALLOC_ARRAY(p, strlen(path) + 1);
		if (p != NULL)
			strcpy(p, path);
	}

	if (dir == NULL || p == NULL) {
		gfs_closedirplus(dp);
		if (dir != NULL)
			free(dir);
		if (p != NULL)
			free(p);
		return (GFARM_ERR_NO_MEMORY);
	}

	dir->super.ops = &ops;
	dir->dp = dp;
	dir->path = p;
	*dirp = &dir->super;
	return (GFARM_ERR_NO_ERROR);
}