示例#1
0
文件: cpUtil.cpp 项目: bpow/irods
int
cpUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
        rodsPathInp_t *rodsPathInp ) {
    if ( rodsPathInp == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    int savedStatus = resolveRodsTarget( conn, rodsPathInp, 1 );
    if ( savedStatus < 0 ) {
        rodsLogError( LOG_ERROR, savedStatus,
                      "cpUtil: resolveRodsTarget error, status = %d", savedStatus );
        return savedStatus;
    }

    dataObjCopyInp_t dataObjCopyInp;
    rodsRestart_t rodsRestart;
    initCondForCp( myRodsEnv, myRodsArgs, &dataObjCopyInp, &rodsRestart );

    /* initialize the progress struct */
    if ( gGuiProgressCB != NULL ) {
        bzero( &conn->operProgress, sizeof( conn->operProgress ) );
        for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
            rodsPath_t * targPath = &rodsPathInp->targPath[i];
            if ( targPath->objType == DATA_OBJ_T ) {
                conn->operProgress.totalNumFiles++;
                if ( rodsPathInp->srcPath[i].size > 0 ) {
                    conn->operProgress.totalFileSize +=
                        rodsPathInp->srcPath[i].size;
                }
            }
            else {
                getCollSizeForProgStat( conn, rodsPathInp->srcPath[i].outPath,
                                        &conn->operProgress );
            }
        }
    }

    for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
        rodsPath_t * targPath = &rodsPathInp->targPath[i];

        if ( rodsPathInp->srcPath[i].rodsObjStat != NULL &&
                rodsPathInp->srcPath[i].rodsObjStat->specColl != NULL ) {
            dataObjCopyInp.srcDataObjInp.specColl =
                rodsPathInp->srcPath[i].rodsObjStat->specColl;
        }

        int status = 0;
        if ( targPath->objType == DATA_OBJ_T ) {
            rmKeyVal( &dataObjCopyInp.srcDataObjInp.condInput,
                      TRANSLATED_PATH_KW );
            status = cpFileUtil( conn, rodsPathInp->srcPath[i].outPath,
                                 targPath->outPath, rodsPathInp->srcPath[i].size,
                                 myRodsArgs, &dataObjCopyInp );
        }
        else if ( targPath->objType == COLL_OBJ_T ) {
            setStateForRestart( &rodsRestart, targPath, myRodsArgs );
            addKeyVal( &dataObjCopyInp.srcDataObjInp.condInput,
                       TRANSLATED_PATH_KW, "" );
            status = cpCollUtil( conn, rodsPathInp->srcPath[i].outPath,
                                 targPath->outPath, myRodsEnv, myRodsArgs, &dataObjCopyInp,
                                 &rodsRestart );
            if ( rodsRestart.fd > 0 && status < 0 ) {
                close( rodsRestart.fd );
                return status;
            }
            if ( dataObjCopyInp.srcDataObjInp.specColl != NULL &&
                    dataObjCopyInp.srcDataObjInp.specColl->collClass == STRUCT_FILE_COLL ) {
                dataObjCopyInp.srcDataObjInp.specColl = NULL;
                status = cpCollUtil( conn, rodsPathInp->srcPath[i].outPath,
                                     targPath->outPath, myRodsEnv, myRodsArgs, &dataObjCopyInp,
                                     &rodsRestart );
            }
        }
        else {
            /* should not be here */
            rodsLog( LOG_ERROR,
                     "cpUtil: invalid cp dest objType %d for %s",
                     targPath->objType, targPath->outPath );
            return USER_INPUT_PATH_ERR;
        }
        /* XXXX may need to return a global status */
        if ( status < 0 &&
                status != CAT_NO_ROWS_FOUND &&
                status != SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
            rodsLogError( LOG_ERROR, status,
                          "cpUtil: cp error for %s, status = %d",
                          targPath->outPath, status );
            savedStatus = status;
        }
    }

    if ( rodsRestart.fd > 0 ) {
        close( rodsRestart.fd );
    }
    return savedStatus;
}
示例#2
0
int
getUtil (rcComm_t **myConn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
rodsPathInp_t *rodsPathInp)
{
    int i;
    int status; 
    int savedStatus = 0;
    rodsPath_t *targPath;
    dataObjInp_t dataObjOprInp;
    rodsRestart_t rodsRestart;
    rcComm_t *conn = *myConn;

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

    if (myRodsArgs->ticket == True) {
       if (myRodsArgs->ticketString == NULL) {
	  rodsLog (LOG_ERROR,
		   "initCondForPut: NULL ticketString error");
	  return (USER__NULL_INPUT_ERR);
       } else {
	  setSessionTicket(conn, myRodsArgs->ticketString);
       }
    }

    initCondForGet (conn, myRodsEnv, myRodsArgs, &dataObjOprInp, &rodsRestart);

    if (rodsPathInp->resolved == False) {
        status = resolveRodsTarget (conn, myRodsEnv, rodsPathInp, 1);
        if (status < 0) {
            rodsLogError (LOG_ERROR, status,
              "getUtil: resolveRodsTarget");
            return (status);
	}
	rodsPathInp->resolved = True;
    }

    /* initialize the progress struct */
    if (gGuiProgressCB != NULL) {
        bzero (&conn->operProgress, sizeof (conn->operProgress));
	for (i = 0; i < rodsPathInp->numSrc; i++) {
	    targPath = &rodsPathInp->targPath[i];
            if (targPath->objType == LOCAL_FILE_T) {
                conn->operProgress.totalNumFiles++;
		if (rodsPathInp->srcPath[i].size > 0) {
                    conn->operProgress.totalFileSize += 
		      rodsPathInp->srcPath[i].size;
		}
	    } else {
		getCollSizeForProgStat (conn, rodsPathInp->srcPath[i].outPath,
		  &conn->operProgress);
	    }
	}
    }

    if (conn->fileRestart.flags == FILE_RESTART_ON) {
        fileRestartInfo_t *info;
        status = readLfRestartFile (conn->fileRestart.infoFile, &info);
        if (status >= 0) {
            status = lfRestartGetWithInfo (conn, info);
            if (status >= 0) {
                /* save info so we know what got restarted and what not to
                 * delete in setStateForResume */
                rstrcpy (conn->fileRestart.info.objPath, info->objPath,
                  MAX_NAME_LEN);
                rstrcpy (conn->fileRestart.info.fileName, info->fileName,
                  MAX_NAME_LEN);
                conn->fileRestart.info.status = FILE_RESTARTED;
                printf ("%s was restarted successfully\n",
                  conn->fileRestart.info.objPath);
                unlink (conn->fileRestart.infoFile);
            }
            if (info != NULL) free (info);
        }
    }

    for (i = 0; i < rodsPathInp->numSrc; i++) {
        targPath = &rodsPathInp->targPath[i];

	if (rodsPathInp->srcPath[i].rodsObjStat != NULL &&
	  rodsPathInp->srcPath[i].rodsObjStat->specColl != NULL) {
	    dataObjOprInp.specColl = 
	      rodsPathInp->srcPath[i].rodsObjStat->specColl;
	} else {
	    dataObjOprInp.specColl = NULL;
	}
	if (targPath->objType == LOCAL_FILE_T) {
	    rmKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW);
	    status = getDataObjUtil (conn, rodsPathInp->srcPath[i].outPath, 
	     targPath->outPath, rodsPathInp->srcPath[i].size,
	      rodsPathInp->srcPath[i].objMode, myRodsEnv, 
	      myRodsArgs, &dataObjOprInp);
	} else if (targPath->objType ==  LOCAL_DIR_T) {
            setStateForRestart (conn, &rodsRestart, targPath, myRodsArgs);
            /* The path given by collEnt.collName from rclReadCollection 
             * has already been translated */
	    addKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW, "");
	    status = getCollUtil (myConn, rodsPathInp->srcPath[i].outPath,
              targPath->outPath, myRodsEnv, myRodsArgs, &dataObjOprInp,
	      &rodsRestart);
#if 0
            if (rodsRestart.fd > 0 && status < 0) {
                close (rodsRestart.fd);
                return (status);
            }
#endif
	} else {
	    /* should not be here */
	    rodsLog (LOG_ERROR,
	     "getUtil: invalid get dest objType %d for %s", 
	      targPath->objType, targPath->outPath);
	    return (USER_INPUT_PATH_ERR);
	}
	/* XXXX may need to return a global status */
	if (status < 0) {
            rodsLogError (LOG_ERROR, status,
             "getUtil: get error for %s", 
	      targPath->outPath);
	    savedStatus = status;
	    break;
	} 
    }

    if (rodsRestart.fd > 0) {
        close (rodsRestart.fd);
    }
    if (savedStatus < 0) {
        status = savedStatus;
    } else if (status == CAT_NO_ROWS_FOUND) {
        status = 0;
    }

    if (status < 0 && myRodsArgs->retries == True) {
        int reconnFlag;
        /* this is recursive. Only do it the first time */
        myRodsArgs->retries = False;
        if (myRodsArgs->reconnect == True) {
            reconnFlag = RECONN_TIMEOUT;
        } else {
            reconnFlag = NO_RECONN;
        }
        while (myRodsArgs->retriesValue > 0) {
            rErrMsg_t errMsg;
            bzero (&errMsg, sizeof (errMsg));
            status = rcReconnect (myConn, myRodsEnv->rodsHost, myRodsEnv,
              reconnFlag);
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                 "getUtil: rcReconnect error for %s", targPath->outPath);
                return status;
            }
            status = getUtil (myConn,  myRodsEnv, myRodsArgs, rodsPathInp);
            if (status >= 0) {
                printf ("Retry get successful\n");
                break;
            } else {
                rodsLogError (LOG_ERROR, status,
                 "getUtil: retry getUtil error");
            }
            myRodsArgs->retriesValue--;
        }
    }
    return status;
}
示例#3
0
int
replUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
          rodsPathInp_t *rodsPathInp ) {
    int i = 0;
    int status = 0;
    int savedStatus = 0;
    dataObjInp_t dataObjInp;
    rodsRestart_t rodsRestart;


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

    initCondForRepl( myRodsEnv, myRodsArgs, &dataObjInp, &rodsRestart );

    for ( i = 0; i < rodsPathInp->numSrc; i++ ) {
        if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
            getRodsObjType( conn, &rodsPathInp->srcPath[i] );
            if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
                rodsLog( LOG_ERROR,
                         "replUtil: srcPath %s does not exist",
                         rodsPathInp->srcPath[i].outPath );
                savedStatus = USER_INPUT_PATH_ERR;
                continue;
            }
        }
    }

    /* initialize the progress struct */
    if ( gGuiProgressCB != NULL ) {
        bzero( &conn->operProgress, sizeof( conn->operProgress ) );
        for ( i = 0; i < rodsPathInp->numSrc; i++ ) {
            if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
                conn->operProgress.totalNumFiles++;
                if ( rodsPathInp->srcPath[i].size > 0 ) {
                    conn->operProgress.totalFileSize +=
                        rodsPathInp->srcPath[i].size;
                }
            }
            else if ( rodsPathInp->srcPath[i].objType ==  COLL_OBJ_T ) {
                getCollSizeForProgStat( conn, rodsPathInp->srcPath[i].outPath,
                                        &conn->operProgress );
            }
        }
    }

    for ( i = 0; i < rodsPathInp->numSrc; i++ ) {
        if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
            rmKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW );
            status = replDataObjUtil( conn, rodsPathInp->srcPath[i].outPath,
                                      rodsPathInp->srcPath[i].size, myRodsEnv, myRodsArgs, &dataObjInp );
        }
        else if ( rodsPathInp->srcPath[i].objType ==  COLL_OBJ_T ) {
            setStateForRestart( conn, &rodsRestart, &rodsPathInp->srcPath[i],
                                myRodsArgs );
            addKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW, "" );
            status = replCollUtil( conn, rodsPathInp->srcPath[i].outPath,
                                   myRodsEnv, myRodsArgs, &dataObjInp, &rodsRestart );
            if ( rodsRestart.fd > 0 && status < 0 ) {
                close( rodsRestart.fd );
                return ( status );
            }
        }
        else {
            /* should not be here */
            rodsLog( LOG_ERROR,
                     "replUtil: invalid repl objType %d for %s",
                     rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
            return ( USER_INPUT_PATH_ERR );
        }
        /* XXXX may need to return a global status */
        if ( status < 0 ) {
            rodsLogError( LOG_ERROR, status,
                          "replUtil: repl error for %s, status = %d",
                          rodsPathInp->srcPath[i].outPath, status );
            savedStatus = status;
        }
    }
    if ( savedStatus < 0 ) {
        return ( savedStatus );
    }
    else if ( status == CAT_NO_ROWS_FOUND ) {
        return ( 0 );
    }
    else {
        return ( status );
    }
}