Example #1
0
int
irodsMkdir (const char *path, mode_t mode)
{
    collInp_t collCreateInp;
    int status;
    iFuseConn_t *iFuseConn = NULL;

    rodsLog (LOG_DEBUG, "irodsMkdir: %s", path);

    memset (&collCreateInp, 0, sizeof (collCreateInp));

    status = parseRodsPathStr ((char *) (path + 1) , &MyRodsEnv,
                               collCreateInp.collName);
    if (status < 0) {
        rodsLogError (LOG_ERROR, status,
                      "irodsMkdir: parseRodsPathStr of %s error", path);
        /* use ENOTDIR for this type of error */
        return -ENOTDIR;
    }

    getAndUseIFuseConn (&iFuseConn, &MyRodsEnv);
    status = rcCollCreate (iFuseConn->conn, &collCreateInp);

    if (status < 0) {
        if (isReadMsgError (status)) {
            ifuseReconnect (iFuseConn);
            status = rcCollCreate (iFuseConn->conn, &collCreateInp);
        }
        unuseIFuseConn (iFuseConn);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
                          "irodsMkdir: rcCollCreate of %s error", path);
            return -ENOENT;
        }
#ifdef CACHE_FUSE_PATH
    } else {
        struct stat stbuf;
        uint mytime = time (0);
        bzero (&stbuf, sizeof (struct stat));
        fillDirStat (&stbuf, mytime, mytime, mytime);
        pathExist ((char *) path, NULL, &stbuf, NULL);
#endif
        unuseIFuseConn (iFuseConn);
    }

    return (0);
}
Example #2
0
int irods_reli_mkdir ( const char *host, const char *path )
{
	collInp_t request;
	int result;

	struct irods_server *server = connect_to_host(host);
	if(!server) return -1;

	memset(&request,0,sizeof(request));
	strcpy(request.collName,path);

	debug(D_IRODS,"rcCollCreate %s %s",host,path);
	result = rcCollCreate(server->conn,&request);
	debug(D_IRODS,"= %d",result);

	if(result<0) {
		errno = irods_reli_errno(result);
		return -1;
	}

	return result;
}
int RodsConnection::makeColl(const std::string &collPath, bool makeRecursive)
{
    collInp_t theColl;
    int status = 0;

    this->mutexLock();

    // initialize rods api coll struct
    memset(&theColl, 0, sizeof (collInp_t));
    rstrcpy(theColl.collName, collPath.c_str(), MAX_NAME_LEN);

    // if a recursive operation is asked for, specify it
    if (makeRecursive)
        addKeyVal(&theColl.condInput, RECURSIVE_OPR__KW, "");

    // call rods api to make collection
    status = rcCollCreate(this->rodsCommPtr, &theColl);

    this->mutexUnlock();

    // return status to caller
    return (status);
}
Example #4
0
int
rsCollCreate( rsComm_t *rsComm, collInp_t *collCreateInp ) {
    int status;
    rodsServerHost_t *rodsServerHost = NULL;
    ruleExecInfo_t rei;
    collInfo_t collInfo;
    specCollCache_t *specCollCache = NULL;
    dataObjInfo_t *dataObjInfo = NULL;

    irods::error ret = validate_logical_path( collCreateInp->collName );
    if ( !ret.ok() ) {
        if ( rsComm->rError.len < MAX_ERROR_MESSAGES ) {
            char error_msg[ERR_MSG_LEN];
            snprintf(error_msg, ERR_MSG_LEN, "%s", ret.user_result().c_str());
            addRErrorMsg( &rsComm->rError, ret.code(), error_msg );
        }
        irods::log( ret );
        return SYS_INVALID_INPUT_PARAM;
    }

    // Issue 3913: retain status in case string too long
    status = resolveLinkedPath( rsComm, collCreateInp->collName, &specCollCache,
                       &collCreateInp->condInput );

    // Issue 3913: retain status in case string too long
    if (status == USER_STRLEN_TOOLONG) {
        return USER_STRLEN_TOOLONG;
    }
    status = getAndConnRcatHost(
                 rsComm,
                 MASTER_RCAT,
                 ( const char* )collCreateInp->collName,
                 &rodsServerHost );

    if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
        return status;
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
        initReiWithCollInp( &rei, rsComm, collCreateInp, &collInfo );

        status = applyRule( "acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI );

        if ( status < 0 ) {
            if ( rei.status < 0 ) {
                status = rei.status;
            }
            rodsLog( LOG_ERROR,
                     "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
                     collCreateInp->collName, status );
            return status;
        }

        if ( getValByKey( &collCreateInp->condInput, RECURSIVE_OPR__KW ) !=
                NULL ) {
            status = rsMkCollR( rsComm, "/", collCreateInp->collName );
            return status;
        }
        std::string svc_role;
        irods::error ret = get_catalog_service_role(svc_role);
        if(!ret.ok()) {
            irods::log(PASS(ret));
            return ret.code();
        }

        if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
            /* for STRUCT_FILE_COLL to make a directory in the structFile, the
             * COLLECTION_TYPE_KW must be set */

            status = resolvePathInSpecColl( rsComm, collCreateInp->collName,
                                            WRITE_COLL_PERM, 0, &dataObjInfo );
            if ( status >= 0 ) {
                freeDataObjInfo( dataObjInfo );
                if ( status == COLL_OBJ_T ) {
                    return 0;
                }
                else if ( status == DATA_OBJ_T ) {
                    return USER_INPUT_PATH_ERR;
                }
            }
            else if ( status == SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
                /* for STRUCT_FILE_COLL to make a directory in the structFile, the
                 * COLLECTION_TYPE_KW must be set */
                if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
                        dataObjInfo->specColl->collClass == LINKED_COLL ) {
                    /*  should not be here because if has been translated */
                    return SYS_COLL_LINK_PATH_ERR;
                }
                else {
                    status = l3Mkdir( rsComm, dataObjInfo );
                }
                freeDataObjInfo( dataObjInfo );
                return status;
            }
            else {
                if ( isColl( rsComm, collCreateInp->collName, NULL ) >= 0 ) {
                    return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
                }
                status = _rsRegColl( rsComm, collCreateInp );
            }
            rei.status = status;
            if ( status >= 0 ) {
                rei.status = applyRule( "acPostProcForCollCreate", NULL, &rei,
                                        NO_SAVE_REI );

                if ( rei.status < 0 ) {
                    rodsLog( LOG_ERROR,
                             "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
                             collCreateInp->collName, status );
                }
            }
        } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
            status = SYS_NO_RCAT_SERVER_ERR;
        } else {
            rodsLog(
                LOG_ERROR,
                "role not supported [%s]",
                svc_role.c_str() );
            status = SYS_SERVICE_ROLE_NOT_SUPPORTED;
        }
    }
    else {
        status = rcCollCreate( rodsServerHost->conn, collCreateInp );
    }
    return status;
}
Example #5
0
int
rsCollCreate( rsComm_t *rsComm, collInp_t *collCreateInp ) {
    int status;
    rodsServerHost_t *rodsServerHost = NULL;
    ruleExecInfo_t rei;
    collInfo_t collInfo;
    specCollCache_t *specCollCache = NULL;
#ifdef RODS_CAT
    dataObjInfo_t *dataObjInfo = NULL;
#endif

    irods::error ret = validate_collection_path( collCreateInp->collName );
    if ( !ret.ok() ) {
        irods::log( ret );
        return SYS_INVALID_INPUT_PARAM;
    }

    resolveLinkedPath( rsComm, collCreateInp->collName, &specCollCache,
                       &collCreateInp->condInput );
    status = getAndConnRcatHost(
                 rsComm,
                 MASTER_RCAT,
                 ( const char* )collCreateInp->collName,
                 &rodsServerHost );
    if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
        return status;
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
        initReiWithCollInp( &rei, rsComm, collCreateInp, &collInfo );

        status = applyRule( "acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI );

        if ( status < 0 ) {
            if ( rei.status < 0 ) {
                status = rei.status;
            }
            rodsLog( LOG_ERROR,
                     "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
                     collCreateInp->collName, status );
            return status;
        }

        if ( getValByKey( &collCreateInp->condInput, RECURSIVE_OPR__KW ) !=
                NULL ) {
            status = rsMkCollR( rsComm, "/", collCreateInp->collName );
            return status;
        }
#ifdef RODS_CAT

        /* for STRUCT_FILE_COLL to make a directory in the structFile, the
         * COLLECTION_TYPE_KW must be set */

        status = resolvePathInSpecColl( rsComm, collCreateInp->collName,
                                        WRITE_COLL_PERM, 0, &dataObjInfo );
        if ( status >= 0 ) {
            freeDataObjInfo( dataObjInfo );
            if ( status == COLL_OBJ_T ) {
                return 0;
            }
            else if ( status == DATA_OBJ_T ) {
                return USER_INPUT_PATH_ERR;
            }
        }
        else if ( status == SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
            /* for STRUCT_FILE_COLL to make a directory in the structFile, the
             * COLLECTION_TYPE_KW must be set */
            if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
                    dataObjInfo->specColl->collClass == LINKED_COLL ) {
                /*  should not be here because if has been translated */
                return SYS_COLL_LINK_PATH_ERR;
            }
            else {
                status = l3Mkdir( rsComm, dataObjInfo );
            }
            freeDataObjInfo( dataObjInfo );
            return status;
        }
        else {
            if ( isColl( rsComm, collCreateInp->collName, NULL ) >= 0 ) {
                return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
            }
            status = _rsRegColl( rsComm, collCreateInp );
        }
        rei.status = status;
        if ( status >= 0 ) {
            rei.status = applyRule( "acPostProcForCollCreate", NULL, &rei,
                                    NO_SAVE_REI );

            if ( rei.status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
                         collCreateInp->collName, status );
            }
        }

#else
        status = SYS_NO_RCAT_SERVER_ERR;
#endif
    }
    else {
        status = rcCollCreate( rodsServerHost->conn, collCreateInp );
    }

    return status;
}