Ejemplo n.º 1
0
int
bunUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
         rodsPathInp_t *rodsPathInp ) {
    rodsPath_t *collPath, *structFilePath;
    structFileExtAndRegInp_t structFileExtAndRegInp;

    if ( rodsPathInp == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    int savedStatus = initCondForBunOpr( myRodsEnv, myRodsArgs, &structFileExtAndRegInp );
    if ( savedStatus < 0 ) {
        return savedStatus;
    }

    for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
        collPath = &rodsPathInp->destPath[i];	/* iRODS Collection */
        structFilePath = &rodsPathInp->srcPath[i];	/* iRODS StructFile */

        getRodsObjType( conn, collPath );

        rstrcpy( structFileExtAndRegInp.collection, collPath->outPath,
                 MAX_NAME_LEN );
        rstrcpy( structFileExtAndRegInp.objPath, structFilePath->outPath,
                 MAX_NAME_LEN );

        int status = 0;
        if ( myRodsArgs->extract == True ) {		/* -x */
            if ( myRodsArgs->condition == True ) {
                rodsLog( LOG_ERROR, "bunUtil: cannot use -x and -c at the same time" );
                return -1;
            }
            status = rcStructFileExtAndReg( conn, &structFileExtAndRegInp );
        }
        else if ( myRodsArgs->condition == True ) {  /* -c - create */
            status = rcStructFileBundle( conn, &structFileExtAndRegInp );
        }
        else if ( myRodsArgs->add == True ) {  /* add to tar */ // JMC - backport 4643
            status = rcStructFileBundle( conn, &structFileExtAndRegInp );
        }
        else {
            rodsLog( LOG_ERROR,
                     "bunUtil: -x or -c must be specified" );
            return -1;
        }

        /* XXXX may need to return a global status */
        if ( status < 0 &&
                status != CAT_NO_ROWS_FOUND ) {
            if ( status == SYS_CACHE_STRUCT_FILE_RESC_ERR &&
                    myRodsArgs->condition == True ) {
                rodsLogError( LOG_ERROR, status,
                              "bunUtil: A resc must be entered for non-existing structFile" );
            }
            else {
                rodsLogError( LOG_ERROR, status,
                              "bunUtil: opr error for %s, status = %d",
                              collPath->outPath, status );
                savedStatus = status;
            }
        }
    }
    return savedStatus;
}
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;
}