示例#1
0
int
regUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
         rodsPathInp_t *rodsPathInp ) {
    if ( rodsPathInp == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    dataObjInp_t dataObjOprInp;
    initCondForReg( myRodsEnv, myRodsArgs, &dataObjOprInp );

    int savedStatus = 0;
    for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
        rodsPath_t * destPath = &rodsPathInp->destPath[i];	/* iRODS path */
        rodsPath_t * srcPath = &rodsPathInp->srcPath[i];	/* file Path */

        getRodsObjType( conn, destPath );

        if ( destPath->objState == EXIST_ST &&
                myRodsArgs->force == False &&
                myRodsArgs->mountCollection == False &&
                myRodsArgs->regRepl != True ) {
            rodsLog( LOG_ERROR,
                     "regUtil: iRODSPath %s already exist", destPath->outPath );
            return CAT_NAME_EXISTS_AS_DATAOBJ;
        }

        int status = 0;
        if ( myRodsArgs->collection == False && myRodsArgs->checksum == True ) {
            status = rcChksumLocFile( srcPath->outPath,
                                      REG_CHKSUM_KW,
                                      &dataObjOprInp.condInput,
                                      myRodsArgs->hashValue );
            if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "regUtil: rcChksumLocFile error for %s, status = %d",
                              srcPath, status );
                return status;
            }
        }
        else if ( myRodsArgs->collection == False && myRodsArgs->verifyChecksum == True ) {
            addKeyVal( &dataObjOprInp.condInput, VERIFY_CHKSUM_KW, "" );
        }

        addKeyVal( &dataObjOprInp.condInput, FILE_PATH_KW, srcPath->outPath );
        rstrcpy( dataObjOprInp.objPath, destPath->outPath, MAX_NAME_LEN );

        status = rcPhyPathReg( conn, &dataObjOprInp );

        /* XXXX may need to return a global status */
        if ( status < 0 &&
                status != CAT_NO_ROWS_FOUND ) {
            rodsLogError( LOG_ERROR, status,
                          "regUtil: reg error for %s, status = %d",
                          destPath->outPath, status );
            savedStatus = status;
        }
    }
    return savedStatus;
}
示例#2
0
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;
}
示例#3
0
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);
}