示例#1
0
int
rsMkBundlePath( rsComm_t *rsComm, char *collection, char *bundlePath,
                int myRanNum ) {
    int status;
    char *tmpStr;
    char startBundlePath[MAX_NAME_LEN];
    char destBundleColl[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
    char *bundlePathPtr;

    bundlePathPtr = bundlePath;
    *bundlePathPtr = '/';
    bundlePathPtr++;
    tmpStr = collection + 1;
    /* copy the zone */
    while ( *tmpStr != '\0' ) {
        *bundlePathPtr = *tmpStr;
        bundlePathPtr ++;
        if ( *tmpStr == '/' ) {
            tmpStr ++;
            break;
        }
        tmpStr ++;
    }

    if ( *tmpStr == '\0' ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: input path %s too short", collection );
        return USER_INPUT_PATH_ERR;
    }

    /* cannot bundle trash and bundle */
    if ( strncmp( tmpStr, "trash/", 6 ) == 0 ||
            strncmp( tmpStr, "bundle/", 7 ) == 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: cannot bundle trash or bundle path %s", collection );
        return USER_INPUT_PATH_ERR;
    }


    /* don't want to go back beyond /myZone/bundle/home */
    *bundlePathPtr = '\0';
    rstrcpy( startBundlePath, bundlePath, MAX_NAME_LEN );

    snprintf( bundlePathPtr, MAX_NAME_LEN, "bundle/%s.%u", tmpStr, ( unsigned int )myRanNum );

    if ( ( status = splitPathByKey( bundlePath, destBundleColl, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) )
            < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: splitPathByKey error for %s ", bundlePath );
        return USER_INPUT_PATH_ERR;
    }

    status = rsMkCollR( rsComm, startBundlePath, destBundleColl );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkBundlePath: rsMkCollR error for startPath %s, destPath %s ",
                 startBundlePath, destBundleColl );
    }

    return status;
}
示例#2
0
int
_rsDataObjCopy( rsComm_t *rsComm, int destL1descInx, int existFlag,
                transferStat_t **transStat ) {
    dataObjInp_t *srcDataObjInp, *destDataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    dataObjInfo_t *srcDataObjInfo, *destDataObjInfo;
    int srcL1descInx;
    int status = 0, status2;

    destDataObjInp  = L1desc[destL1descInx].dataObjInp;
    destDataObjInfo = L1desc[destL1descInx].dataObjInfo;
    srcL1descInx    = L1desc[destL1descInx].srcL1descInx;

    srcDataObjInp  = L1desc[srcL1descInx].dataObjInp;
    srcDataObjInfo = L1desc[srcL1descInx].dataObjInfo;

    if ( destDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInp is NULL" );
        return -1;
    }
    if ( destDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInfo is NULL" );
        return -1;
    }
    if ( srcDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInp is NULL" );
        return -1;
    }
    if ( srcDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInfo is NULL" );
        return -1;
    }

    if ( L1desc[srcL1descInx].l3descInx <= 2 ) {

        /* no physical file was opened */
        status = l3DataCopySingleBuf( rsComm, destL1descInx );

        /* has not been registered yet because of NO_OPEN_FLAG_KW */
        if ( status    >= 0                    &&
                existFlag == 0                    &&
                destDataObjInfo->specColl == NULL &&
                L1desc[destL1descInx].remoteZoneHost == NULL ) {
            /* If the dest is in remote zone, register in _rsDataObjClose there */
            status = svrRegDataObj( rsComm, destDataObjInfo );
            if ( status == CAT_UNKNOWN_COLLECTION ) {
                /* collection does not exist. make one */
                char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN];
                splitPathByKey( destDataObjInfo->objPath, parColl, MAX_NAME_LEN, child, MAX_NAME_LEN, '/' );
                status = svrRegDataObj( rsComm, destDataObjInfo );
                rsMkCollR( rsComm, "/", parColl );
                status = svrRegDataObj( rsComm, destDataObjInfo );
            }
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "_rsDataObjCopy: svrRegDataObj for %s failed, status = %d",
                         destDataObjInfo->objPath, status );
                return status;
            }
        }

    }
    else {
        if ( srcDataObjInfo != NULL ) {
            destDataObjInp->numThreads = getNumThreads( rsComm, srcDataObjInfo->dataSize, destDataObjInp->numThreads, NULL,
                                         destDataObjInfo->rescHier, srcDataObjInfo->rescHier, 0 );

        }

        srcDataObjInp->numThreads = destDataObjInp->numThreads;

        status = dataObjCopy( rsComm, destL1descInx );
    }

    memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) );
    dataObjCloseInp.l1descInx = destL1descInx;
    if ( status >= 0 ) {
        *transStat = ( transferStat_t* )malloc( sizeof( transferStat_t ) );
        memset( *transStat, 0, sizeof( transferStat_t ) );
        ( *transStat )->bytesWritten = srcDataObjInfo->dataSize;
        ( *transStat )->numThreads = destDataObjInp->numThreads;
        dataObjCloseInp.bytesWritten = srcDataObjInfo->dataSize;
    }

    status2 = rsDataObjClose( rsComm, &dataObjCloseInp );

    if ( status ) {
        return status;
    }
    return status2;
}
示例#3
0
int
rsDataObjCopy( rsComm_t *rsComm, dataObjCopyInp_t *dataObjCopyInp,
               transferStat_t **transStat ) {
    dataObjInp_t *srcDataObjInp, *destDataObjInp;
    int srcL1descInx, destL1descInx;
    int status;
    int existFlag;
    uint createMode;
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    specCollCache_t *specCollCache = NULL;

    srcDataObjInp = &dataObjCopyInp->srcDataObjInp;
    destDataObjInp = &dataObjCopyInp->destDataObjInp;

    resolveLinkedPath( rsComm, srcDataObjInp->objPath, &specCollCache, &srcDataObjInp->condInput );
    resolveLinkedPath( rsComm, destDataObjInp->objPath, &specCollCache, &destDataObjInp->condInput );

    remoteFlag = getAndConnRemoteZoneForCopy( rsComm, dataObjCopyInp, &rodsServerHost );
    if ( remoteFlag < 0 ) {
        return remoteFlag;
    }
    else if ( remoteFlag == REMOTE_HOST ) {
        status = _rcDataObjCopy( rodsServerHost->conn, dataObjCopyInp,
                                 transStat );
        return status;
    }

    if ( strcmp( srcDataObjInp->objPath, destDataObjInp->objPath ) == 0 ) {
        rodsLog( LOG_ERROR,
                 "rsDataObjCopy: same src and dest objPath %s not allowed",
                 srcDataObjInp->objPath );
        return USER_INPUT_PATH_ERR;
    }

    addKeyVal( &srcDataObjInp->condInput, PHYOPEN_BY_SIZE_KW, "" );

    srcL1descInx = rsDataObjOpen( rsComm, srcDataObjInp );

    if ( srcL1descInx < 0 ) {
        std::stringstream msg;
        char* sys_error = NULL;
        const char* rods_error = rodsErrorName( srcL1descInx, &sys_error );
        msg << __FUNCTION__;
        msg << " - Failed to open source object: \"";
        msg << srcDataObjInp->objPath;
        msg << "\" - ";
        msg << rods_error << " " << sys_error;
        irods::log( LOG_ERROR, msg.str() );
        free( sys_error );
        return srcL1descInx;
    }

    /* have to set L1desc[srcL1descInx].dataSize because open set this to -1 */
    destDataObjInp->dataSize = L1desc[srcL1descInx].dataSize =
                                   L1desc[srcL1descInx].dataObjInfo->dataSize;

    createMode = atoi( L1desc[srcL1descInx].dataObjInfo->dataMode );

    if ( createMode >= 0100 ) {
        destDataObjInp->createMode = createMode;
    }

    L1desc[srcL1descInx].oprType = COPY_SRC;

    if ( L1desc[srcL1descInx].l3descInx <= 2 ) {
        /* dataSingleBuf */
        addKeyVal( &destDataObjInp->condInput, NO_OPEN_FLAG_KW, "" );
    }

    destL1descInx = rsDataObjCreate( rsComm, destDataObjInp );
    if ( destL1descInx == CAT_UNKNOWN_COLLECTION ) {
        /* collection does not exist. make one */
        char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN];
        splitPathByKey( destDataObjInp->objPath, parColl, MAX_NAME_LEN, child, MAX_NAME_LEN, '/' );
        rsMkCollR( rsComm, "/", parColl );
        destL1descInx = rsDataObjCreate( rsComm, destDataObjInp );
    }

    if ( destL1descInx < 0 ) {
        clearKeyVal( &destDataObjInp->condInput );
        std::stringstream msg;
        char* sys_error = NULL;
        const char* rods_error = rodsErrorName( destL1descInx, &sys_error );
        msg << __FUNCTION__;
        msg << " - Failed to create destination object: \"";
        msg << destDataObjInp->objPath;
        msg << "\" - ";
        msg << rods_error << " " << sys_error;
        irods::log( LOG_ERROR, msg.str() );
        free( sys_error );
        return destL1descInx;
    }

    if ( L1desc[destL1descInx].replStatus == NEWLY_CREATED_COPY ) {
        existFlag = 0;
    }
    else {
        existFlag = 1;
    }

    L1desc[destL1descInx].oprType = COPY_DEST;

    L1desc[destL1descInx].srcL1descInx = srcL1descInx;

    rstrcpy( L1desc[destL1descInx].dataObjInfo->dataType,

             L1desc[srcL1descInx].dataObjInfo->dataType, NAME_LEN );
    /* set dataSize for verification in _rsDataObjClose */

    L1desc[destL1descInx].dataSize =
        L1desc[srcL1descInx].dataObjInfo->dataSize;

    status = _rsDataObjCopy( rsComm, destL1descInx, existFlag, transStat );

    clearKeyVal( &destDataObjInp->condInput );

    return status;
}
示例#4
0
int
dirPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath,
rescInfo_t *rescInfo)
{
    collInp_t collCreateInp;
    fileOpendirInp_t fileOpendirInp;
    fileClosedirInp_t fileClosedirInp;
    int rescTypeInx;
    int status;
    int dirFd;
    dataObjInp_t subPhyPathRegInp;
    fileReaddirInp_t fileReaddirInp;
    rodsDirent_t *rodsDirent = NULL;
    rodsObjStat_t *rodsObjStatOut = NULL;
    int forceFlag;
    fileStatInp_t fileStatInp;
    rodsStat_t *myStat = NULL;
    char curcoll[MAX_NAME_LEN];

    *curcoll = '\0';
    rescTypeInx = rescInfo->rescTypeInx;

    status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
    if (status < 0) {
        memset (&collCreateInp, 0, sizeof (collCreateInp));
        rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, 
	  MAX_NAME_LEN);
	/* no need to resolve sym link */
	addKeyVal (&collCreateInp.condInput, TRANSLATED_PATH_KW, "");
#ifdef FILESYSTEM_META
        /* stat the source directory to track the         */
        /* original directory meta-data                   */
        memset (&fileStatInp, 0, sizeof (fileStatInp));
        rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN);
        fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
        rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN);

        status = rsFileStat (rsComm, &fileStatInp, &myStat);
        if (status != 0) {
            rodsLog (LOG_ERROR,
	      "dirPathReg: rsFileStat failed for %s, status = %d",
	      filePath, status);
	    return (status);
        }
        getFileMetaFromStat (myStat, &collCreateInp.condInput);
        addKeyVal(&collCreateInp.condInput, FILE_SOURCE_PATH_KW, filePath);
        free (myStat);
#endif /* FILESYSTEM_META */
        /* create the coll just in case it does not exist */
        status = rsCollCreate (rsComm, &collCreateInp);
	clearKeyVal (&collCreateInp.condInput);
	if (status < 0) {
            rodsLog (LOG_ERROR,
              "dirPathReg: rsCollCreate %s error. status = %d", 
              phyPathRegInp->objPath, status);
            return status;
        }
    } else if (rodsObjStatOut->specColl != NULL) {
        freeRodsObjStat (rodsObjStatOut);
        rodsLog (LOG_ERROR,
          "dirPathReg: %s already mounted", phyPathRegInp->objPath);
        return (SYS_MOUNT_MOUNTED_COLL_ERR);
    }
    freeRodsObjStat (rodsObjStatOut);

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

    rstrcpy (fileOpendirInp.dirName, filePath, MAX_NAME_LEN);
    fileOpendirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
    rstrcpy (fileOpendirInp.addr.hostAddr,  rescInfo->rescLoc, NAME_LEN);

    dirFd = rsFileOpendir (rsComm, &fileOpendirInp);
    if (dirFd < 0) {
       rodsLog (LOG_ERROR,
          "dirPathReg: rsFileOpendir for %s error, status = %d",
          filePath, dirFd);
        return (dirFd);
    }

    fileReaddirInp.fileInx = dirFd;

    if (getValByKey (&phyPathRegInp->condInput, FORCE_FLAG_KW) != NULL) {
	forceFlag = 1;
    } else {
	forceFlag = 0;
    }

    while ((status = rsFileReaddir (rsComm, &fileReaddirInp, &rodsDirent))
      >= 0) {
	int len;

        if (strlen (rodsDirent->d_name) == 0) break;

        if (strcmp (rodsDirent->d_name, ".") == 0 ||
          strcmp (rodsDirent->d_name, "..") == 0) {
	    free (rodsDirent);
            continue;
        }

        if (matchPathname(ExcludePatterns, rodsDirent->d_name, filePath)) {
            continue;
        }

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

        if (RescTypeDef[rescTypeInx].incParentDir == NO_INC_PARENT_DIR) {
	    /* don't include parent path */
            snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s",
             rodsDirent->d_name);
        } else if (RescTypeDef[rescTypeInx].incParentDir == 
          PHYPATH_IN_DIR_PTR) {
            /* we can do this locally because this API is executed at the
             * resource server */
            getPhyPathInOpenedDir (dirFd, rodsDirent->d_ino, 
              fileStatInp.fileName);
        } else {
	    len = strlen (filePath);
	    if (filePath[len - 1] == '/') {
                /* already has a '/' */
                snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s%s",
                 filePath, rodsDirent->d_name);
            } else {
                snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s/%s",
                  filePath, rodsDirent->d_name);
            }
        }
        fileStatInp.fileType = fileOpendirInp.fileType; 
	fileStatInp.addr = fileOpendirInp.addr;
        myStat = NULL;
        status = rsFileStat (rsComm, &fileStatInp, &myStat);

	if (status != 0) {
            rodsLog (LOG_ERROR,
	      "dirPathReg: rsFileStat failed for %s, status = %d",
	      fileStatInp.fileName, status);
	    free (rodsDirent);
	    return (status);
	}

        if (RescTypeDef[rescTypeInx].driverType == TDS_FILE_TYPE &&
          strchr (rodsDirent->d_name, '/') != NULL) {
            /* TDS may contain '/' in the file path */
            char *tmpPtr = rodsDirent->d_name;
            /* replace '/' with '.' */
            while (*tmpPtr != '\0') {
               if (*tmpPtr == '/') *tmpPtr = '.';
               tmpPtr ++;
            }
        }
        if (RescTypeDef[rescTypeInx].incParentDir == PHYPATH_IN_DIR_PTR) {
            /* the st_mode is stored in the opened dir */
            myStat->st_mode = getStModeInOpenedDir (dirFd, rodsDirent->d_ino);
            freePhyPathInOpenedDir (dirFd, rodsDirent->d_ino);
        }
	subPhyPathRegInp = *phyPathRegInp;
        if (RescTypeDef[rescTypeInx].incParentDir == NO_INC_PARENT_DIR) {
	    char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
	    /* d_name is a full path, need to split it */
            if ((status = splitPathByKey (rodsDirent->d_name, myDir, myFile, 
              '/')) < 0) {
                rodsLog (LOG_ERROR,
                  "dirPathReg: splitPathByKey error for %s ", 
                  rodsDirent->d_name);
                continue;
            }
	    snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s",
	      phyPathRegInp->objPath, myFile);
        } else if (RescTypeDef[rescTypeInx].incParentDir == 
            PHYPATH_IN_DIR_PTR) {
            char curdir[MAX_NAME_LEN];
            *curdir = '\0';
            getCurDirInOpenedDir (dirFd, curdir);
            if (strlen (curdir) > 0) {
                /* see if we have done it already */
                int len = strlen (subPhyPathRegInp.objPath);
                if (*curcoll == '\0'  || 
                  strcmp (&curcoll[len + 1], curdir) != 0) {
                    snprintf (curcoll, MAX_NAME_LEN, "%s/%s",
                      phyPathRegInp->objPath, curdir);
                    rsMkCollR (rsComm, phyPathRegInp->objPath, curcoll);
                }
	        snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s",
	          curcoll, rodsDirent->d_name);
            } else {
                snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s",
                  phyPathRegInp->objPath, rodsDirent->d_name);
            }
        } else {
	    snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s",
	      phyPathRegInp->objPath, rodsDirent->d_name);
        }
	if ((myStat->st_mode & S_IFREG) != 0) {     /* a file */
	    if (forceFlag > 0) {
		/* check if it already exists */
	        if (isData (rsComm, subPhyPathRegInp.objPath, NULL) >= 0) {
		    free (myStat);
	            free (rodsDirent);
		    continue;
		}
	    }
	    subPhyPathRegInp.dataSize = myStat->st_size;
	    if (getValByKey (&phyPathRegInp->condInput, REG_REPL_KW) != NULL) {
                status = filePathRegRepl (rsComm, &subPhyPathRegInp,
                  fileStatInp.fileName, rescInfo);
	    } else {
                addKeyVal (&subPhyPathRegInp.condInput, FILE_PATH_KW, 
	          fileStatInp.fileName);
	        status = filePathReg (rsComm, &subPhyPathRegInp, 
	          fileStatInp.fileName, rescInfo);
	    }
        } else if ((myStat->st_mode & S_IFDIR) != 0) {      /* a directory */
            len = strlen (subPhyPathRegInp.objPath);
            if (subPhyPathRegInp.objPath[len - 1] == '/') {
                /* take out the end '/' for objPath */
                subPhyPathRegInp.objPath[len - 1] = '\0';
            }
            status = dirPathReg (rsComm, &subPhyPathRegInp,
              fileStatInp.fileName, rescInfo);
	}
        if (status < 0) return status;
	free (myStat);
	free (rodsDirent);
    }
    if (status == -1) {         /* just EOF */
        status = 0;
    }

    fileClosedirInp.fileInx = dirFd;
    rsFileClosedir (rsComm, &fileClosedirInp);

    return (status);
}
示例#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;
    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;
}
示例#6
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;
}
示例#7
0
文件: rsRmColl.cpp 项目: bpow/irods
int
rsMkTrashPath( rsComm_t *rsComm, char *objPath, char *trashPath ) {
    int status;
    char *tmpStr;
    char startTrashPath[MAX_NAME_LEN];
    char destTrashColl[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
    char *trashPathPtr;

    trashPathPtr = trashPath;
    *trashPathPtr = '/';
    trashPathPtr++;
    tmpStr = objPath + 1;
    /* copy the zone */
    while ( *tmpStr != '\0' ) {
        *trashPathPtr = *tmpStr;
        trashPathPtr ++;
        if ( *tmpStr == '/' ) {
            tmpStr ++;
            break;
        }
        tmpStr ++;
    }

    if ( *tmpStr == '\0' ) {
        rodsLog( LOG_ERROR,
                 "rsMkTrashPath: input path %s too short", objPath );
        return USER_INPUT_PATH_ERR;
    }

    /* skip "home/userName/"  or "home/userName#" */

    if ( strncmp( tmpStr, "home/", 5 ) == 0 ) {
        int nameLen;
        tmpStr += 5;
        nameLen = strlen( rsComm->clientUser.userName );
        if ( strncmp( tmpStr, rsComm->clientUser.userName, nameLen ) == 0 &&
                ( *( tmpStr + nameLen ) == '/' || *( tmpStr + nameLen ) == '#' ) ) {
            /* tmpStr += (nameLen + 1); */
            tmpStr = strchr( tmpStr, '/' ) + 1;
        }
    }


    /* don't want to go back beyond /myZone/trash/home */
    *trashPathPtr = '\0';
    snprintf( startTrashPath, MAX_NAME_LEN, "%strash/home", trashPath );

    /* add home/userName/ */

    if ( rsComm->clientUser.authInfo.authFlag == REMOTE_USER_AUTH ||
            rsComm->clientUser.authInfo.authFlag == REMOTE_PRIV_USER_AUTH ) {
        /* remote user */
        snprintf( trashPathPtr, MAX_NAME_LEN, "trash/home/%s#%s/%s",
                  rsComm->clientUser.userName, rsComm->clientUser.rodsZone, tmpStr );
    }
    else {
        snprintf( trashPathPtr, MAX_NAME_LEN, "trash/home/%s/%s",
                  rsComm->clientUser.userName, tmpStr );
    }

    if ( ( status = splitPathByKey( trashPath, destTrashColl, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkTrashPath: splitPathByKey error for %s ", trashPath );
        return USER_INPUT_PATH_ERR;
    }

    status = rsMkCollR( rsComm, startTrashPath, destTrashColl );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMkTrashPath: rsMkCollR error for startPath %s, destPath %s ",
                 startTrashPath, destTrashColl );
    }

    return status;
}
int 
chkCollForExtAndReg (rsComm_t *rsComm, char *collection, 
rodsObjStat_t **rodsObjStatOut)
{
    dataObjInp_t dataObjInp;
    int status;
    rodsObjStat_t *myRodsObjStat = NULL;

    bzero (&dataObjInp, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, collection, MAX_NAME_LEN);
#if 0	/* allow mounted coll */
    status = collStat (rsComm, &dataObjInp, &myRodsObjStat);
#endif
    status = collStatAllKinds (rsComm, &dataObjInp, &myRodsObjStat);
#if 0
    if (status == CAT_NO_ROWS_FOUND || status == OBJ_PATH_DOES_NOT_EXIST ||
      status == USER_FILE_DOES_NOT_EXIST) {
#endif
    if (status < 0) { 
	status = rsMkCollR (rsComm, "/", collection);
	if (status < 0) {
            rodsLog (LOG_ERROR,
              "chkCollForExtAndReg: rsMkCollR of %s error. status = %d",
              collection, status);
            return (status);
	} else {
#if 0	/* allow mounted coll */
	    status = collStat (rsComm, &dataObjInp, &myRodsObjStat);
#endif
	    status = collStatAllKinds (rsComm, &dataObjInp, &myRodsObjStat);
	}
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: collStat of %s error. status = %d",
          dataObjInp.objPath, status);
        return (status);
    } else if (myRodsObjStat->specColl != NULL && 
      myRodsObjStat->specColl->collClass != MOUNTED_COLL) {
	/* only do mounted coll */
        freeRodsObjStat (myRodsObjStat);
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: %s is a struct file collection",
          dataObjInp.objPath);
        return (SYS_STRUCT_FILE_INMOUNTED_COLL);
    }

    if (myRodsObjStat->specColl == NULL) {
        status = checkCollAccessPerm (rsComm, collection, ACCESS_DELETE_OBJECT);
    } else {
	status = checkCollAccessPerm (rsComm, 
	  myRodsObjStat->specColl->collection, ACCESS_DELETE_OBJECT);
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: no permission to write %s, status = %d",
          collection, status);
        freeRodsObjStat (myRodsObjStat);
    } else {
	if (rodsObjStatOut != NULL) {
	    *rodsObjStatOut = myRodsObjStat;
	} else {
            freeRodsObjStat (myRodsObjStat);
	}
    }
    return (status);
}

/* regUnbunSubfiles - non bulk version of registering all files in phyBunDir 
 * to the collection. Valid values for flags are: 
 *	FORCE_FLAG_FLAG.
 */

int
regUnbunSubfiles (rsComm_t *rsComm, rescInfo_t *rescInfo, char *rescGroupName,
char *collection, char *phyBunDir, int flags, genQueryOut_t *attriArray)
{
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
    struct stat statbuf;
#endif
    char subfilePath[MAX_NAME_LEN];
    char subObjPath[MAX_NAME_LEN];
    dataObjInp_t dataObjInp;
    int status;
    int savedStatus = 0;
    rodsLong_t st_size;

#ifdef USE_BOOST_FS
    path srcDirPath (phyBunDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (phyBunDir);
    if (dirPtr == NULL) {
#endif
        rodsLog (LOG_ERROR,
        "regUnbunphySubfiles: opendir error for %s, errno = %d",
         phyBunDir, errno);
        return (UNIX_FILE_OPENDIR_ERR - errno);
    }
    bzero (&dataObjInp, sizeof (dataObjInp));
#ifdef USE_BOOST_FS
    directory_iterator end_itr; // default construction yields past-the-end
    for (directory_iterator itr(srcDirPath); itr != end_itr;++itr) {
        path p = itr->path();
        snprintf (subfilePath, MAX_NAME_LEN, "%s",
          p.c_str ());
#else
    while ((myDirent = readdir (dirPtr)) != NULL) {
        if (strcmp (myDirent->d_name, ".") == 0 ||
          strcmp (myDirent->d_name, "..") == 0) {
            continue;
        }
        snprintf (subfilePath, MAX_NAME_LEN, "%s/%s",
          phyBunDir, myDirent->d_name);
#endif

#ifdef USE_BOOST_FS
        if (!exists (p)) {
#else
        status = lstat (subfilePath, &statbuf);

        if (status != 0) {
#endif
            rodsLog (LOG_ERROR,
              "regUnbunphySubfiles: stat error for %s, errno = %d",
              subfilePath, errno);
            savedStatus = UNIX_FILE_STAT_ERR - errno;
	    unlink (subfilePath);
	    continue;
        }

#ifdef USE_BOOST_FS
	if (is_symlink (p)) {
#else
	if ((statbuf.st_mode & S_IFLNK) == S_IFLNK) {
#endif
            rodsLogError (LOG_ERROR, SYMLINKED_BUNFILE_NOT_ALLOWED,
              "regUnbunSubfiles: %s is a symlink",
              subfilePath);
            savedStatus = SYMLINKED_BUNFILE_NOT_ALLOWED;
            continue;
        }
#ifdef USE_BOOST_FS
        path childPath = p.filename();
        snprintf (subObjPath, MAX_NAME_LEN, "%s/%s",
          collection, childPath.c_str());

	if (is_directory (p)) {
#else
        snprintf (subObjPath, MAX_NAME_LEN, "%s/%s",
          collection, myDirent->d_name);

        if ((statbuf.st_mode & S_IFDIR) != 0) {
#endif
            status = rsMkCollR (rsComm, "/", subObjPath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: rsMkCollR of %s error. status = %d",
                  subObjPath, status);
                savedStatus = status;
		continue;
	    }
	    status = regUnbunSubfiles (rsComm, rescInfo, rescGroupName,
	      subObjPath, subfilePath, flags, attriArray);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: regUnbunSubfiles of %s error. status=%d",
                  subObjPath, status);
                savedStatus = status;
                continue;
            }
#ifdef USE_BOOST_FS
        } else if (is_regular_file (p)) {
	    st_size = file_size (p);
#else
        } else if ((statbuf.st_mode & S_IFREG) != 0) {
	    st_size = statbuf.st_size;
#endif
	    status = regSubfile (rsComm, rescInfo, rescGroupName,
		subObjPath, subfilePath, st_size, flags);
	    unlink (subfilePath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: regSubfile of %s error. status=%d",
                  subObjPath, status);
                savedStatus = status;
                continue;
	    }
	}
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif
    rmdir (phyBunDir);
    return savedStatus;
}

int
regSubfile (rsComm_t *rsComm, rescInfo_t *rescInfo, char *rescGroupName,
char *subObjPath, char *subfilePath, rodsLong_t dataSize, int flags)
{
    dataObjInfo_t dataObjInfo;
    dataObjInp_t dataObjInp;
#ifndef USE_BOOST_FS
    struct stat statbuf;
#endif
    int status;
    int modFlag = 0;

    bzero (&dataObjInp, sizeof (dataObjInp));
    bzero (&dataObjInfo, sizeof (dataObjInfo));
    rstrcpy (dataObjInp.objPath, subObjPath, MAX_NAME_LEN);
    rstrcpy (dataObjInfo.objPath, subObjPath, MAX_NAME_LEN);
    rstrcpy (dataObjInfo.rescName, rescInfo->rescName, NAME_LEN);
    rstrcpy (dataObjInfo.dataType, "generic", NAME_LEN);
    dataObjInfo.rescInfo = rescInfo;
    rstrcpy (dataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
    dataObjInfo.dataSize = dataSize;

    status = getFilePathName (rsComm, &dataObjInfo, &dataObjInp);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: getFilePathName err for %s. status = %d",
          dataObjInp.objPath, status);
        return (status);
    }

#ifdef USE_BOOST_FS
    path p (dataObjInfo.filePath);
    if (exists (p)) {
	if (is_directory (p)) {
#else
    status = stat (dataObjInfo.filePath, &statbuf);
    if (status == 0 || errno != ENOENT) {
        if ((statbuf.st_mode & S_IFDIR) != 0) {
#endif
	    return SYS_PATH_IS_NOT_A_FILE;
	}

        if (chkOrphanFile (rsComm, dataObjInfo.filePath, rescInfo->rescName, 
	  &dataObjInfo) > 0) {
	    /* an orphan file. just rename it */
	    fileRenameInp_t fileRenameInp;
	    bzero (&fileRenameInp, sizeof (fileRenameInp));
            rstrcpy (fileRenameInp.oldFileName, dataObjInfo.filePath, 
	      MAX_NAME_LEN);
            status = renameFilePathToNewDir (rsComm, ORPHAN_DIR, 
	      &fileRenameInp, rescInfo, 1);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regSubFile: renameFilePathToNewDir err for %s. status = %d",
                  fileRenameInp.oldFileName, status);
                return (status);
	    }
	} else {
	    /* not an orphan file */
	    if ((flags & FORCE_FLAG_FLAG) != 0 && dataObjInfo.dataId > 0 && 
	      strcmp (dataObjInfo.objPath, subObjPath) == 0) {
		/* overwrite the current file */
		modFlag = 1;
		unlink (dataObjInfo.filePath);
	    } else {
		status = SYS_COPY_ALREADY_IN_RESC;
                rodsLog (LOG_ERROR,
                  "regSubFile: phypath %s is already in use. status = %d",
                  dataObjInfo.filePath, status);
                return (status);
	    }
        }
    }
    /* make the necessary dir */
    mkDirForFilePath (UNIX_FILE_TYPE, rsComm, "/", dataObjInfo.filePath,
      getDefDirMode ());
    /* add a link */

#ifndef windows_platform   /* Windows does not support link */
    status = link (subfilePath, dataObjInfo.filePath);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: link error %s to %s. errno = %d",
          subfilePath, dataObjInfo.filePath, errno);
        return (UNIX_FILE_LINK_ERR - errno);
    }
#endif

    if (modFlag == 0) {
        status = svrRegDataObj (rsComm, &dataObjInfo);
    } else {
        char tmpStr[MAX_NAME_LEN];
        modDataObjMeta_t modDataObjMetaInp;
	keyValPair_t regParam;

	bzero (&modDataObjMetaInp, sizeof (modDataObjMetaInp));
	bzero (&regParam, sizeof (regParam));
        snprintf (tmpStr, MAX_NAME_LEN, "%lld", dataSize);
        addKeyVal (&regParam, DATA_SIZE_KW, tmpStr);
        addKeyVal (&regParam, ALL_REPL_STATUS_KW, tmpStr);
        snprintf (tmpStr, MAX_NAME_LEN, "%d", (int) time (NULL));
        addKeyVal (&regParam, DATA_MODIFY_KW, tmpStr);

        modDataObjMetaInp.dataObjInfo = &dataObjInfo;
        modDataObjMetaInp.regParam = &regParam;

        status = rsModDataObjMeta (rsComm, &modDataObjMetaInp);

        clearKeyVal (&regParam);
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: svrRegDataObj of %s. errno = %d",
          dataObjInfo.objPath, errno);
	unlink (dataObjInfo.filePath);
    } else {
	ruleExecInfo_t rei;
	dataObjInp_t dataObjInp;
	bzero (&dataObjInp, sizeof (dataObjInp));
	rstrcpy (dataObjInp.objPath, dataObjInfo.objPath, MAX_NAME_LEN);
	initReiWithDataObjInp (&rei, rsComm, &dataObjInp);
	rei.doi = &dataObjInfo;
	rei.status = applyRule ("acPostProcForTarFileReg", NULL, &rei,
                    NO_SAVE_REI);
	if (rei.status < 0) {
            rodsLogError (LOG_ERROR, rei.status,
              "regSubFile: acPostProcForTarFileReg error for %s. status = %d",
              dataObjInfo.objPath);
	}
    }
    return status;
}