int mvUtil( rcComm_t *conn, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp ) { if ( rodsPathInp == NULL ) { return USER__NULL_INPUT_ERR; } dataObjCopyInp_t dataObjRenameInp; initCondForMv( &dataObjRenameInp ); int savedStatus = resolveRodsTarget( conn, rodsPathInp, MOVE_OPR ); if ( savedStatus < 0 ) { rodsLogError( LOG_ERROR, savedStatus, "mvUtil: resolveRodsTarget error, status = %d", savedStatus ); return savedStatus; } for ( int i = 0; i < rodsPathInp->numSrc; i++ ) { rodsPath_t * targPath = &rodsPathInp->targPath[i]; int status = mvObjUtil( conn, rodsPathInp->srcPath[i].outPath, targPath->outPath, targPath->objType, myRodsArgs, &dataObjRenameInp ); /* XXXX may need to return a global status */ if ( status < 0 && status != CAT_NO_ROWS_FOUND ) { rodsLogError( LOG_ERROR, status, "mvUtil: mv error for %s, status = %d", targPath->outPath, status ); savedStatus = status; } } return savedStatus; }
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; }
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; }
int putUtil( rcComm_t **myConn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp ) { int i; int status; int savedStatus = 0; rodsPath_t *targPath = 0; dataObjInp_t dataObjOprInp; bulkOprInp_t bulkOprInp; 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 ); } } status = initCondForPut( conn, myRodsEnv, myRodsArgs, &dataObjOprInp, &bulkOprInp, &rodsRestart ); if ( status < 0 ) { return status; } if ( rodsPathInp->resolved == False ) { status = resolveRodsTarget( conn, rodsPathInp, 1 ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "putUtil: resolveRodsTarget error, status = %d", status ); 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 == DATA_OBJ_T ) { conn->operProgress.totalNumFiles++; if ( rodsPathInp->srcPath[i].size > 0 ) { conn->operProgress.totalFileSize += rodsPathInp->srcPath[i].size; } } else { getDirSizeForProgStat( myRodsArgs, 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 = lfRestartPutWithInfo( conn, info ); if ( status >= 0 ) { /* save info so we know what got restarted */ rstrcpy( conn->fileRestart.info.objPath, info->objPath, MAX_NAME_LEN ); conn->fileRestart.info.status = FILE_RESTARTED; printf( "%s was restarted successfully\n", conn->fileRestart.info.objPath ); unlink( conn->fileRestart.infoFile ); } free( info ); } } for ( i = 0; i < rodsPathInp->numSrc; i++ ) { targPath = &rodsPathInp->targPath[i]; if ( targPath->objType == DATA_OBJ_T ) { if ( isPathSymlink( myRodsArgs, rodsPathInp->srcPath[i].outPath ) > 0 ) { continue; } dataObjOprInp.createMode = rodsPathInp->srcPath[i].objMode; status = putFileUtil( conn, rodsPathInp->srcPath[i].outPath, targPath->outPath, rodsPathInp->srcPath[i].size, myRodsArgs, &dataObjOprInp ); } else if ( targPath->objType == COLL_OBJ_T ) { setStateForRestart( &rodsRestart, targPath, myRodsArgs ); if ( myRodsArgs->bulk == True ) { status = bulkPutDirUtil( myConn, rodsPathInp->srcPath[i].outPath, targPath->outPath, myRodsEnv, myRodsArgs, &dataObjOprInp, &bulkOprInp, &rodsRestart ); } else { status = putDirUtil( myConn, rodsPathInp->srcPath[i].outPath, targPath->outPath, myRodsEnv, myRodsArgs, &dataObjOprInp, &bulkOprInp, &rodsRestart, NULL ); } } else { /* should not be here */ rodsLog( LOG_ERROR, "putUtil: invalid put 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, "putUtil: put error for %s, status = %d", targPath->outPath, status ); 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, "putUtil: rcReconnect error for %s", targPath->outPath ); return status; } status = putUtil( myConn, myRodsEnv, myRodsArgs, rodsPathInp ); if ( status >= 0 ) { printf( "Retry put successful\n" ); break; } else { rodsLogError( LOG_ERROR, status, "putUtil: retry putUtil error" ); } myRodsArgs->retriesValue--; } } return status; }
int rsyncUtil (rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp) { int i; int status; int savedStatus = 0; rodsPath_t *srcPath, *targPath; dataObjInp_t dataObjOprInp; dataObjCopyInp_t dataObjCopyInp; if (rodsPathInp == NULL) { return (USER__NULL_INPUT_ERR); } status = resolveRodsTarget (conn, myRodsEnv, rodsPathInp, RSYNC_OPR); if (status < 0) { rodsLogError (LOG_ERROR, status, "rsyncUtil: resolveRodsTarget"); return (status); } if (rodsPathInp->srcPath[0].objType <= COLL_OBJ_T && rodsPathInp->targPath[0].objType <= COLL_OBJ_T) { initCondForIrodsToIrodsRsync (myRodsEnv, myRodsArgs, &dataObjCopyInp); } else { initCondForRsync (myRodsEnv, myRodsArgs, &dataObjOprInp); } for (i = 0; i < rodsPathInp->numSrc; i++) { int srcType, targType; targPath = &rodsPathInp->targPath[i]; srcPath = &rodsPathInp->srcPath[i]; srcType = srcPath->objType; targType = targPath->objType; if (srcPath->objState != EXIST_ST) { rodsLog (LOG_ERROR, "rsyncUtil: Source path %s does not exist"); return USER_INPUT_PATH_ERR; } if (srcPath->objType <= COLL_OBJ_T && srcPath->rodsObjStat != NULL && rodsPathInp->srcPath[i].rodsObjStat->specColl != NULL) { dataObjOprInp.specColl = dataObjCopyInp.srcDataObjInp.specColl = srcPath->rodsObjStat->specColl; } else { dataObjOprInp.specColl = dataObjCopyInp.srcDataObjInp.specColl = NULL; } if (srcType == DATA_OBJ_T && targType == LOCAL_FILE_T) { rmKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW); status = rsyncDataToFileUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjOprInp); } else if (srcType == LOCAL_FILE_T && targType == DATA_OBJ_T) { if (isPathSymlink (myRodsArgs, srcPath->outPath) > 0) continue; dataObjOprInp.createMode = rodsPathInp->srcPath[i].objMode; #ifdef FILESYSTEM_META getFileMetaFromPath(rodsPathInp->srcPath[i].outPath, &dataObjOprInp.condInput); #endif status = rsyncFileToDataUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjOprInp); } else if (srcType == DATA_OBJ_T && targType == DATA_OBJ_T) { rmKeyVal (&dataObjCopyInp.srcDataObjInp.condInput, TRANSLATED_PATH_KW); addKeyVal (&dataObjCopyInp.destDataObjInp.condInput, REG_CHKSUM_KW, ""); status = rsyncDataToDataUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjCopyInp); } else if (srcType == COLL_OBJ_T && targType == LOCAL_DIR_T) { /* The path given by collEnt.collName from rclReadCollection * has already been translated */ addKeyVal (&dataObjOprInp.condInput, TRANSLATED_PATH_KW, ""); status = rsyncCollToDirUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjOprInp); if (status >= 0 && dataObjOprInp.specColl != NULL && dataObjOprInp.specColl->collClass == STRUCT_FILE_COLL) { dataObjOprInp.specColl = NULL; status = rsyncCollToDirUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjOprInp); } } else if (srcType == LOCAL_DIR_T && targType == COLL_OBJ_T) { status = rsyncDirToCollUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjOprInp); } else if (srcType == COLL_OBJ_T && targType == COLL_OBJ_T) { addKeyVal (&dataObjCopyInp.srcDataObjInp.condInput, TRANSLATED_PATH_KW, ""); addKeyVal (&dataObjCopyInp.destDataObjInp.condInput, REG_CHKSUM_KW, ""); status = rsyncCollToCollUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjCopyInp); if (status >= 0 && dataObjOprInp.specColl != NULL && dataObjCopyInp.srcDataObjInp.specColl->collClass == STRUCT_FILE_COLL) { dataObjCopyInp.srcDataObjInp.specColl = NULL; status = rsyncCollToCollUtil (conn, srcPath, targPath, myRodsEnv, myRodsArgs, &dataObjCopyInp); } } else { /* should not be here */ rodsLog (LOG_ERROR, "rsyncUtil: invalid srcType %d and targType %d combination for %s", srcType, targType, targPath->outPath); return (USER_INPUT_PATH_ERR); } /* XXXX may need to return a global status */ if (status < 0) { rodsLogError (LOG_ERROR, status, "rsyncUtil: rsync error for %s", targPath->outPath); savedStatus = status; } } if (savedStatus < 0) { return (savedStatus); } else if (status == CAT_NO_ROWS_FOUND || status == SYS_SPEC_COLL_OBJ_NOT_EXIST) { return (0); } else { return (status); } }