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; }
static int _upload (const char *iRODSPath) { int status; rcComm_t *conn; rodsPathInp_t rodsPathInp; rErrMsg_t errMsg; char bufferPath[MAX_NAME_LEN]; char destiRODSDir[MAX_NAME_LEN]; status = getParentDir(iRODSPath, destiRODSDir); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: failed to get parent dir - %s", iRODSPath); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: failed to get Buffered lazy upload file path - %s", iRODSPath); return status; } // set src path memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) ); addSrcInPath( &rodsPathInp, bufferPath ); status = parseLocalPath (&rodsPathInp.srcPath[0]); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: parseLocalPath error : %d", status); return status; } // set dest path rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) ); rstrcpy( rodsPathInp.destPath->inPath, destiRODSDir, MAX_NAME_LEN ); status = parseRodsPath (rodsPathInp.destPath, LazyUploadRodsEnv); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: parseRodsPath error : %d", status); return status; } // Connect conn = rcConnect (LazyUploadRodsEnv->rodsHost, LazyUploadRodsEnv->rodsPort, LazyUploadRodsEnv->rodsUserName, LazyUploadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg); if (conn == NULL) { rodsLog (LOG_DEBUG, "_upload: error occurred while connecting to irods"); return -EPIPE; } // Login if (strcmp (LazyUploadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { status = clientLogin(conn); if (status != 0) { rodsLog (LOG_DEBUG, "_upload: ClientLogin error : %d", status); rcDisconnect(conn); return status; } } // upload Buffered file rodsLog (LOG_DEBUG, "_upload: upload %s", bufferPath); bool prev = LazyUploadRodsArgs->force; LazyUploadRodsArgs->force = True; status = putUtil (&conn, LazyUploadRodsEnv, LazyUploadRodsArgs, &rodsPathInp); LazyUploadRodsArgs->force = prev; rodsLog (LOG_DEBUG, "_upload: complete uploading %s -> %s", bufferPath, destiRODSDir); // Disconnect rcDisconnect(conn); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: putUtil error : %d", status); return status; } return 0; }