Exemple #1
0
/* parseLocalPath - Parse a local path into full path taking care of
 * all the "/../", "/./" and "." entries in the path.
 * The input is taken from rodsPath->inPath.
 * The output path is written in rodsPath->outPath.
 * In addition, a stat is done on the rodsPath->outPath to determine the
 * objType and size of the file.
 */

int 
parseLocalPath (rodsPath_t *rodsPath)
{
    int len;
    int status;
    
    if (rodsPath == NULL) {
        fprintf (stderr, "parseLocalPath: NULL rodsPath input\n");
        return (USER__NULL_INPUT_ERR);
    }

    if (rodsPath->inPath == NULL) {
        fprintf (stderr, "parseLocalPath: NULL rodsPath->inPath input\n");
        return (USER__NULL_INPUT_ERR);
    }

    len = strlen (rodsPath->inPath);

    if (len == 0) {
	rstrcpy (rodsPath->outPath, ".", MAX_NAME_LEN);
    } else {
        rstrcpy (rodsPath->outPath, rodsPath->inPath, MAX_NAME_LEN);
    }

    status = getFileType (rodsPath);

    return (status);
}
 
#ifdef USE_BOOST_FS
int
getFileType (rodsPath_t *rodsPath)
{
    path p (rodsPath->outPath);

    if (!exists(p)) {
        rodsPath->objType = UNKNOWN_FILE_T;
        rodsPath->objState = NOT_EXIST_ST;
        return (NOT_EXIST_ST);
    } else if (is_regular_file(p)) {
        rodsPath->objType = LOCAL_FILE_T;
        rodsPath->objState = EXIST_ST;
        rodsPath->size = file_size(p);
    } else if (is_directory(p)) {
        rodsPath->objType = LOCAL_DIR_T;
        rodsPath->objState = EXIST_ST;
    }

    return (rodsPath->objType);
}
#else	/* USE_BOOST_FS */
int
getFileType (rodsPath_t *rodsPath)
{
#ifndef windows_platform
    struct stat statbuf;
#else
	struct irodsntstat statbuf;
#endif
    int status;

    /* XXXX need to use lstat to follow symbolic link. to be done later. 
     * also needs to call symlink to get the real path */
#ifndef windows_platform
    status = stat (rodsPath->outPath, &statbuf);
#else
	status = iRODSNt_stat(rodsPath->outPath, &statbuf);
#endif

    if (status < 0) {
	rodsPath->objType = UNKNOWN_FILE_T;
	rodsPath->objState = NOT_EXIST_ST;
	return (NOT_EXIST_ST);
    }
    rodsPath->objMode = statbuf.st_mode;
    if ((statbuf.st_mode & S_IFREG) != 0) {     /* A file */
        rodsPath->objType = LOCAL_FILE_T;
	rodsPath->objState = EXIST_ST;
        rodsPath->size = statbuf.st_size;
    } else if ((statbuf.st_mode & S_IFDIR) != 0) {      /* A directory */
        rodsPath->objType = LOCAL_DIR_T;
	rodsPath->objState = EXIST_ST;
    }

    return (rodsPath->objType);
}
Exemple #2
0
int
rcDataObjGet( rcComm_t *conn, dataObjInp_t *dataObjInp, char *locFilePath ) {
    int status;
    portalOprOut_t *portalOprOut = NULL;
    bytesBuf_t dataObjOutBBuf;
#ifndef windows_platform
    struct stat statbuf;
#else
    struct irodsntstat statbuf;
#endif

    if ( strcmp( locFilePath, STDOUT_FILE_NAME ) == 0 ) {
        /* no parallel I/O if pipe to stdout */
        dataObjInp->numThreads = NO_THREADING;
    }
#ifndef windows_platform
    else if ( stat( locFilePath, &statbuf ) >= 0 )
#else
    else if ( iRODSNt_stat( locFilePath, &statbuf ) >= 0 )
#endif
    {
        /* local file exists */
        if ( getValByKey( &dataObjInp->condInput, FORCE_FLAG_KW ) == NULL ) {
            return ( OVERWRITE_WITHOUT_FORCE_FLAG );
        }
    }

    status = _rcDataObjGet( conn, dataObjInp, &portalOprOut, &dataObjOutBBuf );

    if ( status < 0 ) {
        if ( portalOprOut != NULL ) {
            free( portalOprOut );
        }
        return ( status );
    }

    if ( status == 0 || dataObjOutBBuf.len > 0 ) {
        /* data included */
        /**** Removed by Raja as this can cause problems when the data sizes are different - say when post processing is done....Dec 2 2010
              if (dataObjInp->dataSize > 0 &&
              dataObjInp->dataSize != dataObjOutBBuf.len) {
              rodsLog (LOG_NOTICE,
              "putFile: totalWritten %lld dataSize %lld mismatch",
              dataObjOutBBuf.len, dataObjInp->dataSize);
              return (SYS_COPY_LEN_ERR);
              }
        ****/
        status = getIncludeFile( conn, &dataObjOutBBuf, locFilePath );
        free( dataObjOutBBuf.buf );
    }
    else if ( getUdpPortFromPortList( &portalOprOut->portList ) != 0 ) {
        int veryVerbose;
        /* rbudp transfer */
        /* some sanity check */
        if ( portalOprOut->numThreads != 1 ) {
            rcOprComplete( conn, SYS_INVALID_PORTAL_OPR );
            free( portalOprOut );
            return ( SYS_INVALID_PORTAL_OPR );
        }
        conn->transStat.numThreads = portalOprOut->numThreads;
        if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) {
            printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n",
                    portalOprOut->numThreads, portalOprOut->portList.hostAddr,
                    portalOprOut->portList.portNum, portalOprOut->portList.cookie );
            veryVerbose = 2;
        }
        else {
            veryVerbose = 0;
        }

        // =-=-=-=-=-=-=-
        // if a secret has been negotiated then we must be using
        // encryption.  given that RBUDP is not supported in an
        // encrypted capacity this is considered an error
        if ( irods::CS_NEG_USE_SSL == conn->negotiation_results ) {
            rodsLog(
                LOG_ERROR,
                "getFileToPortal: Encryption is not supported with RBUDP" );
            return SYS_INVALID_PORTAL_OPR;

        }

        status = getFileToPortalRbudp(
                     portalOprOut,
                     locFilePath, 0,
                     dataObjInp->dataSize,
                     veryVerbose, 0 );

        /* just send a complete msg */
        if ( status < 0 ) {
            rcOprComplete( conn, status );

        }
        else {
            status = rcOprComplete( conn, portalOprOut->l1descInx );
        }
    }
    else {

        if ( portalOprOut->numThreads <= 0 ) {
            status = getFile( conn, portalOprOut->l1descInx,
                              locFilePath, dataObjInp->objPath, dataObjInp->dataSize );
        }
        else {
            if ( getValByKey( &dataObjInp->condInput, VERY_VERBOSE_KW ) != NULL ) {
                printf( "From server: NumThreads=%d, addr:%s, port:%d, cookie=%d\n",
                        portalOprOut->numThreads, portalOprOut->portList.hostAddr,
                        portalOprOut->portList.portNum, portalOprOut->portList.cookie );
            }
            /* some sanity check */
            if ( portalOprOut->numThreads >= 20 * DEF_NUM_TRAN_THR ) {
                rcOprComplete( conn, SYS_INVALID_PORTAL_OPR );
                free( portalOprOut );
                return ( SYS_INVALID_PORTAL_OPR );
            }

            conn->transStat.numThreads = portalOprOut->numThreads;
            status = getFileFromPortal( conn, portalOprOut, locFilePath,
                                        dataObjInp->objPath, dataObjInp->dataSize );
        }
        /* just send a complete msg */
        if ( status < 0 ) {
            rcOprComplete( conn, status );
        }
        else {
            status = rcOprComplete( conn, portalOprOut->l1descInx );
        }
    }

    if ( status >= 0 && conn->fileRestart.info.numSeg > 0 ) { /* file restart */
        clearLfRestartFile( &conn->fileRestart );
    }

    if ( getValByKey( &dataObjInp->condInput, VERIFY_CHKSUM_KW ) != NULL ) {
        if ( portalOprOut == NULL || strlen( portalOprOut->chksum ) == 0 ) {
            rodsLog( LOG_ERROR,
                     "rcDataObjGet: VERIFY_CHKSUM_KW set but no chksum from server" );
        }
        else {

            status = verifyChksumLocFile( locFilePath, portalOprOut->chksum, NULL );
            if ( status == USER_CHKSUM_MISMATCH ) {
                rodsLogError( LOG_ERROR, status,
                              "rcDataObjGet: chksum mismatch error for %s, status = %d",
                              locFilePath, status );
                if ( portalOprOut != NULL ) {
                    free( portalOprOut );
                }
                return ( status );
            }
            else if ( status < 0 ) {
                rodsLogError( LOG_ERROR, status,
                              "rcDataObjGet: chksumLocFile error for %s, status = %d",
                              locFilePath, status );
                if ( portalOprOut != NULL ) {
                    free( portalOprOut );
                }
                return ( status );
            }

        }
    }
    if ( portalOprOut != NULL ) {
        free( portalOprOut );
    }

    return ( status );
}
Exemple #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);
}
Exemple #4
0
int
rsyncDirToCollUtil (rcComm_t *conn, rodsPath_t *srcPath, 
rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjOprInp)
{
    int status = 0;
    int savedStatus = 0;
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
#ifndef windows_platform
    struct stat statbuf;
#else
	struct irodsntstat statbuf;
#endif
#endif	/* #ifndef USE_BOOST_FS */
    char *srcDir, *targColl;
    rodsPath_t mySrcPath, myTargPath;

    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "rsyncDirToCollUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    srcDir = srcPath->outPath;
    targColl = targPath->outPath;

    if (isPathSymlink (rodsArgs, srcDir) > 0) return 0;

    if (rodsArgs->recursive != True) {
        rodsLog (LOG_ERROR,
        "rsyncDirToCollUtil: -r option must be used for putting %s directory",
         srcDir);
        return (USER_INPUT_OPTION_ERR);
    }

#ifdef USE_BOOST_FS
    path srcDirPath (srcDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (srcDir);
    if (dirPtr == NULL) {
#endif  /* USE_BOOST_FS */
        rodsLog (LOG_ERROR,
        "rsyncDirToCollUtil: opendir local dir error for %s, errno = %d\n",
         srcDir, errno);
        return (USER_INPUT_PATH_ERR);
    }

    if (rodsArgs->verbose == True) {
        fprintf (stdout, "C- %s:\n", targColl);
    }

    memset (&mySrcPath, 0, sizeof (mySrcPath));
    memset (&myTargPath, 0, sizeof (myTargPath));
    myTargPath.objType = DATA_OBJ_T;
    mySrcPath.objType = LOCAL_FILE_T;

#ifdef USE_BOOST_FS
    directory_iterator end_itr; // default construction yields past-the-end
    for (directory_iterator itr(srcDirPath); itr != end_itr;++itr) {
        path p = itr->path();
        snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s",
          p.c_str ());
#else
    while ((myDirent = readdir (dirPtr)) != NULL) {
        if (strcmp (myDirent->d_name, ".") == 0 ||
          strcmp (myDirent->d_name, "..") == 0) {
            continue;
        }
        snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
          srcDir, myDirent->d_name);
#endif	/* USE_BOOST_FS */

        if (isPathSymlink (rodsArgs, mySrcPath.outPath) > 0) continue;
#ifdef USE_BOOST_FS
#if 0
        path p (mySrcPath.outPath);
#endif
	if (!exists(p)) {
#else
#ifndef windows_platform
        status = stat (mySrcPath.outPath, &statbuf);
#else
	status = iRODSNt_stat(mySrcPath.outPath, &statbuf);
#endif

        if (status != 0) {
            closedir (dirPtr);
#endif  /* USE_BOOST_FS */
            rodsLog (LOG_ERROR,
              "rsyncDirToCollUtil: stat error for %s, errno = %d\n",
              mySrcPath.outPath, errno);
            return (USER_INPUT_PATH_ERR);
        }
#ifndef USE_BOOST_FS
        if ((statbuf.st_mode & S_IFREG) != 0 && rodsArgs->age == True) {
            if (ageExceeded (rodsArgs->agevalue, statbuf.st_mtime,
              rodsArgs->verbose, mySrcPath.outPath, statbuf.st_size)) 
                continue;
        }
#endif /* #ifndef USE_BOOST_FS */
#ifdef FILESYSTEM_META
        getFileMetaFromPath(mySrcPath.outPath, &dataObjOprInp->condInput);
#endif
	bzero (&myTargPath, sizeof (myTargPath));
#ifdef USE_BOOST_FS
        path childPath = p.filename();
        snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
          targColl, childPath.c_str());
        if (is_symlink (p)) {
            path cp = read_symlink (p);
            snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
              srcDir, cp.c_str ());
            p = path (mySrcPath.outPath);
        }
	dataObjOprInp->createMode = getPathStMode (p);
	if (is_regular_file(p)) {
#else
        snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
          targColl, myDirent->d_name);
	dataObjOprInp->createMode = statbuf.st_mode;
        if ((statbuf.st_mode & S_IFREG) != 0) {     /* a file */
#endif
            myTargPath.objType = DATA_OBJ_T;
            mySrcPath.objType = LOCAL_FILE_T;
	    mySrcPath.objState = EXIST_ST;
#ifdef USE_BOOST_FS
	    mySrcPath.size = file_size (p);
#else
	    mySrcPath.size = statbuf.st_size;
#endif
	    getRodsObjType (conn, &myTargPath);
            status = rsyncFileToDataUtil (conn, &mySrcPath, &myTargPath,
              myRodsEnv, rodsArgs, dataObjOprInp);
	    /* fix a big mem leak */
            if (myTargPath.rodsObjStat != NULL) {
                freeRodsObjStat (myTargPath.rodsObjStat);
                myTargPath.rodsObjStat = NULL;
            }
#if 0
	    if (myTargPath.objState != NOT_EXIST_ST)
	        freeRodsObjStat (myTargPath.rodsObjStat);
#endif
#ifdef USE_BOOST_FS
	} else if (is_directory(p)) {
#else
        } else if ((statbuf.st_mode & S_IFDIR) != 0) {      /* a directory */
#endif
            status = 0;
            /* only do the sync if no -l option specified */
            if ( rodsArgs->longOption != True ) {
#ifdef FILESYSTEM_META
                status = mkCollRWithDirMeta (conn, targColl,
                                             myTargPath.outPath, mySrcPath.outPath);
#else
            	status = mkCollR (conn, targColl, myTargPath.outPath);
#endif
            }
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncDirToCollUtil: mkCollR error for %s", 
		  myTargPath.outPath);
            } else {
                myTargPath.objType = COLL_OBJ_T;
                mySrcPath.objType = LOCAL_DIR_T;
                mySrcPath.objState = myTargPath.objState = EXIST_ST;
                getRodsObjType (conn, &myTargPath);
                status = rsyncDirToCollUtil (conn, &mySrcPath, &myTargPath,
                  myRodsEnv, rodsArgs, dataObjOprInp);
	        /* fix a big mem leak */
                if (myTargPath.rodsObjStat != NULL) {
                    freeRodsObjStat (myTargPath.rodsObjStat);
                    myTargPath.rodsObjStat = NULL;
                }
#if 0
	        if (myTargPath.objState != NOT_EXIST_ST)
		    freeRodsObjStat (myTargPath.rodsObjStat);
#endif
            }
        } else {
            rodsLog (LOG_ERROR,
#ifdef USE_BOOST_FS
              "rsyncDirToCollUtil: unknown local path %s",
              mySrcPath.outPath);
#else
              "rsyncDirToCollUtil: unknown local path type %d for %s",
              statbuf.st_mode, mySrcPath.outPath);
#endif	/* USE_BOOST_FS */
            status = USER_INPUT_PATH_ERR;
        }

        if (status < 0) {
            savedStatus = status;
            rodsLogError (LOG_ERROR, status,
             "rsyncDirToCollUtil: put %s failed. status = %d",
              mySrcPath.outPath, status);
        }
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif

    if (savedStatus < 0) {
        return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND || 
      status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
        return (0);
    } else {
        return (status);
    }

}

int
rsyncCollToCollUtil (rcComm_t *conn, rodsPath_t *srcPath, 
rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjCopyInp_t *dataObjCopyInp)
{
    int status = 0;
    int savedStatus = 0;
    char *srcColl, *targColl;
    char targChildPath[MAX_NAME_LEN];
#if 0
    int collLen;
#else
    char parPath[MAX_NAME_LEN], childPath[MAX_NAME_LEN];
#endif
    rodsPath_t mySrcPath, myTargPath;
    collHandle_t collHandle;
    collEnt_t collEnt;
    dataObjCopyInp_t childDataObjCopyInp;

    dataObjInp_t *dataObjOprInp = &collHandle.dataObjInp;

    if (srcPath == NULL || targPath == NULL) {
       rodsLog (LOG_ERROR,
          "rsyncCollToCollUtil: NULL srcPath or targPath input");
        return (USER__NULL_INPUT_ERR);
    }

    srcColl = srcPath->outPath;
    targColl = targPath->outPath;

    if (rodsArgs->recursive != True) {
        rodsLog (LOG_ERROR,
        "rsyncCollToCollUtil: -r option must be used for collection %s",
         targColl);
        return (USER_INPUT_OPTION_ERR);
    }

#if 0
    status = rclOpenCollection (conn, srcColl,
      RECUR_QUERY_FG | VERY_LONG_METADATA_FG, &collHandle);
#else
    status = rclOpenCollection (conn, srcColl,
      VERY_LONG_METADATA_FG, &collHandle);
#endif

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "getCollUtil: rclOpenCollection of %s error. status = %d",
          srcColl, status);
        return status;
    }

    if (dataObjOprInp->specColl != NULL) {
        if (rodsArgs->verbose == True) {
            if (rodsArgs->verbose == True) {
                char objType[NAME_LEN];
                status = getSpecCollTypeStr (dataObjOprInp->specColl, objType);
                if (status < 0) 
                    fprintf (stdout, "C- %s    :\n", targColl);
		else
                    fprintf (stdout, "C- %s    %-5.5s :\n", targColl, objType);
            }
        }
    }

    memset (&mySrcPath, 0, sizeof (mySrcPath));
    memset (&myTargPath, 0, sizeof (myTargPath));
    myTargPath.objType = DATA_OBJ_T;
    mySrcPath.objType = DATA_OBJ_T;

#if 0
    collLen = strlen (srcColl);
    collLen = getOpenedCollLen (&collHandle);
#endif
    while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) {
        if (collEnt.objType == DATA_OBJ_T) {
            if (rodsArgs->age == True) {
                if (ageExceeded (rodsArgs->agevalue,
                  atoi (collEnt.modifyTime), rodsArgs->verbose,
                  collEnt.dataName, collEnt.dataSize)) continue;
            }
#if 0
            snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s%s/%s",
              targColl, collEnt.collName + collLen,
              collEnt.dataName);
#else
            snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s",
              targColl, collEnt.dataName);
#endif
            snprintf (mySrcPath.outPath, MAX_NAME_LEN, "%s/%s",
              collEnt.collName, collEnt.dataName);
            /* fill in some info for mySrcPath */
            if (strlen (mySrcPath.dataId) == 0)
                rstrcpy (mySrcPath.dataId, collEnt.dataId, NAME_LEN);
            mySrcPath.size = collEnt.dataSize;
            rstrcpy (mySrcPath.chksum, collEnt.chksum, CHKSUM_LEN);
            mySrcPath.objState = EXIST_ST;

#if 0
            getFileType (&myTargPath);
#else
	    getRodsObjType (conn, &myTargPath);
#endif

            status = rsyncDataToDataUtil (conn, &mySrcPath,
             &myTargPath, myRodsEnv, rodsArgs, dataObjCopyInp);
	    if (myTargPath.rodsObjStat != NULL) {
	        freeRodsObjStat (myTargPath.rodsObjStat);
		myTargPath.rodsObjStat = NULL;
	    }
            if (status < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncCollToCollUtil: rsyncDataToDataUtil failed for %s.stat=%d",
                  myTargPath.outPath, status);
                /* need to set global error here */
                savedStatus = status;
                status = 0;
            }
        } else if (collEnt.objType == COLL_OBJ_T) {
#if 0
            if (strlen (collEnt.collName) <= collLen)
                continue;

            snprintf (targChildPath, MAX_NAME_LEN, "%s%s",
              targColl, collEnt.collName + collLen);
#else
            if ((status = splitPathByKey (
              collEnt.collName, parPath, childPath, '/')) < 0) {
                rodsLogError (LOG_ERROR, status,
                  "rsyncCollToCollUtil:: splitPathByKey for %s error, status = %d",
                  collEnt.collName, status);
                return (status);
            }
            snprintf (targChildPath, MAX_NAME_LEN, "%s/%s",
              targColl, childPath);
#endif


	    if ( rodsArgs->longOption != True ) {   /* only do the sync if no -l option specified */
#ifdef FILESYSTEM_META
                mkCollWithSrcCollMeta (conn, targChildPath, collEnt.collName);
#else
            	mkColl (conn, targChildPath);
#endif
	    }

#if 0
            if (collEnt.specColl.collClass != NO_SPEC_COLL) {
#endif
                /* the child is a spec coll. need to drill down */
                childDataObjCopyInp = *dataObjCopyInp;
		if (collEnt.specColl.collClass != NO_SPEC_COLL)
                    childDataObjCopyInp.srcDataObjInp.specColl = 
		      &collEnt.specColl;
                rstrcpy (myTargPath.outPath, targChildPath, MAX_NAME_LEN);
                rstrcpy (mySrcPath.outPath, collEnt.collName, MAX_NAME_LEN);
                status = rsyncCollToCollUtil (conn, &mySrcPath,
                  &myTargPath, myRodsEnv, rodsArgs, &childDataObjCopyInp);


                if (status < 0 && status != CAT_NO_ROWS_FOUND) {
                    return (status);
                }
#if 0
            }
#endif
	}
    }
    rclCloseCollection (&collHandle);

    if (savedStatus < 0) {
        return (savedStatus);
    } else if (status == CAT_NO_ROWS_FOUND || 
      status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
        return (0);
    } else {
        return (status);
    }
}

int
initCondForRsync (rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, 
dataObjInp_t *dataObjInp)
{
    char *myResc = NULL;
    char tmpStr[NAME_LEN];

    if (dataObjInp == NULL) {
       rodsLog (LOG_ERROR,
          "initCondForRsync: NULL dataObjOprInp input");
        return (USER__NULL_INPUT_ERR);
    }

    memset (dataObjInp, 0, sizeof (dataObjInp_t));

    if (rodsArgs == NULL) {
	return (0);
    }

    /* always turn on the force flag */
    addKeyVal (&dataObjInp->condInput, FORCE_FLAG_KW, "");

    if (rodsArgs->sizeFlag == True) {
        addKeyVal (&dataObjInp->condInput, VERIFY_BY_SIZE_KW, "");
    }

    if (rodsArgs->all == True) {
        addKeyVal (&dataObjInp->condInput, ALL_KW, "");
    }

#ifdef windows_platform
    dataObjInp->numThreads = NO_THREADING;
#else
    if (rodsArgs->number == True) {
        if (rodsArgs->numberValue == 0) {
            dataObjInp->numThreads = NO_THREADING;
        } else {
            dataObjInp->numThreads = rodsArgs->numberValue;
        }
    }
#endif

    if (rodsArgs->resource == True) {
        if (rodsArgs->resourceString == NULL) {
            rodsLog (LOG_ERROR,
              "initCondForRepl: NULL resourceString error");
            return (USER__NULL_INPUT_ERR);
        } else {
            myResc = rodsArgs->resourceString;
            addKeyVal (&dataObjInp->condInput, DEST_RESC_NAME_KW,
              rodsArgs->resourceString);
        }
    } else if (myRodsEnv != NULL && strlen (myRodsEnv->rodsDefResource) > 0) {
        myResc = myRodsEnv->rodsDefResource;
        addKeyVal (&dataObjInp->condInput, DEST_RESC_NAME_KW,
          myRodsEnv->rodsDefResource);
    }
    if (rodsArgs->age == True) {
        snprintf (tmpStr, NAME_LEN, "%d", rodsArgs->agevalue);
        addKeyVal (&dataObjInp->condInput, AGE_KW, tmpStr);
    }

    return (0);
}
Exemple #5
0
int
localProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp,
               genQueryOut_t **procStatOut)
{
    int numProc, status;
    procLog_t procLog;
    char childPath[MAX_NAME_LEN];
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
#ifndef windows_platform
    struct stat statbuf;
#else
    struct irodsntstat statbuf;
#endif
#endif
    int count = 0;

    numProc = getNumFilesInDir (ProcLogDir) + 2; /* add 2 to give some room */

    bzero (&procLog, sizeof (procLog));
    /* init serverAddr */
    if (*procStatInp->addr != '\0') {   /* given input addr */
        rstrcpy (procLog.serverAddr, procStatInp->addr, NAME_LEN);
    } else {
        setLocalSrvAddr (procLog.serverAddr);
    }
    if (numProc <= 0) {
        /* add an empty entry with only serverAddr */
        initProcStatOut (procStatOut, 1);
        addProcToProcStatOut (&procLog, *procStatOut);
        return numProc;
    } else {
        initProcStatOut (procStatOut, numProc);
    }

    /* loop through the directory */
#ifdef USE_BOOST_FS
    path srcDirPath (ProcLogDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (ProcLogDir);
    if (dirPtr == NULL) {
#endif
        status = USER_INPUT_PATH_ERR - errno;
        rodsLogError (LOG_ERROR, status,
                      "localProcStat: opendir local dir error for %s", ProcLogDir);
        return status;
    }
#ifdef USE_BOOST_FS
    directory_iterator end_itr; // default construction yields past-the-end
    for (directory_iterator itr(srcDirPath); itr != end_itr; ++itr) {
        path p = itr->path();
        path cp = p.filename();
        if (!isdigit (*cp.c_str())) continue;   /* not a pid */
        snprintf (childPath, MAX_NAME_LEN, "%s",
                  p.c_str ());
#else
    while ((myDirent = readdir (dirPtr)) != NULL) {
        if (strcmp (myDirent->d_name, ".") == 0 ||
                strcmp (myDirent->d_name, "..") == 0) {
            continue;
        }
        if (!isdigit (*myDirent->d_name)) continue;   /* not a pid */
        snprintf (childPath, MAX_NAME_LEN, "%s/%s", ProcLogDir,
                  myDirent->d_name);
#endif
#ifdef USE_BOOST_FS
        if (!exists (p)) {
#else
#ifndef windows_platform
        status = stat (childPath, &statbuf);
#else
        status = iRODSNt_stat(childPath, &statbuf);
#endif
        if (status != 0) {
#endif  /* USE_BOOST_FS */
            rodsLogError (LOG_ERROR, status,
                          "localProcStat: stat error for %s", childPath);
            continue;
        }
#ifdef USE_BOOST_FS
        if (is_regular_file(p)) {
#else
        if (statbuf.st_mode & S_IFREG) {
#endif
            if (count >= numProc) {
                rodsLog (LOG_ERROR,
                         "localProcStat: proc count %d exceeded", numProc);
                break;
            }
#ifdef USE_BOOST_FS
            procLog.pid = atoi (cp.c_str());
#else
            procLog.pid = atoi (myDirent->d_name);
#endif
            if (readProcLog (procLog.pid, &procLog) < 0) continue;
            status = addProcToProcStatOut (&procLog, *procStatOut);
            if (status < 0) continue;
            count++;
        } else {
            continue;
        }
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif
    return 0;
}

int
remoteProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp,
                genQueryOut_t **procStatOut, rodsServerHost_t *rodsServerHost)
{
    int status;
    procLog_t procLog;

    if (rodsServerHost == NULL) {
        rodsLog (LOG_ERROR,
                 "remoteProcStat: Invalid rodsServerHost");
        return SYS_INVALID_SERVER_HOST;
    }

    if (procStatInp == NULL || procStatOut == NULL) return USER__NULL_INPUT_ERR;

    status = svrToSvrConnect (rsComm, rodsServerHost);

    if (status >= 0) {
        status = rcProcStat (rodsServerHost->conn, procStatInp, procStatOut);
    }
    if (status < 0 && *procStatOut == NULL) {
        /* add an empty entry */
        initProcStatOut (procStatOut, 1);
        bzero (&procLog, sizeof (procLog));
        rstrcpy (procLog.serverAddr, rodsServerHost->hostName->name,
                 NAME_LEN);
        addProcToProcStatOut (&procLog, *procStatOut);
    }
    return status;
}

int
initProcStatOut (genQueryOut_t **procStatOut, int numProc)
{
    genQueryOut_t *myProcStatOut;

    if (procStatOut == NULL || numProc <= 0) return USER__NULL_INPUT_ERR;

    myProcStatOut = *procStatOut = (genQueryOut_t*)malloc (sizeof (genQueryOut_t));
    bzero (myProcStatOut, sizeof (genQueryOut_t));

    myProcStatOut->continueInx = -1;

    myProcStatOut->attriCnt = 9;

    myProcStatOut->sqlResult[0].attriInx = PID_INX;
    myProcStatOut->sqlResult[0].len = NAME_LEN;
    myProcStatOut->sqlResult[0].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[0].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[1].attriInx = STARTTIME_INX;
    myProcStatOut->sqlResult[1].len = NAME_LEN;
    myProcStatOut->sqlResult[1].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[1].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[2].attriInx = CLIENT_NAME_INX;
    myProcStatOut->sqlResult[2].len = NAME_LEN;
    myProcStatOut->sqlResult[2].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[2].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[3].attriInx = CLIENT_ZONE_INX;
    myProcStatOut->sqlResult[3].len = NAME_LEN;
    myProcStatOut->sqlResult[3].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[3].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[4].attriInx = PROXY_NAME_INX;
    myProcStatOut->sqlResult[4].len = NAME_LEN;
    myProcStatOut->sqlResult[4].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[4].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[5].attriInx = PROXY_ZONE_INX;
    myProcStatOut->sqlResult[5].len = NAME_LEN;
    myProcStatOut->sqlResult[5].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[5].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[6].attriInx = REMOTE_ADDR_INX;
    myProcStatOut->sqlResult[6].len = NAME_LEN;
    myProcStatOut->sqlResult[6].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[6].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[7].attriInx = SERVER_ADDR_INX;
    myProcStatOut->sqlResult[7].len = NAME_LEN;
    myProcStatOut->sqlResult[7].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[7].value, NAME_LEN * numProc);

    myProcStatOut->sqlResult[8].attriInx = PROG_NAME_INX;
    myProcStatOut->sqlResult[8].len = NAME_LEN;
    myProcStatOut->sqlResult[8].value =
        (char*)malloc (NAME_LEN * numProc);
    bzero (myProcStatOut->sqlResult[8].value, NAME_LEN * numProc);


    return 0;
}

int
addProcToProcStatOut (procLog_t *procLog, genQueryOut_t *procStatOut)
{
    int rowCnt;

    if (procLog == NULL || procStatOut == NULL) return USER__NULL_INPUT_ERR;
    rowCnt = procStatOut->rowCnt;

    snprintf (&procStatOut->sqlResult[0].value[NAME_LEN * rowCnt],
              NAME_LEN, "%d", procLog->pid);
    snprintf (&procStatOut->sqlResult[1].value[NAME_LEN * rowCnt],
              NAME_LEN, "%u", procLog->startTime);
    rstrcpy (&procStatOut->sqlResult[2].value[NAME_LEN * rowCnt],
             procLog->clientName, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[3].value[NAME_LEN * rowCnt],
             procLog->clientZone, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[4].value[NAME_LEN * rowCnt],
             procLog->proxyName, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[5].value[NAME_LEN * rowCnt],
             procLog->proxyZone, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[6].value[NAME_LEN * rowCnt],
             procLog->remoteAddr, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[7].value[NAME_LEN * rowCnt],
             procLog->serverAddr, NAME_LEN);
    rstrcpy (&procStatOut->sqlResult[8].value[NAME_LEN * rowCnt],
             procLog->progName, NAME_LEN);

    procStatOut->rowCnt++;

    return 0;
}