Esempio n. 1
0
int
initDataObjInfoForRepl(
    dataObjInfo_t* destDataObjInfo,
    dataObjInfo_t* srcDataObjInfo,
    const char*	   _resc_name ) {


    memset( destDataObjInfo, 0, sizeof( dataObjInfo_t ) );
    *destDataObjInfo = *srcDataObjInfo;
    memset( &destDataObjInfo->condInput, 0, sizeof( destDataObjInfo->condInput ) );
    replKeyVal( &srcDataObjInfo->condInput, &destDataObjInfo->condInput );

    destDataObjInfo->filePath[0] = '\0';
    rstrcpy( destDataObjInfo->rescName, _resc_name, NAME_LEN );

    // initialize the destination resource hierarchy to the root resource
    rstrcpy( destDataObjInfo->rescHier, _resc_name, MAX_NAME_LEN ); // orphan right now
    irods::error ret = resc_mgr.hier_to_leaf_id(_resc_name,destDataObjInfo->rescId);
    if( !ret.ok() ) {
        irods::log(PASS(ret));
    }

    destDataObjInfo->replNum = destDataObjInfo->dataId = 0;

    return 0;
}
Esempio n. 2
0
int
rsOpenCollection (rsComm_t *rsComm, collInp_t *openCollInp)
{
    int status;
    int handleInx;
    collHandle_t *collHandle;
    rodsObjStat_t *rodsObjStatOut = NULL;

    handleInx = allocCollHandle ();

    if (handleInx < 0) return (handleInx);

    collHandle = &CollHandle[handleInx];

    status = rsInitQueryHandle (&collHandle->queryHandle, rsComm);
   
    if (status < 0) return status;

    rstrcpy (collHandle->dataObjInp.objPath, openCollInp->collName, 
      MAX_NAME_LEN);
    if ((openCollInp->flags & INCLUDE_CONDINPUT_IN_QUERY) != 0) {
	replKeyVal (&openCollInp->condInput, &collHandle->dataObjInp.condInput);
    }
    status = rsObjStat (rsComm, &collHandle->dataObjInp, &rodsObjStatOut);


    if (status < 0) {
	rsCloseCollection (rsComm, &handleInx);
	return status;
    }

    if (rodsObjStatOut->objType != COLL_OBJ_T) {
	freeRodsObjStat (rodsObjStatOut);
	rsCloseCollection (rsComm, &handleInx);
	return CAT_NAME_EXISTS_AS_DATAOBJ;
    }

#if 0
    collHandle->dataObjInp.specColl = rodsObjStatOut->specColl;
#else
    replSpecColl (rodsObjStatOut->specColl, &collHandle->dataObjInp.specColl);
#endif
    if (rodsObjStatOut->specColl != NULL &&
      rodsObjStatOut->specColl->collClass == LINKED_COLL) {
	/* save the linked path */
	rstrcpy (collHandle->linkedObjPath, rodsObjStatOut->specColl->objPath,
	  MAX_NAME_LEN);
    };

    collHandle->rodsObjStat = rodsObjStatOut;

    collHandle->state = COLL_OPENED;
    collHandle->flags = openCollInp->flags;
    /* the collection exist. now query the data in it */
    return (handleInx);
}
Esempio n. 3
0
/**
 * \fn msiPropertiesClone( msParam_t *listParam, msParam_t *cloneParam, ruleExecInfo_t *rei )
 *
 * \brief Clone a property list, returning a new property list
 *
 * \module properties
 *
 * \since pre-2.1
 *
 * \author  David R. Nadeau / University of California, San Diego
 * \date    2007
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] listParam - a KeyValPair_MS_T, the property list to clone
 * \param[out] cloneParam - a KeyValPair_MS_T, the returned clone (new property list)
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect a new peoperty list is created
 *
 * \return integer
 * \retval 0 on success
 * \pre none
 * \post none
 * \sa none
**/
int
msiPropertiesClone( msParam_t *listParam, msParam_t *cloneParam, ruleExecInfo_t *rei )
{
	RE_TEST_MACRO( "    Calling msiPropertiesClone" );

	/* Check parameters */
	if ( strcmp( listParam->type, KeyValPair_MS_T ) != 0 )
		return USER_PARAM_TYPE_ERR;

	fillMsParam( cloneParam, NULL,
		KeyValPair_MS_T, mallocAndZero( sizeof(keyValPair_t) ), NULL );
	replKeyVal( (keyValPair_t*)listParam->inOutStruct, (keyValPair_t*)cloneParam->inOutStruct );
	return 0;
}
Esempio n. 4
0
int
readAggInfo (rsComm_t *rsComm, char *aggColl, keyValPair_t *condInput,
ncAggInfo_t **ncAggInfo)
{
    int status;
    dataObjInp_t dataObjInp;
    bytesBuf_t packedBBuf;
    portalOprOut_t *portalOprOut = NULL;

    bzero (&dataObjInp, sizeof (dataObjInp));
    bzero (&packedBBuf, sizeof (packedBBuf));
    if (condInput != NULL)
        replKeyVal (condInput, &dataObjInp.condInput);
    snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
      aggColl, NC_AGG_INFO_FILE_NAME);
    dataObjInp.oprType = GET_OPR;
    status = rsDataObjGet (rsComm, &dataObjInp, &portalOprOut, &packedBBuf);
    clearKeyVal (&dataObjInp.condInput);
    if (portalOprOut != NULL) free (portalOprOut);
    if (status < 0) {
        if (status == CAT_NO_ROWS_FOUND) status = NETCDF_AGG_INFO_FILE_ERR;
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: rsDataObjGet error for %s", dataObjInp.objPath);
        return status;
    }
    status = unpackStruct (packedBBuf.buf, (void **) ncAggInfo,
      "NcAggInfo_PI", RodsPackTable, XML_PROT);

    if (status < 0) {
        rodsLogError (LOG_ERROR, status,
          "readAggInfo: unpackStruct error for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    if (*ncAggInfo == NULL || (*ncAggInfo)->numFiles == 0) {
        rodsLog (LOG_ERROR,
          "readAggInfo: No ncAggInfo for %s", dataObjInp.objPath);
        return NETCDF_AGG_INFO_FILE_ERR;
    }
    return status;
}
Esempio n. 5
0
int
initDataObjInfoForRepl(
    dataObjInfo_t* destDataObjInfo,
    dataObjInfo_t* srcDataObjInfo,
    const char*	   _resc_name ) {


    memset( destDataObjInfo, 0, sizeof( dataObjInfo_t ) );
    *destDataObjInfo = *srcDataObjInfo;
    memset( &destDataObjInfo->condInput, 0, sizeof( destDataObjInfo->condInput ) );
    replKeyVal( &srcDataObjInfo->condInput, &destDataObjInfo->condInput );

    destDataObjInfo->filePath[0] = '\0';
    rstrcpy( destDataObjInfo->rescName, _resc_name, NAME_LEN );

    // initialize the destination resource hierarchy to the root resource
    rstrcpy( destDataObjInfo->rescHier, _resc_name, MAX_NAME_LEN ); // orphan right now


    destDataObjInfo->replNum = destDataObjInfo->dataId = 0;

    return 0;
}
Esempio n. 6
0
    int
    rsNcGetAggInfo( rsComm_t *rsComm, ncOpenInp_t *ncOpenInp,
                    ncAggInfo_t **ncAggInfo ) {
        specCollCache_t *specCollCache = NULL;
        collInp_t collInp;
        int handleInx;
        collEnt_t *collEnt;
        int status = 0;
        int status2 = 0;
        int savedStatus = 0;
        ncOpenInp_t childNcOpenInp;
        ncAggElement_t *ncAggElement = NULL;
        bytesBuf_t *packedBBuf = NULL;

        bzero( &collInp, sizeof( collInp ) );
        rstrcpy( collInp.collName, ncOpenInp->objPath, MAX_NAME_LEN );
        resolveLinkedPath( rsComm, collInp.collName, &specCollCache,
                           &ncOpenInp->condInput );
        collInp.flags = VERY_LONG_METADATA_FG;
        handleInx = irods::server_api_call ( OPEN_COLLECTION_AN, rsComm, &collInp );
        if ( handleInx < 0 ) {
            rodsLog( LOG_ERROR,
                     "rsNcGetAggInfo: rsOpenCollection of %s error. status = %d",
                     collInp.collName, handleInx );
            return ( handleInx );
        }
        bzero( &childNcOpenInp, sizeof( childNcOpenInp ) );
        *ncAggInfo = ( ncAggInfo_t * ) calloc( 1, sizeof( ncAggInfo_t ) );
        rstrcpy( ( *ncAggInfo )->ncObjectName, ncOpenInp->objPath, MAX_NAME_LEN );
        while ( ( status2 = irods::server_api_call ( READ_COLLECTION_AN, rsComm, &handleInx, &collEnt ) ) >= 0 ) {
            if ( collEnt->objType != DATA_OBJ_T ) {
                free( collEnt );
                continue;
            }
            else if ( strcmp( collEnt->dataType, "netcdf" ) != 0 ) {
                if ( strcmp( collEnt->dataName, NC_AGG_INFO_FILE_NAME ) != 0 ) {
                    rodsLog( LOG_NOTICE,
                             "rsNcGetAggInfo: dataType of %s in %s is not 'netcdf' type",
                             collEnt->dataName, collInp.collName );
                    savedStatus = NETCDF_INVALID_DATA_TYPE;
                }
                free( collEnt );
                continue;
            }
            snprintf( childNcOpenInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, collEnt->dataName );
            status = irods::server_api_call ( NC_GET_AGG_ELEMENT_AN, rsComm, &childNcOpenInp, &ncAggElement );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsNcGetAggElement of %s error.",
                              childNcOpenInp.objPath );
                free( collEnt );
                break;
            }
            else {
                status = addNcAggElement( ncAggElement, *ncAggInfo );
                free( ncAggElement );
                if ( status < 0 ) {
                    free( collEnt );
                    break;
                }
            }
            free( collEnt );
        }
        irods::server_api_call ( CLOSE_COLLECTION_AN, rsComm, &handleInx );
        if ( status2 < 0 && status2 != CAT_NO_ROWS_FOUND && status >= 0 ) {
            status = status2;
        }
        if ( status >= 0 && ( ncOpenInp->mode & NC_WRITE ) != 0 ) {
            dataObjInp_t dataObjInp;
            portalOprOut_t *portalOprOut = NULL;
            status = packStruct( ( void * ) * ncAggInfo, &packedBBuf, "NcAggInfo_PI",
                                 RodsPackTable, 0, XML_PROT );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: packStruct error for %s",
                              childNcOpenInp.objPath );
                return status;
            }
            /* write it */
            bzero( &dataObjInp, sizeof( dataObjInp ) );
            replKeyVal( &ncOpenInp->condInput, &dataObjInp.condInput );
            snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collInp.collName, NC_AGG_INFO_FILE_NAME );
            dataObjInp.dataSize = packedBBuf->len;
            dataObjInp.oprType = PUT_OPR;
            addKeyVal( &dataObjInp.condInput, DATA_INCLUDED_KW, "" );
            addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
            status = irods::server_api_call ( DATA_OBJ_PUT_AN, rsComm, &dataObjInp, packedBBuf, &portalOprOut );
            clearBBuf( packedBBuf );
            clearKeyVal( &dataObjInp.condInput );
            if ( portalOprOut != NULL ) {
                free( portalOprOut );
            }
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rsNcGetAggInfo: rsDataObjPut error for %s", dataObjInp.objPath );
            }
        }
        if ( status < 0 ) {
            return status;
        }
        else {
            return savedStatus;
        }
    }
Esempio n. 7
0
int _rsStructFileBundle( rsComm_t*                 rsComm,
                         structFileExtAndRegInp_t* structFileBundleInp ) {
    int status;
    int handleInx;
    char phyBunDir[MAX_NAME_LEN];
    char tmpPath[MAX_NAME_LEN];
    int l1descInx;
    char* dataType = 0; // JMC - backport 4664
    openedDataObjInp_t dataObjCloseInp;

    // =-=-=-=-=-=-=-
    // create an empty data obj
    dataObjInp_t dataObjInp;
    memset( &dataObjInp, 0, sizeof( dataObjInp ) );
    dataObjInp.openFlags = O_WRONLY;

    // =-=-=-=-=-=-=-
    // get the data type of the structured file
    dataType = getValByKey( &structFileBundleInp->condInput, DATA_TYPE_KW );

    // =-=-=-=-=-=-=-
    // ensure that the file name will end in .zip, if necessary
    if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
        int len = strlen( structFileBundleInp->objPath );
        if ( strcmp( &structFileBundleInp->objPath[len - 4], ".zip" ) != 0 ) {
            strcat( structFileBundleInp->objPath, ".zip" );
        }
    }

    // =-=-=-=-=-=-=-
    // capture the object path in the data obj struct
    rstrcpy( dataObjInp.objPath, structFileBundleInp->objPath, MAX_NAME_LEN );

    // =-=-=-=-=-=-=-
    // replicate the condInput. may have resource input
    replKeyVal( &structFileBundleInp->condInput, &dataObjInp.condInput );

    // =-=-=-=-=-=-=-
    // open the file if we are in an add operation, otherwise create the new file
    if ( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR ) != 0 ) { // JMC - backport 4643
        l1descInx = rsDataObjOpen( rsComm, &dataObjInp );

    }
    else {
        l1descInx = rsDataObjCreate( rsComm, &dataObjInp );

    }

    // =-=-=-=-=-=-=-
    // error check create / open
    if ( l1descInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsDataObjCreate of %s error. status = %d",
                 dataObjInp.objPath, l1descInx );
        return l1descInx;
    }

    // =-=-=-=-=-=-=-
    // FIXME :: Why, when we replicate them above?
    clearKeyVal( &dataObjInp.condInput ); // JMC - backport 4637
    // ???? l3Close (rsComm, l1descInx);

    // =-=-=-=-=-=-=-
    // zip does not like a zero length file as target
    //L1desc[ l1descInx ].l3descInx = 0;
    //if( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) {
    //    if( ( structFileBundleInp->oprType & ADD_TO_TAR_OPR) == 0 ) { // JMC - backport 4643
    //        l3Unlink( rsComm, L1desc[l1descInx].dataObjInfo );
    //    }
    //}

    // =-=-=-=-=-=-=-
    // check object permissions / stat
    chkObjPermAndStat_t chkObjPermAndStatInp;
    memset( &chkObjPermAndStatInp, 0, sizeof( chkObjPermAndStatInp ) );
    rstrcpy( chkObjPermAndStatInp.objPath, structFileBundleInp->collection, MAX_NAME_LEN );
    chkObjPermAndStatInp.flags = CHK_COLL_FOR_BUNDLE_OPR;
    addKeyVal( &chkObjPermAndStatInp.condInput, RESC_NAME_KW,     L1desc[l1descInx].dataObjInfo->rescName );

    // =-=-=-=-=-=-=-
    // get the resc hier string
    std::string resc_hier;
    char* resc_hier_ptr = getValByKey( &structFileBundleInp->condInput, RESC_HIER_STR_KW );
    if ( !resc_hier_ptr ) {
        rodsLog( LOG_NOTICE, "_rsStructFileBundle :: RESC_HIER_STR_KW is NULL" );
    }
    else {
        addKeyVal( &chkObjPermAndStatInp.condInput, RESC_HIER_STR_KW, resc_hier_ptr );
        resc_hier = resc_hier_ptr;
    }

    status = rsChkObjPermAndStat( rsComm, &chkObjPermAndStatInp );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsChkObjPermAndStat of %s error. stat = %d",
                 chkObjPermAndStatInp.objPath, status );
        dataObjCloseInp.l1descInx = l1descInx;
        rsDataObjClose( rsComm, &dataObjCloseInp );
        return status;
    }

    clearKeyVal( &chkObjPermAndStatInp.condInput );

    // =-=-=-=-=-=-=-
    // create the special hidden directory where the bundling happens
    createPhyBundleDir( rsComm, L1desc[ l1descInx ].dataObjInfo->filePath, phyBunDir, L1desc[ l1descInx ].dataObjInfo->rescHier );

    // =-=-=-=-=-=-=-
    // build a collection open input structure
    collInp_t collInp;
    bzero( &collInp, sizeof( collInp ) );
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG | INCLUDE_CONDINPUT_IN_QUERY;
    rstrcpy( collInp.collName, structFileBundleInp->collection, MAX_NAME_LEN );
    addKeyVal( &collInp.condInput, RESC_NAME_KW, L1desc[ l1descInx ].dataObjInfo->rescName );

    rodsLog( LOG_DEBUG, "rsStructFileBundle: calling rsOpenCollection for [%s]", structFileBundleInp->collection );

    // =-=-=-=-=-=-=-
    // open the collection from which we will bundle
    handleInx = rsOpenCollection( rsComm, &collInp );
    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: rsOpenCollection of %s error. status = %d",
                 collInp.collName, handleInx );
        rmdir( phyBunDir );
        return handleInx;
    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    int collLen = 0;
    if ( ( structFileBundleInp->oprType & PRESERVE_COLL_PATH ) != 0 ) {
        // =-=-=-=-=-=-=-
        // preserve the last entry of the coll path
        char* tmpPtr = collInp.collName;
        int   tmpLen = 0;
        collLen = 0;

        // =-=-=-=-=-=-=-
        // find length to the last '/'
        while ( *tmpPtr != '\0' ) {
            if ( *tmpPtr == '/' ) {
                collLen = tmpLen;
            }

            tmpLen++;
            tmpPtr++;
        }

    }
    else {
        collLen = strlen( collInp.collName );

    }

    // =-=-=-=-=-=-=-
    // preserve the collection path?
    collEnt_t* collEnt = NULL;
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( NULL == collEnt ) {
            rodsLog(
                LOG_ERROR,
                "rsStructFileBundle: collEnt is NULL" );
            continue;
        }

        // =-=-=-=-=-=-=-
        // entry is a data object
        if ( collEnt->objType == DATA_OBJ_T ) {
            // =-=-=-=-=-=-=-
            // filter out any possible replicas that are not on this resource
            if ( resc_hier != collEnt->resc_hier ) {
                rodsLog(
                    LOG_DEBUG,
                    "_rsStructFileBundle - skipping [%s] on resc [%s]",
                    collEnt->phyPath,
                    collEnt->resc_hier );
                free( collEnt );
                collEnt = NULL;
                continue;
            }

            if ( collEnt->collName[collLen] == '\0' ) {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN,
                    "%s/%s",
                    phyBunDir,
                    collEnt->dataName );
            }
            else {
                snprintf(
                    tmpPath,
                    MAX_NAME_LEN, "%s/%s/%s",
                    phyBunDir,
                    collEnt->collName + collLen + 1,
                    collEnt->dataName );
                status = mkDirForFilePath(
                             rsComm,
                             strlen( phyBunDir ),
                             tmpPath,
                             collEnt->resc_hier,
                             getDefDirMode() );
                if ( status < 0 ) {
                    rodsLog(
                        LOG_ERROR,
                        "mkDirForFilePath failed in _rsStructFileBundle with status %d",
                        status );
                    free( collEnt );
                    return status;
                }
            }

            // =-=-=-=-=-=-=-
            // add a link
            status = link( collEnt->phyPath, tmpPath );
            if ( status < 0 ) {
                rodsLog(
                    LOG_ERROR,
                    "rsStructFileBundle: link error %s to %s. errno = %d",
                    collEnt->phyPath,
                    tmpPath,
                    errno );
                rmLinkedFilesInUnixDir( phyBunDir );
                rmdir( phyBunDir );
                free( collEnt );
                return UNIX_FILE_LINK_ERR - errno;
            }
            else {
                rodsLog(
                    LOG_DEBUG,
                    "_rsStructFileBundle - LINK  [%s] on resc [%s]",
                    collEnt->phyPath,
                    collEnt->resc_hier );
            }
        }
        else {
            // =-=-=-=-=-=-=-
            // entry is a collection
            if ( ( int ) strlen( collEnt->collName ) + 1 <= collLen ) {
                free( collEnt );
                collEnt = NULL;
                continue;
            }
            snprintf( tmpPath, MAX_NAME_LEN, "%s/%s", phyBunDir, collEnt->collName + collLen );
            status = mkFileDirR( rsComm, strlen( phyBunDir ), tmpPath, resc_hier.c_str(), getDefDirMode() );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR, "mkFileDirR failed in _rsStructFileBundle with status %d", status );
                free( collEnt );
                return status;
            }
        } // else

        free( collEnt );
        collEnt = NULL;

    } // while

    // =-=-=-=-=-=-=-
    // clean up key vals and close the collection
    clearKeyVal( &collInp.condInput );
    rsCloseCollection( rsComm, &handleInx );

    // =-=-=-=-=-=-=-
    // call the helper function to do the actual bundling
    status = phyBundle( rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
                        collInp.collName, structFileBundleInp->oprType ); // JMC - backport 4643

    int savedStatus = 0;
    if ( status < 0 ) {
        rodsLog( LOG_ERROR, "rsStructFileBundle: phyBundle of %s error. stat = %d",
                 L1desc[ l1descInx ].dataObjInfo->objPath, status );
        L1desc[ l1descInx ].bytesWritten = 0;
        savedStatus = status;
    }
    else {
        // mark it was written so the size would be adjusted
        L1desc[ l1descInx ].bytesWritten = 1;
    }

    // =-=-=-=-=-=-=-
    // clean up after the bundle directory
    rmLinkedFilesInUnixDir( phyBunDir );
    rmdir( phyBunDir );

    dataObjCloseInp.l1descInx = l1descInx;
    status = rsDataObjClose( rsComm, &dataObjCloseInp );
    if ( status >= 0 ) {
        return savedStatus;
    }

    return status;
}
Esempio n. 8
0
 virtual void cond_input( const keyValPair_t& _cond_input ) {
     replKeyVal( &_cond_input, &cond_input_ );
 }
Esempio n. 9
0
int
chksumCollUtil (rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, 
rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
{
    int status;
    int savedStatus = 0;
    char srcChildPath[MAX_NAME_LEN];
    collHandle_t collHandle;
    collEnt_t collEnt;
    int queryFlags;

    if (srcColl == NULL) {
       rodsLog (LOG_ERROR,
          "chksumCollUtil: NULL srcColl input");
        return (USER__NULL_INPUT_ERR);
    }

    fprintf (stdout, "C- %s:\n", srcColl);

    if (rodsArgs->resource == True) {
#if 0
	queryFlags = LONG_METADATA_FG | NO_TRIM_REPL_FG;
#else
	queryFlags = INCLUDE_CONDINPUT_IN_QUERY;
	bzero (&collHandle, sizeof (collHandle));
	replKeyVal (&dataObjInp->condInput, &collHandle.dataObjInp.condInput);
#endif
    } else {
	queryFlags = 0;
    }
    status = rclOpenCollection (conn, srcColl, queryFlags, &collHandle);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chksumCollUtil: rclOpenCollection of %s error. status = %d",
          srcColl, status);
        return status;
    }
    if (collHandle.rodsObjStat->specColl != NULL &&
      collHandle.rodsObjStat->specColl->collClass != LINKED_COLL) {
        /* no trim for mounted coll */
        rclCloseCollection (&collHandle);
        return 0;
    }
    while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) {
        if (collEnt.objType == DATA_OBJ_T) {
            snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s",
              collEnt.collName, collEnt.dataName);
	    /* screen unnecessary call to chksumDataObjUtil if user input a 
	     * resource. */
#if 0
            if (rodsArgs->resource != True || 
	      rodsArgs->resourceString == NULL ||
	      strcmp (rodsArgs->resourceString, collEnt.resource) == 0) {
#endif
                status = chksumDataObjUtil (conn, srcChildPath, myRodsEnv, 
	          rodsArgs, dataObjInp);
                if (status < 0) {
                    rodsLogError (LOG_ERROR, status,
                      "chksumCollUtil:chksumDataObjU failed for %s.stat = %d",
                      srcChildPath, status);
                    /* need to set global error here */
                    savedStatus = status;
                    status = 0;
		}
#if 0
	    } else {
		status = 0;
            }
#endif
        } else if (collEnt.objType == COLL_OBJ_T) {
            dataObjInp_t childDataObjInp;
            childDataObjInp = *dataObjInp;
	    if (collEnt.specColl.collClass != NO_SPEC_COLL)
                childDataObjInp.specColl = &collEnt.specColl;
            else 
                childDataObjInp.specColl = NULL;
            status = chksumCollUtil (conn, collEnt.collName, myRodsEnv,
              rodsArgs, &childDataObjInp, collInp);
            if (status < 0 && status != CAT_NO_ROWS_FOUND) {
                return (status);
            }
        }
    }
    rclCloseCollection (&collHandle);
    if (savedStatus < 0) {
	return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND) {
	return (0);
    } else {
        return (status);
    }
}
Esempio n. 10
0
int
replCollUtil( rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv,
              rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp,
              rodsRestart_t *rodsRestart ) {
    int status;
    int savedStatus = 0;
    collHandle_t collHandle;
    collEnt_t collEnt;
    char srcChildPath[MAX_NAME_LEN];

    if ( srcColl == NULL ) {
        rodsLog( LOG_ERROR,
                 "replCollUtil: NULL srcColl input" );
        return ( USER__NULL_INPUT_ERR );
    }

    if ( rodsArgs->recursive != True ) {
        rodsLog( LOG_ERROR,
                 "replCollUtil: -r option must be used for getting %s collection",
                 srcColl );
        return ( USER_INPUT_OPTION_ERR );
    }

    if ( rodsArgs->verbose == True ) {
        fprintf( stdout, "C- %s:\n", srcColl );
    }

    bzero( &collHandle, sizeof( collHandle ) );
    replKeyVal( &dataObjInp->condInput, &collHandle.dataObjInp.condInput );
    status = rclOpenCollection( conn, srcColl, INCLUDE_CONDINPUT_IN_QUERY,
                                &collHandle );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "replCollUtil: rclOpenCollection of %s error. status = %d",
                 srcColl, status );
        return status;
    }
    if ( collHandle.rodsObjStat->specColl != NULL &&
            collHandle.rodsObjStat->specColl->collClass != LINKED_COLL ) {
        /* no repl for mounted coll */
        rclCloseCollection( &collHandle );
        return 0;
    }
    while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) {
        if ( collEnt.objType == DATA_OBJ_T ) {
            snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s",
                      collEnt.collName, collEnt.dataName );

            status = chkStateForResume( conn, rodsRestart, srcChildPath,
                                        rodsArgs, DATA_OBJ_T, &dataObjInp->condInput, 0 );

            if ( status < 0 ) {
                /* restart failed */
                break;
            }
            else if ( status == 0 ) {
                continue;
            }

            status = replDataObjUtil( conn, srcChildPath, collEnt.dataSize,
                                      myRodsEnv, rodsArgs, dataObjInp );

            if ( status == SYS_COPY_ALREADY_IN_RESC ) {
                if ( rodsArgs->verbose == True ) {
                    printf( "copy of %s already exists. Probably OK\n",
                            srcChildPath );
                }
                status = 0;
            }

            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "replCollUtil: replDataObjUtil failed for %s. status = %d",
                              srcChildPath, status );
                if ( rodsRestart->fd > 0 ) {
                    break;
                }
                else {
                    savedStatus = status;
                }
            }
            else {
                status = procAndWrriteRestartFile( rodsRestart, srcChildPath );
            }
        }
        else if ( collEnt.objType == COLL_OBJ_T ) {
            dataObjInp_t childDataObjInp;
            childDataObjInp = *dataObjInp;
            if ( collEnt.specColl.collClass != NO_SPEC_COLL ) {
                childDataObjInp.specColl = &collEnt.specColl;
            }
            else {
                childDataObjInp.specColl = NULL;
            }
            status = replCollUtil( conn, collEnt.collName, myRodsEnv,
                                   rodsArgs, &childDataObjInp, rodsRestart );
            if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
                savedStatus = status;
            }
        }
    }
    rclCloseCollection( &collHandle );

    if ( savedStatus < 0 ) {
        return ( savedStatus );
    }
    else if ( status == CAT_NO_ROWS_FOUND ) {
        return ( 0 );
    }
    else {
        return ( status );
    }
}
Esempio n. 11
0
int
_rsStructFileBundle (rsComm_t *rsComm,
structFileExtAndRegInp_t *structFileBundleInp)
{
    int status;
    dataObjInp_t dataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    collInp_t collInp;
    collEnt_t *collEnt = NULL;
    int handleInx;
    int collLen;
    char phyBunDir[MAX_NAME_LEN];
    char tmpPath[MAX_NAME_LEN];
    chkObjPermAndStat_t chkObjPermAndStatInp;
    int l1descInx;
    int savedStatus = 0;
    char *dataType;

    /* open the structured file */
    memset (&dataObjInp, 0, sizeof (dataObjInp));
    dataType = getValByKey (&structFileBundleInp->condInput, DATA_TYPE_KW);
    if (dataType != NULL && strstr (dataType, ZIP_DT_STR) != NULL) {
	/* zipFile type. must end with .zip */
	int len = strlen (structFileBundleInp->objPath);
	if (strcmp (&structFileBundleInp->objPath[len - 4], ".zip") != 0) {
	    strcat (structFileBundleInp->objPath, ".zip");
        }
    }
    rstrcpy (dataObjInp.objPath, structFileBundleInp->objPath, 
      MAX_NAME_LEN);
 
    /* replicate the condInput. may have resource input */
    replKeyVal (&structFileBundleInp->condInput, &dataObjInp.condInput);

    dataObjInp.openFlags = O_WRONLY;  

    if ((structFileBundleInp->oprType & ADD_TO_TAR_OPR) != 0) {
        l1descInx = rsDataObjOpen (rsComm, &dataObjInp);
    } else {
        l1descInx = rsDataObjCreate (rsComm, &dataObjInp);
    }
    if (l1descInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsDataObjCreate of %s error. status = %d",
          dataObjInp.objPath, l1descInx);
        return (l1descInx);
    }
    clearKeyVal (&dataObjInp.condInput);
    l3Close (rsComm, l1descInx);
    L1desc[l1descInx].l3descInx = 0;
    /* zip does not like a zero length file as target */
    if ((structFileBundleInp->oprType & ADD_TO_TAR_OPR) == 0)
        l3Unlink (rsComm, L1desc[l1descInx].dataObjInfo);

    memset (&chkObjPermAndStatInp, 0, sizeof (chkObjPermAndStatInp));
    rstrcpy (chkObjPermAndStatInp.objPath, 
      structFileBundleInp->collection, MAX_NAME_LEN); 
    chkObjPermAndStatInp.flags = CHK_COLL_FOR_BUNDLE_OPR;
    addKeyVal (&chkObjPermAndStatInp.condInput, RESC_NAME_KW,
      L1desc[l1descInx].dataObjInfo->rescName);

    status = rsChkObjPermAndStat (rsComm, &chkObjPermAndStatInp);

    clearKeyVal (&chkObjPermAndStatInp.condInput);

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsChkObjPermAndStat of %s error. stat = %d",
          chkObjPermAndStatInp.objPath, status);
        dataObjCloseInp.l1descInx = l1descInx;
        rsDataObjClose (rsComm, &dataObjCloseInp);
        return (status);
    }

    createPhyBundleDir (rsComm, L1desc[l1descInx].dataObjInfo->filePath,
      phyBunDir);

    bzero (&collInp, sizeof (collInp));
    rstrcpy (collInp.collName, structFileBundleInp->collection, MAX_NAME_LEN);
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG |
      NO_TRIM_REPL_FG | INCLUDE_CONDINPUT_IN_QUERY;
    addKeyVal (&collInp.condInput, RESC_NAME_KW, 
      L1desc[l1descInx].dataObjInfo->rescName);
    handleInx = rsOpenCollection (rsComm, &collInp);
    if (handleInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsOpenCollection of %s error. status = %d",
          collInp.collName, handleInx);
        rmdir (phyBunDir);
        return (handleInx);
    }
    if ((structFileBundleInp->oprType & PRESERVE_COLL_PATH) != 0) {
	/* preserver the last entry of the coll path */
	char *tmpPtr = collInp.collName;
	int tmpLen = 0;
	collLen = 0;
	/* find length to the last '/' */
        while (*tmpPtr != '\0') {
	    if (*tmpPtr == '/') collLen = tmpLen;
	    tmpLen++;
	    tmpPtr++;
	}
    } else {
        collLen = strlen (collInp.collName);
    }
    while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
        if (collEnt->objType == DATA_OBJ_T) {
            if (collEnt->collName[collLen] == '\0') {
                snprintf (tmpPath, MAX_NAME_LEN, "%s/%s",
                  phyBunDir, collEnt->dataName);
            } else {
                snprintf (tmpPath, MAX_NAME_LEN, "%s/%s/%s",
                 phyBunDir, collEnt->collName + collLen + 1, collEnt->dataName);               
	        mkDirForFilePath (UNIX_FILE_TYPE, rsComm, phyBunDir, 
	          tmpPath, getDefDirMode ());
            }
            /* add a link */
            status = link (collEnt->phyPath, tmpPath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "rsStructFileBundle: link error %s to %s. errno = %d",
                  collEnt->phyPath, tmpPath, errno);
                rmLinkedFilesInUnixDir (phyBunDir);
                rmdir (phyBunDir);
                return (UNIX_FILE_LINK_ERR - errno);
            }
        } else {        /* a collection */
	    if ((int) strlen (collEnt->collName) + 1 <= collLen) {
		free (collEnt);
		continue;
	    }
            snprintf (tmpPath, MAX_NAME_LEN, "%s/%s",
              phyBunDir, collEnt->collName + collLen);
            mkdirR (phyBunDir, tmpPath, getDefDirMode ());
	}
	if (collEnt != NULL) {
	    free (collEnt);
	    collEnt = NULL;
	}
    }
    clearKeyVal (&collInp.condInput);
    rsCloseCollection (rsComm, &handleInx);

    status = phyBundle (rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
      collInp.collName, structFileBundleInp->oprType);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: phyBundle of %s error. stat = %d",
          L1desc[l1descInx].dataObjInfo->objPath, status);
	L1desc[l1descInx].bytesWritten = 0;
	savedStatus = status;
    } else {
        /* mark it was written so the size would be adjusted */
        L1desc[l1descInx].bytesWritten = 1;
    }

    rmLinkedFilesInUnixDir (phyBunDir);
    rmdir (phyBunDir);

    dataObjCloseInp.l1descInx = l1descInx;
    status = rsDataObjClose (rsComm, &dataObjCloseInp);

    if (status >= 0)
	return savedStatus;
    else
        return (status);
}
Esempio n. 12
0
    int
    rsNcCreate( rsComm_t *rsComm, ncOpenInp_t *ncCreateInp, int **ncid ) {
        int remoteFlag;
        rodsServerHost_t *rodsServerHost;
        specCollCache_t *specCollCache = NULL;
        int status;
        dataObjInp_t dataObjInp;
        int l1descInx, myncid;

        if ( getValByKey( &ncCreateInp->condInput, NATIVE_NETCDF_CALL_KW ) != NULL ) {
            /* just do nc_open with objPath as file nc file path */
            /* must to be called internally */
            if ( rsComm->proxyUser.authInfo.authFlag < REMOTE_PRIV_USER_AUTH ) {
                return( CAT_INSUFFICIENT_PRIVILEGE_LEVEL );
            }
            status = nc_create( ncCreateInp->objPath, ncCreateInp->mode, &myncid );
            if ( status == NC_NOERR ) {
                *ncid = ( int * ) malloc( sizeof( int ) );
                *( *ncid ) = myncid;
                return 0;
            }
            else {
                rodsLog( LOG_ERROR,
                         "rsNccreate: nc_create %s error, status = %d, %s",
                         ncCreateInp->objPath, status, nc_strerror( status ) );
                return ( NETCDF_OPEN_ERR + status );
            }
        }
        bzero( &dataObjInp, sizeof( dataObjInp ) );
        rstrcpy( dataObjInp.objPath, ncCreateInp->objPath, MAX_NAME_LEN );
        replKeyVal( &ncCreateInp->condInput, &dataObjInp.condInput );
        resolveLinkedPath( rsComm, dataObjInp.objPath, &specCollCache,
                           &dataObjInp.condInput );
        remoteFlag = getAndConnRemoteZone( rsComm, &dataObjInp, &rodsServerHost,
                                           REMOTE_OPEN );

        if ( remoteFlag < 0 ) {
            return ( remoteFlag );
        }
        else if ( remoteFlag == LOCAL_HOST ) {
            addKeyVal( &dataObjInp.condInput, NO_OPEN_FLAG_KW, "" );
            l1descInx = _rsDataObjCreate( rsComm, &dataObjInp );
            clearKeyVal( &dataObjInp.condInput );
            if ( l1descInx < 0 ) {
                return l1descInx;
            }
        
            l1desc_t& my_desc = irods::get_l1desc( l1descInx );
            remoteFlag = resoAndConnHostByDataObjInfo( rsComm,
                         my_desc.dataObjInfo, &rodsServerHost );
            if ( remoteFlag < 0 ) {
                return ( remoteFlag );
            }
            else if ( remoteFlag == LOCAL_HOST ) {
                status = nc_create( my_desc.dataObjInfo->filePath,
                                    ncCreateInp->mode, &myncid );
                if ( status != NC_NOERR ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: nc_open %s error, status = %d, %s",
                             ncCreateInp->objPath, status, nc_strerror( status ) );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
            else {
                /* execute it remotely with dataObjInfo->filePath */
                ncOpenInp_t myNcCreateInp;
                bzero( &myNcCreateInp, sizeof( myNcCreateInp ) );
                rstrcpy( myNcCreateInp.objPath,
                         my_desc.dataObjInfo->filePath, MAX_NAME_LEN );
                addKeyVal( &myNcCreateInp.condInput, NATIVE_NETCDF_CALL_KW, "" );
                status = rcNcCreate( rodsServerHost->conn, &myNcCreateInp, &myncid );
                clearKeyVal( &myNcCreateInp.condInput );
                if ( status < 0 ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: _rcNcCreate %s error, status = %d",
                             myNcCreateInp.objPath, status );
                    freeL1desc( l1descInx );
                    return ( status );
                }
            }
            my_desc.l3descInx = myncid;
            /* need to reg here since NO_OPEN_FLAG_KW does not do it */
            if ( my_desc.dataObjInfo->specColl == NULL ) {
                status = svrRegDataObj( rsComm, my_desc.dataObjInfo );
                if ( status < 0 ) {
                    ncCloseInp_t myNcCloseInp;
                    bzero( &myNcCloseInp, sizeof( myNcCloseInp ) );
                    myNcCloseInp.ncid = l1descInx;
                    irods::server_api_call ( NC_CLOSE_AN, rsComm, &myNcCloseInp );
                    l3Unlink( rsComm, my_desc.dataObjInfo );
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: svrRegDataObj for %s failed, status = %d",
                             my_desc.dataObjInfo->objPath, status );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
        }
        else {
            addKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW, "" );
            status = rcNcCreate( rodsServerHost->conn, ncCreateInp, &myncid );
            /* rm it to avoid confusion */
            rmKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsNcCreate: _rcNcCreate %s error, status = %d",
                         ncCreateInp->objPath, status );
                return ( status );
            }
            l1descInx = allocAndSetL1descForZoneOpr( myncid, &dataObjInp,
                        rodsServerHost, NULL );
        }
        
        l1desc_t& my_desc = irods::get_l1desc( l1descInx );
        my_desc.oprType = NC_CREATE;
        *ncid = ( int * ) malloc( sizeof( int ) );
        *( *ncid ) = l1descInx;

        return 0;
    }
int
rsStructFileExtAndReg (rsComm_t *rsComm,
structFileExtAndRegInp_t *structFileExtAndRegInp)
{
    int status;
    dataObjInp_t dataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    dataObjInfo_t *dataObjInfo;
    int l1descInx;
    rescInfo_t *rescInfo;
    char *rescGroupName;
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    char phyBunDir[MAX_NAME_LEN], *tmpStr;
    int flags = 0;
#if 0
    dataObjInp_t dirRegInp;
    structFileOprInp_t structFileOprInp;
#endif
    specCollCache_t *specCollCache = NULL;

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

    resolveLinkedPath (rsComm, structFileExtAndRegInp->collection, 
      &specCollCache, NULL);

    if (!isSameZone (structFileExtAndRegInp->objPath, 
      structFileExtAndRegInp->collection))
        return SYS_CROSS_ZONE_MV_NOT_SUPPORTED;

    memset (&dataObjInp, 0, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, structFileExtAndRegInp->objPath,
      MAX_NAME_LEN);

    /* replicate the condInput. may have resource input */
    replKeyVal (&structFileExtAndRegInp->condInput, &dataObjInp.condInput);
    dataObjInp.openFlags = O_RDONLY;

    remoteFlag = getAndConnRemoteZone (rsComm, &dataObjInp, &rodsServerHost,
      REMOTE_OPEN);

    if (remoteFlag < 0) {
        return (remoteFlag);
    } else if (remoteFlag == REMOTE_HOST) {
        status = rcStructFileExtAndReg (rodsServerHost->conn, 
          structFileExtAndRegInp);
        return status;
    }

    /* open the structured file */
    addKeyVal (&dataObjInp.condInput, NO_OPEN_FLAG_KW, "");
    l1descInx = _rsDataObjOpen (rsComm, &dataObjInp);

    if (l1descInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileExtAndReg: _rsDataObjOpen of %s error. status = %d",
          dataObjInp.objPath, l1descInx);
        return (l1descInx);
    }

    rescInfo = L1desc[l1descInx].dataObjInfo->rescInfo;
    rescGroupName = L1desc[l1descInx].dataObjInfo->rescGroupName;
    remoteFlag = resolveHostByRescInfo (rescInfo, &rodsServerHost);
    bzero (&dataObjCloseInp, sizeof (dataObjCloseInp));
    dataObjCloseInp.l1descInx = l1descInx;

    if (remoteFlag == REMOTE_HOST) {
        addKeyVal (&structFileExtAndRegInp->condInput, RESC_NAME_KW,
          rescInfo->rescName);

        if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
            return status;
        }
        status = rcStructFileExtAndReg (rodsServerHost->conn,
          structFileExtAndRegInp);

        rsDataObjClose (rsComm, &dataObjCloseInp);


        return status;
    }

    status = chkCollForExtAndReg (rsComm, structFileExtAndRegInp->collection, 
      NULL);
    if (status < 0) return status;


    dataObjInfo = L1desc[l1descInx].dataObjInfo;

    createPhyBundleDir (rsComm, dataObjInfo->filePath, phyBunDir);

    status = unbunPhyBunFile (rsComm, dataObjInp.objPath, rescInfo, 
      dataObjInfo->filePath, phyBunDir, dataObjInfo->dataType, 0);

    if (status == SYS_DIR_IN_VAULT_NOT_EMPTY) {
	/* rename the phyBunDir */
    tmpStr = strdup(phyBunDir); // cppcheck - Undefined behavior: same parameter and destination in snprintf().
	snprintf (phyBunDir, MAX_NAME_LEN, "%s.%-d", tmpStr, (int) random ());
	free(tmpStr);
        status = unbunPhyBunFile (rsComm, dataObjInp.objPath, rescInfo,
          dataObjInfo->filePath, phyBunDir,  dataObjInfo->dataType, 0);
    }
    if (status < 0) {
        rodsLog (LOG_ERROR,
        "rsStructFileExtAndReg:unbunPhyBunFile err for %s to dir %s.stat=%d",
          dataObjInfo->filePath, phyBunDir, status);
        rsDataObjClose (rsComm, &dataObjCloseInp);
        return status;
    }

    if (getValByKey (&structFileExtAndRegInp->condInput, FORCE_FLAG_KW) 
      != NULL) {
	flags = flags | FORCE_FLAG_FLAG;
    }
    if (getValByKey (&structFileExtAndRegInp->condInput, BULK_OPR_KW)
      != NULL) {
        status = bulkRegUnbunSubfiles (rsComm, rescInfo, rescGroupName,
          structFileExtAndRegInp->collection, phyBunDir, flags, NULL);
    } else {
        status = regUnbunSubfiles (rsComm, rescInfo, rescGroupName,
          structFileExtAndRegInp->collection, phyBunDir, flags, NULL);
    }

    if (status == CAT_NO_ROWS_FOUND) {
        /* some subfiles have been deleted. harmless */
        status = 0;
    } else if (status < 0) {
        rodsLog (LOG_ERROR,
          "_rsUnbunAndRegPhyBunfile: rsStructFileExtAndReg for dir %s.stat=%d",
          phyBunDir, status);
    }
    rsDataObjClose (rsComm, &dataObjCloseInp);

    return status;
}