int irods_reli_putfile ( const char *host, const char *path, const char *local_path ) { dataObjInp_t request; int result; struct irods_server *server = connect_to_host(host); if(!server) return -1; memset(&request,0,sizeof(request)); strcpy(request.objPath,path); request.numThreads = 0; // server chooses threads request.openFlags = O_CREAT|O_WRONLY; addKeyVal (&request.condInput, FORCE_FLAG_KW, ""); addKeyVal (&request.condInput, ALL_KW, ""); debug(D_IRODS,"rcDataObjPut %s %s %s",host,path,local_path); result = rcDataObjPut(server->conn,&request,(char*)local_path); debug(D_IRODS,"= %d",result); clearKeyVal (&request.condInput); if(result<0) { errno = irods_reli_errno(result); return -1; } return 0; }
/** * \fn rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) * * \brief Execute my rule. * * \user client * * \ingroup rules * * \since 1.0 * * * \remark none * * \note none * * \param[in] conn - A rcComm_t connection handle to the server. * \param[in] execMyRuleInp * \param[out] outParamArray * * \return integer * \retval 0 on success. * \sideeffect none * \pre none * \post none * \sa none **/ int rcExecMyRule( rcComm_t *conn, execMyRuleInp_t *execMyRuleInp, msParamArray_t **outParamArray ) { int status = procApiRequest( conn, EXEC_MY_RULE_AN, execMyRuleInp, NULL, ( void ** )outParamArray, NULL ); while ( status == SYS_SVR_TO_CLI_MSI_REQUEST ) { /* it is a server request */ msParam_t *myParam = NULL, *putParam = NULL; if ( ( myParam = putParam = getMsParamByLabel( *outParamArray, CL_PUT_ACTION ) ) || ( myParam = getMsParamByLabel( *outParamArray, CL_GET_ACTION ) ) ) { //putParam is non-null if it's a put, null if it's a get dataObjInp_t * dataObjInp = ( dataObjInp_t * ) myParam->inOutStruct; char * locFilePath; char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN]; // locFilePath should be the return of getValByKey if it exists, // otherwise use the filename from splitPathByKey if ( ( locFilePath = getValByKey( &dataObjInp->condInput, LOCAL_PATH_KW ) ) || ( ( status = splitPathByKey( dataObjInp->objPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) >= 0 && ( locFilePath = ( char * ) myFile ) ) ) { status = putParam ? rcDataObjPut( conn, dataObjInp, locFilePath ) : rcDataObjGet( conn, dataObjInp, locFilePath ); rcOprComplete( conn, status ); } else { rodsLogError( LOG_ERROR, status, "rcExecMyRule: splitPathByKey for %s error", dataObjInp->objPath ); rcOprComplete( conn, USER_FILE_DOES_NOT_EXIST ); } clearKeyVal( &dataObjInp->condInput ); } else { rcOprComplete( conn, SYS_SVR_TO_CLI_MSI_NO_EXIST ); } /* free outParamArray */ clearMsParamArray( *outParamArray, 1 ); free( *outParamArray ); *outParamArray = NULL; /* read the reply from the earlier call */ status = branchReadAndProcApiReply( conn, EXEC_MY_RULE_AN, ( void ** )outParamArray, NULL ); if ( status < 0 ) { rodsLogError( LOG_DEBUG, status, "rcExecMyRule: readAndProcApiReply failed. status = %d", status ); } } return status; }
int RodsConnection::putFile(const std::string &localPath, const std::string &objPath, const std::string &rodsResc, unsigned int numThreads) { dataObjInp_t putParam; char filePath[MAX_NAME_LEN]; rodsLong_t size = 0; int status = 0; // get file size std::ifstream fileStream(localPath.c_str(), std::ifstream::binary); fileStream.seekg(0, fileStream.end); size = fileStream.tellg(); fileStream.close(); this->mutexLock(); // zero rods api input params structure memset(&putParam, 0, sizeof(dataObjInp_t)); // initialize rods api input params struct putParam.dataSize = size; putParam.oprType = PUT_OPR; putParam.numThreads = numThreads; // set remote object path rstrcpy(putParam.objPath, objPath.c_str(), MAX_NAME_LEN); // for now, we use the generic data type addKeyVal(&putParam.condInput, DATA_TYPE_KW, "generic"); // target storage resource, if defined if (rodsResc.length()) addKeyVal(&putParam.condInput, DEST_RESC_NAME_KW, rodsResc.c_str()); // take copy of the local file path for the rods api strcpy(filePath, localPath.c_str()); // call rods api status = rcDataObjPut(this->rodsCommPtr, &putParam, filePath); this->mutexUnlock(); // return rods api status return (status); }
int ifusePut( rcComm_t *conn, char *objPath, char *cachePath, int mode, rodsLong_t srcSize ) { dataObjInp_t dataObjInp; int status; memset( &dataObjInp, 0, sizeof( dataObjInp ) ); rstrcpy( dataObjInp.objPath, objPath, MAX_NAME_LEN ); dataObjInp.dataSize = srcSize; dataObjInp.createMode = mode; dataObjInp.openFlags = O_RDWR; addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" ); addKeyVal( &dataObjInp.condInput, DATA_TYPE_KW, "generic" ); if ( strlen( MyRodsEnv.rodsDefResource ) > 0 ) { addKeyVal( &dataObjInp.condInput, DEST_RESC_NAME_KW, MyRodsEnv.rodsDefResource ); } status = rcDataObjPut( conn, &dataObjInp, cachePath ); return ( status ); }
int rcDataObjRsync (rcComm_t *conn, dataObjInp_t *dataObjInp) { int status; msParamArray_t *outParamArray = NULL; char *locFilePath; status = _rcDataObjRsync (conn, dataObjInp, &outParamArray); if (status == SYS_SVR_TO_CLI_PUT_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } else if (status == SYS_SVR_TO_CLI_GET_ACTION) { if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { return USER_INPUT_PATH_ERR; } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (status >= 0) { return SYS_RSYNC_TARGET_MODIFIED; } else { return status; } } } /* below is for backward compatibility */ while (status == SYS_SVR_TO_CLI_MSI_REQUEST) { /* it is a server request */ msParam_t *myMsParam; dataObjInp_t *dataObjInp = NULL; int l1descInx; myMsParam = getMsParamByLabel (outParamArray, CL_ZONE_OPR_INX); if (myMsParam == NULL) { l1descInx = -1; } else { l1descInx = *(int*) myMsParam->inOutStruct; } if ((myMsParam = getMsParamByLabel (outParamArray, CL_PUT_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjPut (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else if ((myMsParam = getMsParamByLabel (outParamArray, CL_GET_ACTION)) != NULL) { dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct; if ((locFilePath = getValByKey (&dataObjInp->condInput, RSYNC_DEST_PATH_KW)) == NULL) { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST); } } else { status = rcDataObjGet (conn, dataObjInp, locFilePath); if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, status); } } } else { if (l1descInx >= 0) { rcOprComplete (conn, l1descInx); } else { rcOprComplete (conn, SYS_SVR_TO_CLI_MSI_NO_EXIST); } } /* free outParamArray */ if (dataObjInp != NULL) { clearKeyVal (&dataObjInp->condInput); } clearMsParamArray (outParamArray, 1); free (outParamArray); /* read the reply from the eariler call */ status = branchReadAndProcApiReply (conn, DATA_OBJ_RSYNC_AN, (void **)&outParamArray, NULL); if (status < 0) { rodsLogError (LOG_DEBUG, status, "rcDataObjRsync: readAndProcApiReply failed. status = %d", status); } } return (status); }
int putFileUtil( rcComm_t *conn, char *srcPath, char *targPath, rodsLong_t srcSize, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp ) { int status; struct timeval startTime, endTime; if ( srcPath == NULL || targPath == NULL ) { rodsLog( LOG_ERROR, "putFileUtil: NULL srcPath or targPath input" ); return USER__NULL_INPUT_ERR; } if ( conn->fileRestart.info.status == FILE_RESTARTED && strcmp( conn->fileRestart.info.objPath, targPath ) == 0 ) { /* it was restarted */ conn->fileRestart.info.status = FILE_NOT_RESTART; return 0; } if ( rodsArgs->verbose == True ) { ( void ) gettimeofday( &startTime, ( struct timezone * )0 ); } if ( gGuiProgressCB != NULL ) { rstrcpy( conn->operProgress.curFileName, srcPath, MAX_NAME_LEN ); conn->operProgress.curFileSize = srcSize; conn->operProgress.curFileSizeDone = 0; conn->operProgress.flag = 0; gGuiProgressCB( &conn->operProgress ); } /* have to take care of checksum here since it needs to be recalculated */ if ( rodsArgs->checksum == True ) { // set the expected flag to indicate that we want a server-side // checksum computed and stored in the catalog addKeyVal( &dataObjOprInp->condInput, REG_CHKSUM_KW, "" ); } else if ( rodsArgs->verifyChecksum == True ) { rodsEnv env; int ret = getRodsEnv( &env ); if ( ret < 0 ) { rodsLog( LOG_ERROR, "putFileUtil - failed to capture rods env %d", ret ); return ret; } status = rcChksumLocFile( srcPath, VERIFY_CHKSUM_KW, &dataObjOprInp->condInput, env.rodsDefaultHashScheme ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "putFileUtil: rcChksumLocFile error for %s, status = %d", srcPath, status ); return status; } } if ( strlen( targPath ) >= MAX_PATH_ALLOWED - 1 ) { return USER_PATH_EXCEEDS_MAX; } rstrcpy( dataObjOprInp->objPath, targPath, MAX_NAME_LEN ); dataObjOprInp->dataSize = srcSize; status = rcDataObjPut( conn, dataObjOprInp, srcPath ); if ( status >= 0 ) { if ( rodsArgs->verbose == True ) { ( void ) gettimeofday( &endTime, ( struct timezone * )0 ); printTiming( conn, dataObjOprInp->objPath, srcSize, srcPath, &startTime, &endTime ); } if ( gGuiProgressCB != NULL ) { conn->operProgress.totalNumFilesDone++; conn->operProgress.totalFileSizeDone += srcSize; } } return status; }
int rsyncFileToDataUtil (rcComm_t *conn, rodsPath_t *srcPath, rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, dataObjInp_t *dataObjOprInp) { int status; struct timeval startTime, endTime; int putFlag = 0; int syncFlag = 0; char *chksum; if (srcPath == NULL || targPath == NULL) { rodsLog (LOG_ERROR, "rsyncFileToDataUtil: NULL srcPath or targPath input"); return (USER__NULL_INPUT_ERR); } /* check the age */ if (myRodsArgs->age == True) { #ifndef windows_platform struct stat statbuf; status = stat (srcPath->outPath, &statbuf); #else struct irodsntstat statbuf; status = iRODSNt_stat(srcPath->outPath, &statbuf); #endif if (status < 0) { rodsLog (LOG_ERROR, "rsyncFileToDataUtil: stat error for %s, errno = %d\n", srcPath->outPath, errno); return (USER_INPUT_PATH_ERR); } if (ageExceeded (myRodsArgs->agevalue, statbuf.st_mtime, myRodsArgs->verbose, srcPath->outPath, srcPath->size)) return 0; } if (myRodsArgs->verbose == True) { (void) gettimeofday(&startTime, (struct timezone *)0); bzero (&conn->transStat, sizeof (transStat_t)); } if (targPath->objState == NOT_EXIST_ST) { putFlag = 1; } else if (myRodsArgs->sizeFlag == True) { /* sync by size */ if (targPath->size != srcPath->size) { putFlag = 1; } } else if (strlen (targPath->chksum) > 0) { /* src has a checksum value */ status = rcChksumLocFile (srcPath->outPath, RSYNC_CHKSUM_KW, &dataObjOprInp->condInput, extractHashFunction3(myRodsArgs)); if (status < 0) { rodsLogError (LOG_ERROR, status, "rsyncFileToDataUtil: rcChksumLocFile error for %s, status = %d", srcPath->outPath, status); return (status); } else { chksum = getValByKey (&dataObjOprInp->condInput, RSYNC_CHKSUM_KW); if (strcmp (chksum, targPath->chksum) != 0) { if (myRodsArgs->verifyChecksum == True) { addKeyVal (&dataObjOprInp->condInput, VERIFY_CHKSUM_KW, chksum); } putFlag = 1; } } } else { /* exist but no chksum */ status = rcChksumLocFile (srcPath->outPath, RSYNC_CHKSUM_KW, &dataObjOprInp->condInput, extractHashFunction3(myRodsArgs)); if (status < 0) { rodsLogError (LOG_ERROR, status, "rsyncFileToDataUtil: rcChksumLocFile error for %s, status = %d", srcPath->outPath, status); return (status); } else { chksum = getValByKey (&dataObjOprInp->condInput, RSYNC_CHKSUM_KW); if (myRodsArgs->verifyChecksum == True) { addKeyVal (&dataObjOprInp->condInput, VERIFY_CHKSUM_KW, chksum); } syncFlag = 1; } } if (putFlag + syncFlag > 0) { rstrcpy (dataObjOprInp->objPath, targPath->outPath, MAX_NAME_LEN); dataObjOprInp->dataSize = srcPath->size; dataObjOprInp->openFlags = O_WRONLY; } if (putFlag == 1) { /* only do the sync if no -l option specified */ if ( myRodsArgs->longOption != True ) { status = rcDataObjPut (conn, dataObjOprInp, srcPath->outPath); } else { status = 0; printf ("%s %lld N\n", srcPath->outPath, srcPath->size); } rmKeyVal (&dataObjOprInp->condInput, RSYNC_CHKSUM_KW); } else if (syncFlag == 1) { addKeyVal (&dataObjOprInp->condInput, RSYNC_DEST_PATH_KW, srcPath->outPath); addKeyVal (&dataObjOprInp->condInput, RSYNC_MODE_KW, IRODS_TO_LOCAL); /* only do the sync if no -l option specified */ if ( myRodsArgs->longOption != True ) { status = rcDataObjRsync (conn, dataObjOprInp); } else { status = 0; printf ("%s %lld N\n", srcPath->outPath, srcPath->size); } rmKeyVal (&dataObjOprInp->condInput, RSYNC_DEST_PATH_KW); rmKeyVal (&dataObjOprInp->condInput, RSYNC_MODE_KW); } else { status = 0; } if (status >= 0 && myRodsArgs->verbose == True) { if (putFlag > 0 || (syncFlag > 0 && status == SYS_RSYNC_TARGET_MODIFIED)) { (void) gettimeofday(&endTime, (struct timezone *)0); printTiming (conn, srcPath->outPath, srcPath->size, targPath->outPath, &startTime, &endTime); } else { printNoSync (srcPath->outPath, srcPath->size, "a match"); } } return (status); }