int RodsConnection::readColl(const std::string &collPath, std::vector<RodsObjEntryPtr> *collObjs) { collHandle_t rodsColl; collEnt_t rodsCollEntry; char collPathIn[MAX_NAME_LEN], collPathOut[MAX_NAME_LEN]; int status = 0; // sanity checks for arguments if (!collObjs || collPath.empty()) return (-1); // take a temp copy of the coll path string strcpy(collPathIn, collPath.c_str()); this->mutexLock(); // first the path string must be parsed by iRODS if ((status = parseRodsPathStr(collPathIn, &this->rodsUserEnv, collPathOut) < 0)) return (status); // try to open collection from iRODS if ((status = rclOpenCollection(this->rodsCommPtr, collPathOut, 0, &rodsColl)) < 0) return (status); // read collection while there are objects to loop over do { status = rclReadCollection(this->rodsCommPtr, &rodsColl, &rodsCollEntry); if (status >= 0) { Kanki::RodsObjEntryPtr newEntry(new Kanki::RodsObjEntry(rodsCollEntry.objType == DATA_OBJ_T ? rodsCollEntry.dataName : rodsCollEntry.collName, rodsCollEntry.collName, rodsCollEntry.createTime, rodsCollEntry.modifyTime, rodsCollEntry.objType, rodsCollEntry.replNum, rodsCollEntry.replStatus, rodsCollEntry.dataSize)); collObjs->push_back(newEntry); } } while (status >= 0); // close the collection handle status = rclCloseCollection(&rodsColl); this->mutexUnlock(); return (status); }
int getCollUtil (rcComm_t **myConn, char *srcColl, char *targDir, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp, rodsRestart_t *rodsRestart) { int status = 0; int savedStatus = 0; char srcChildPath[MAX_NAME_LEN], targChildPath[MAX_NAME_LEN]; #if 0 int collLen; #else char parPath[MAX_NAME_LEN], childPath[MAX_NAME_LEN]; #endif collHandle_t collHandle; collEnt_t collEnt; dataObjInp_t childDataObjInp; rcComm_t *conn; if (srcColl == NULL || targDir == NULL) { rodsLog (LOG_ERROR, "getCollUtil: NULL srcColl or targDir input"); return (USER__NULL_INPUT_ERR); } if (rodsArgs->recursive != True) { rodsLog (LOG_ERROR, "getCollUtil: -r option must be used for getting %s collection", targDir); return (USER_INPUT_OPTION_ERR); } if (rodsArgs->redirectConn == True) { int reconnFlag; if (rodsArgs->reconnect == True) { reconnFlag = RECONN_TIMEOUT; } else { reconnFlag = NO_RECONN; } /* reconnect to the resource server */ rstrcpy (dataObjOprInp->objPath, srcColl, MAX_NAME_LEN); redirectConnToRescSvr (myConn, dataObjOprInp, myRodsEnv, reconnFlag); rodsArgs->redirectConn = 0; /* only do it once */ } conn = *myConn; printCollOrDir (targDir, LOCAL_DIR_T, rodsArgs, dataObjOprInp->specColl); #if 0 status = rclOpenCollection (conn, srcColl, RECUR_QUERY_FG, &collHandle); #else status = rclOpenCollection (conn, srcColl, 0, &collHandle); #endif if (status < 0) { rodsLog (LOG_ERROR, "getCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } #if 0 collLen = strlen (srcColl); collLen = getOpenedCollLen (&collHandle); #endif while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) { if (collEnt.objType == DATA_OBJ_T) { rodsLong_t mySize; mySize = collEnt.dataSize; /* have to save it. May be freed */ #if 0 snprintf (targChildPath, MAX_NAME_LEN, "%s%s/%s", targDir, collEnt.collName + collLen, collEnt.dataName); #else snprintf (targChildPath, MAX_NAME_LEN, "%s/%s", targDir, collEnt.dataName); #endif snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName); status = chkStateForResume (conn, rodsRestart, targChildPath, rodsArgs, LOCAL_FILE_T, &dataObjOprInp->condInput, 1); if (status < 0) { /* restart failed */ break; } else if (status == 0) { continue; } status = getDataObjUtil (conn, srcChildPath, targChildPath, mySize, collEnt.dataMode, myRodsEnv, rodsArgs, dataObjOprInp); if (status < 0) { rodsLogError (LOG_ERROR, status, "getCollUtil: getDataObjUtil failed for %s. status = %d", srcChildPath, status); savedStatus = status; if (rodsRestart->fd > 0) break; } else { status = procAndWrriteRestartFile (rodsRestart, targChildPath); } } else if (collEnt.objType == COLL_OBJ_T) { if ((status = splitPathByKey ( collEnt.collName, parPath, childPath, '/')) < 0) { rodsLogError (LOG_ERROR, status, "getCollUtil:: splitPathByKey for %s error, status = %d", collEnt.collName, status); return (status); } snprintf (targChildPath, MAX_NAME_LEN, "%s/%s", targDir, childPath); mkdirR (targDir, targChildPath, 0750); /* the child is a spec coll. need to drill down */ childDataObjInp = *dataObjOprInp; if (collEnt.specColl.collClass != NO_SPEC_COLL) childDataObjInp.specColl = &collEnt.specColl; else childDataObjInp.specColl = NULL; status = getCollUtil (myConn, collEnt.collName, targChildPath, myRodsEnv, rodsArgs, &childDataObjInp, rodsRestart); if (status < 0 && status != CAT_NO_ROWS_FOUND) { rodsLogError (LOG_ERROR, status, "getCollUtil: getCollUtil failed for %s. status = %d", collEnt.collName, status); savedStatus = status; if (rodsRestart->fd > 0) break; } } } 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 ncOperCollUtil (rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, ncOpenInp_t *ncOpenInp, ncVarSubset_t *ncVarSubset) { int status; int savedStatus = 0; collHandle_t collHandle; collEnt_t collEnt; char srcChildPath[MAX_NAME_LEN]; if (srcColl == NULL) { rodsLog (LOG_ERROR, "ncOperCollUtil: NULL srcColl input"); return (USER__NULL_INPUT_ERR); } if (rodsArgs->recursive != True) { rodsLog (LOG_ERROR, "ncOperCollUtil: -r option must be used for getting %s collection", srcColl); return (USER_INPUT_OPTION_ERR); } if (rodsArgs->verbose == True) { fprintf (stdout, "C- %s:\n", srcColl); } status = rclOpenCollection (conn, srcColl, 0, &collHandle); if (status < 0) { rodsLog (LOG_ERROR, "ncOperCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } if (collHandle.rodsObjStat->specColl != NULL && collHandle.rodsObjStat->specColl->collClass != LINKED_COLL) { /* no reg for mounted coll */ rclCloseCollection (&collHandle); return 0; } while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) { if (collEnt.objType == DATA_OBJ_T) { snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName); status = ncOperDataObjUtil (conn, srcChildPath, myRodsEnv, rodsArgs, ncOpenInp, ncVarSubset); if (status < 0) { rodsLogError (LOG_ERROR, status, "ncOperCollUtil: ncOperDataObjUtil failed for %s. status = %d", srcChildPath, status); /* need to set global error here */ savedStatus = status; status = 0; } } else if (collEnt.objType == COLL_OBJ_T) { ncOpenInp_t childNcOpen; childNcOpen = *ncOpenInp; if (collEnt.specColl.collClass != NO_SPEC_COLL) continue; status = ncOperCollUtil (conn, collEnt.collName, myRodsEnv, rodsArgs, &childNcOpen, ncVarSubset); if (status < 0 && status != CAT_NO_ROWS_FOUND) { savedStatus = status; } } } rclCloseCollection (&collHandle); if (savedStatus < 0) { return (savedStatus); } else if (status == CAT_NO_ROWS_FOUND) { return (0); } else { return (status); } }
int cpCollUtil( rcComm_t *conn, char *srcColl, char *targColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjCopyInp_t *dataObjCopyInp, rodsRestart_t *rodsRestart ) { int status = 0; int savedStatus = 0; char parPath[MAX_NAME_LEN], childPath[MAX_NAME_LEN]; collHandle_t collHandle; collEnt_t collEnt; char srcChildPath[MAX_NAME_LEN], targChildPath[MAX_NAME_LEN]; dataObjCopyInp_t childDataObjCopyInp; if ( srcColl == NULL || targColl == NULL ) { rodsLog( LOG_ERROR, "cpCollUtil: NULL srcColl or targColl in cp" ); return USER__NULL_INPUT_ERR; } if ( rodsArgs->recursive != True ) { rodsLog( LOG_ERROR, "cpCollUtil: -r option must be used for copying %s directory", srcColl ); return USER_INPUT_OPTION_ERR; } status = rclOpenCollection( conn, srcColl, 0, &collHandle ); if ( status < 0 ) { rodsLog( LOG_ERROR, "cpCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status ); return status; } while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) { if ( collEnt.objType == DATA_OBJ_T ) { snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName ); snprintf( targChildPath, MAX_NAME_LEN, "%s/%s", targColl, collEnt.dataName ); status = chkStateForResume( conn, rodsRestart, targChildPath, rodsArgs, DATA_OBJ_T, &dataObjCopyInp->destDataObjInp.condInput, 1 ); if ( status < 0 ) { /* restart failed */ break; } else if ( status == 0 ) { continue; } status = cpFileUtil( conn, srcChildPath, targChildPath, collEnt.dataSize, rodsArgs, dataObjCopyInp ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "getCollUtil: getDataObjUtil failed for %s. status = %d", srcChildPath, status ); if ( rodsRestart->fd > 0 ) { break; } else { savedStatus = status; } } else { status = procAndWrriteRestartFile( rodsRestart, targChildPath ); } } else if ( collEnt.objType == COLL_OBJ_T ) { if ( ( status = splitPathByKey( collEnt.collName, parPath, MAX_NAME_LEN, childPath, MAX_NAME_LEN, '/' ) ) < 0 ) { rodsLogError( LOG_ERROR, status, "cpCollUtil:: splitPathByKey for %s error, status = %d", collEnt.collName, status ); return status; } snprintf( targChildPath, MAX_NAME_LEN, "%s/%s", targColl, childPath ); mkCollR( conn, targColl, targChildPath ); if ( rodsArgs->verbose == True ) { fprintf( stdout, "C- %s:\n", targChildPath ); } /* the child is a spec coll. need to drill down */ childDataObjCopyInp = *dataObjCopyInp; if ( collEnt.specColl.collClass != NO_SPEC_COLL ) childDataObjCopyInp.srcDataObjInp.specColl = &collEnt.specColl; status = cpCollUtil( conn, collEnt.collName, targChildPath, myRodsEnv, rodsArgs, &childDataObjCopyInp, rodsRestart ); if ( status < 0 && status != CAT_NO_ROWS_FOUND && status != SYS_SPEC_COLL_OBJ_NOT_EXIST ) { savedStatus = status; } } } 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 chksumCollUtil (rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp) { int status; int savedStatus = 0; char srcChildPath[MAX_NAME_LEN]; collHandle_t collHandle; collEnt_t collEnt; int queryFlags; if (srcColl == NULL) { rodsLog (LOG_ERROR, "chksumCollUtil: NULL srcColl input"); return (USER__NULL_INPUT_ERR); } fprintf (stdout, "C- %s:\n", srcColl); if (rodsArgs->resource == True) { #if 0 queryFlags = LONG_METADATA_FG | NO_TRIM_REPL_FG; #else queryFlags = INCLUDE_CONDINPUT_IN_QUERY; bzero (&collHandle, sizeof (collHandle)); replKeyVal (&dataObjInp->condInput, &collHandle.dataObjInp.condInput); #endif } else { queryFlags = 0; } status = rclOpenCollection (conn, srcColl, queryFlags, &collHandle); if (status < 0) { rodsLog (LOG_ERROR, "chksumCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } if (collHandle.rodsObjStat->specColl != NULL && collHandle.rodsObjStat->specColl->collClass != LINKED_COLL) { /* no trim for mounted coll */ rclCloseCollection (&collHandle); return 0; } while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) { if (collEnt.objType == DATA_OBJ_T) { snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName); /* screen unnecessary call to chksumDataObjUtil if user input a * resource. */ #if 0 if (rodsArgs->resource != True || rodsArgs->resourceString == NULL || strcmp (rodsArgs->resourceString, collEnt.resource) == 0) { #endif status = chksumDataObjUtil (conn, srcChildPath, myRodsEnv, rodsArgs, dataObjInp); if (status < 0) { rodsLogError (LOG_ERROR, status, "chksumCollUtil:chksumDataObjU failed for %s.stat = %d", srcChildPath, status); /* need to set global error here */ savedStatus = status; status = 0; } #if 0 } else { status = 0; } #endif } else if (collEnt.objType == COLL_OBJ_T) { dataObjInp_t childDataObjInp; childDataObjInp = *dataObjInp; if (collEnt.specColl.collClass != NO_SPEC_COLL) childDataObjInp.specColl = &collEnt.specColl; else childDataObjInp.specColl = NULL; status = chksumCollUtil (conn, collEnt.collName, myRodsEnv, rodsArgs, &childDataObjInp, collInp); if (status < 0 && status != CAT_NO_ROWS_FOUND) { return (status); } } } rclCloseCollection (&collHandle); if (savedStatus < 0) { return (savedStatus); } else if (status == CAT_NO_ROWS_FOUND) { return (0); } else { return (status); } }
int lsCollUtil (rcComm_t *conn, rodsPath_t *srcPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs) { int savedStatus = 0; char *srcColl; int status; int queryFlags; collHandle_t collHandle; collEnt_t collEnt; if (srcPath == NULL) { rodsLog (LOG_ERROR, "lsCollUtil: NULL srcPath input"); return (USER__NULL_INPUT_ERR); } srcColl = srcPath->outPath; /* print this collection */ printf ("%s:\n", srcColl); if (rodsArgs->accessControl == True) { printCollAcl (conn, srcColl); printCollInheritance (conn, srcColl); } queryFlags = DATA_QUERY_FIRST_FG; if (rodsArgs->veryLongOption == True) { /* need to check veryLongOption first since it will have both * veryLongOption and longOption flags on. */ queryFlags = queryFlags | VERY_LONG_METADATA_FG | NO_TRIM_REPL_FG; } else if (rodsArgs->longOption == True) { queryFlags |= LONG_METADATA_FG | NO_TRIM_REPL_FG;; } status = rclOpenCollection (conn, srcColl, queryFlags, &collHandle); if (status < 0) { rodsLog (LOG_ERROR, "lsCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) { if (collEnt.objType == DATA_OBJ_T) { if (rodsArgs->bundle == True) { char myPath[MAX_NAME_LEN]; snprintf (myPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName); lsSubfilesInBundle (conn, myPath, myRodsEnv, rodsArgs); } else { printDataCollEnt (&collEnt, queryFlags); if (rodsArgs->accessControl == True) { printDataAcl (conn, collEnt.dataId); } } } else { printCollCollEnt (&collEnt, queryFlags); /* need to drill down */ if (rodsArgs->recursive == True && strcmp (collEnt.collName, "/") != 0) { rodsPath_t tmpPath; memset (&tmpPath, 0, sizeof (tmpPath)); rstrcpy (tmpPath.outPath, collEnt.collName, MAX_NAME_LEN); status = lsCollUtil (conn, &tmpPath, myRodsEnv, rodsArgs); if (status < 0) savedStatus = status; } } } rclCloseCollection (&collHandle); if (savedStatus < 0 && savedStatus != CAT_NO_ROWS_FOUND) { return (savedStatus); } else { return (0); } }
int replCollUtil( rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, rodsRestart_t *rodsRestart ) { int status; int savedStatus = 0; collHandle_t collHandle; collEnt_t collEnt; char srcChildPath[MAX_NAME_LEN]; if ( srcColl == NULL ) { rodsLog( LOG_ERROR, "replCollUtil: NULL srcColl input" ); return ( USER__NULL_INPUT_ERR ); } if ( rodsArgs->recursive != True ) { rodsLog( LOG_ERROR, "replCollUtil: -r option must be used for getting %s collection", srcColl ); return ( USER_INPUT_OPTION_ERR ); } if ( rodsArgs->verbose == True ) { fprintf( stdout, "C- %s:\n", srcColl ); } bzero( &collHandle, sizeof( collHandle ) ); replKeyVal( &dataObjInp->condInput, &collHandle.dataObjInp.condInput ); status = rclOpenCollection( conn, srcColl, INCLUDE_CONDINPUT_IN_QUERY, &collHandle ); if ( status < 0 ) { rodsLog( LOG_ERROR, "replCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status ); return status; } if ( collHandle.rodsObjStat->specColl != NULL && collHandle.rodsObjStat->specColl->collClass != LINKED_COLL ) { /* no repl for mounted coll */ rclCloseCollection( &collHandle ); return 0; } while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) { if ( collEnt.objType == DATA_OBJ_T ) { snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName ); status = chkStateForResume( conn, rodsRestart, srcChildPath, rodsArgs, DATA_OBJ_T, &dataObjInp->condInput, 0 ); if ( status < 0 ) { /* restart failed */ break; } else if ( status == 0 ) { continue; } status = replDataObjUtil( conn, srcChildPath, collEnt.dataSize, myRodsEnv, rodsArgs, dataObjInp ); if ( status == SYS_COPY_ALREADY_IN_RESC ) { if ( rodsArgs->verbose == True ) { printf( "copy of %s already exists. Probably OK\n", srcChildPath ); } status = 0; } if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "replCollUtil: replDataObjUtil failed for %s. status = %d", srcChildPath, status ); if ( rodsRestart->fd > 0 ) { break; } else { savedStatus = status; } } else { status = procAndWrriteRestartFile( rodsRestart, srcChildPath ); } } else if ( collEnt.objType == COLL_OBJ_T ) { dataObjInp_t childDataObjInp; childDataObjInp = *dataObjInp; if ( collEnt.specColl.collClass != NO_SPEC_COLL ) { childDataObjInp.specColl = &collEnt.specColl; } else { childDataObjInp.specColl = NULL; } status = replCollUtil( conn, collEnt.collName, myRodsEnv, rodsArgs, &childDataObjInp, rodsRestart ); if ( status < 0 && status != CAT_NO_ROWS_FOUND ) { savedStatus = status; } } } rclCloseCollection( &collHandle ); if ( savedStatus < 0 ) { return ( savedStatus ); } else if ( status == CAT_NO_ROWS_FOUND ) { return ( 0 ); } else { return ( status ); } }
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); }
int rsyncCollToDirUtil (rcComm_t *conn, rodsPath_t *srcPath, rodsPath_t *targPath, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjOprInp) { int status = 0; int savedStatus = 0; char *srcColl, *targDir; 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; dataObjInp_t childDataObjInp; if (srcPath == NULL || targPath == NULL) { rodsLog (LOG_ERROR, "rsyncCollToDirUtil: NULL srcPath or targPath input"); return (USER__NULL_INPUT_ERR); } srcColl = srcPath->outPath; targDir = targPath->outPath; if (rodsArgs->recursive != True) { rodsLog (LOG_ERROR, "rsyncCollToDirUtil: -r option must be used for collection %s", targDir); 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, "rsyncCollToDirUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } memset (&mySrcPath, 0, sizeof (mySrcPath)); memset (&myTargPath, 0, sizeof (myTargPath)); myTargPath.objType = LOCAL_FILE_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", targDir, collEnt.collName + collLen, collEnt.dataName); #else snprintf (myTargPath.outPath, MAX_NAME_LEN, "%s/%s", targDir, 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; mySrcPath.objMode = collEnt.dataMode; rstrcpy (mySrcPath.chksum, collEnt.chksum, CHKSUM_LEN); mySrcPath.objState = EXIST_ST; getFileType (&myTargPath); status = rsyncDataToFileUtil (conn, &mySrcPath, &myTargPath, myRodsEnv, rodsArgs, dataObjOprInp); if (status < 0) { rodsLogError (LOG_ERROR, status, "rsyncCollUtil: rsyncDataObjUtil failed for %s. status = %d", mySrcPath.outPath, status); /* need to set global error here */ savedStatus = status; status = 0; } } else if (collEnt.objType == COLL_OBJ_T) { #if 0 snprintf (targChildPath, MAX_NAME_LEN, "%s/%s", targDir, collEnt.collName + collLen); #else if ((status = splitPathByKey ( collEnt.collName, parPath, childPath, '/')) < 0) { rodsLogError (LOG_ERROR, status, "rsyncCollToDirUtil:: splitPathByKey for %s error, stat=%d", collEnt.collName, status); return (status); } snprintf (targChildPath, MAX_NAME_LEN, "%s/%s", targDir, childPath); #endif /* only do the sync if no -l option specified */ if ( rodsArgs->longOption != True ) { mkdirR (targDir, targChildPath, 0750); } #if 0 if (collEnt.specColl.collClass != NO_SPEC_COLL) { #endif /* the child is a spec coll. need to drill down */ childDataObjInp = *dataObjOprInp; if (collEnt.specColl.collClass != NO_SPEC_COLL) childDataObjInp.specColl = &collEnt.specColl; else childDataObjInp.specColl = NULL; rstrcpy (myTargPath.outPath, targChildPath, MAX_NAME_LEN); rstrcpy (mySrcPath.outPath, collEnt.collName, MAX_NAME_LEN); status = rsyncCollToDirUtil (conn, &mySrcPath, &myTargPath, myRodsEnv, rodsArgs, &childDataObjInp); 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 irodsReaddir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { char collPath[MAX_NAME_LEN]; collHandle_t collHandle; collEnt_t collEnt; int status; #ifdef CACHE_FUSE_PATH struct stat stbuf; pathCache_t *tmpPathCache; #endif /* don't know why we need this. the example have them */ (void) offset; (void) fi; iFuseConn_t *iFuseConn = NULL; rodsLog (LOG_DEBUG, "irodsReaddir: %s", path); filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); status = parseRodsPathStr ((char *) (path + 1), &MyRodsEnv, collPath); if (status < 0) { rodsLogError (LOG_ERROR, status, "irodsReaddir: parseRodsPathStr of %s error", path); /* use ENOTDIR for this type of error */ return -ENOTDIR; } iFuseConn = getAndUseConnByPath ((char *) path, &MyRodsEnv, &status); status = rclOpenCollection (iFuseConn->conn, collPath, 0, &collHandle); if (status < 0) { if (isReadMsgError (status)) { ifuseReconnect (iFuseConn); status = rclOpenCollection (iFuseConn->conn, collPath, 0, &collHandle); } if (status < 0) { rodsLog (LOG_ERROR, "irodsReaddir: rclOpenCollection of %s error. status = %d", collPath, status); unuseIFuseConn (iFuseConn); return -ENOENT; } } while ((status = rclReadCollection (iFuseConn->conn, &collHandle, &collEnt)) >= 0) { char myDir[MAX_NAME_LEN], mySubDir[MAX_NAME_LEN]; #ifdef CACHE_FUSE_PATH char childPath[MAX_NAME_LEN]; bzero (&stbuf, sizeof (struct stat)); #endif if (collEnt.objType == DATA_OBJ_T) { filler (buf, collEnt.dataName, NULL, 0); #ifdef CACHE_FUSE_PATH if (strcmp (path, "/") == 0) { snprintf (childPath, MAX_NAME_LEN, "/%s", collEnt.dataName); } else { snprintf (childPath, MAX_NAME_LEN, "%s/%s", path, collEnt.dataName); } if (lookupPathExist ((char *) childPath, &tmpPathCache) != 1) { fillFileStat (&stbuf, collEnt.dataMode, collEnt.dataSize, atoi (collEnt.createTime), atoi (collEnt.modifyTime), atoi (collEnt.modifyTime)); pathExist (childPath, NULL, &stbuf, &tmpPathCache); } #endif } else if (collEnt.objType == COLL_OBJ_T) { splitPathByKey (collEnt.collName, myDir, mySubDir, '/'); if(mySubDir[0] != '\0') { filler (buf, mySubDir, NULL, 0); #ifdef CACHE_FUSE_PATH if (strcmp (path, "/") == 0) { snprintf (childPath, MAX_NAME_LEN, "/%s", mySubDir); } else { snprintf (childPath, MAX_NAME_LEN, "%s/%s", path, mySubDir); } if (lookupPathExist ((char *) childPath, &tmpPathCache) != 1) { fillDirStat (&stbuf, atoi (collEnt.createTime), atoi (collEnt.modifyTime), atoi (collEnt.modifyTime)); pathExist (childPath, NULL, &stbuf, &tmpPathCache); } #endif } } } rclCloseCollection (&collHandle); unuseIFuseConn (iFuseConn); return (0); }
int phymvCollUtil (rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp) { int status; int savedStatus = 0; #if 0 int collLen; #endif collHandle_t collHandle; collEnt_t collEnt; char srcChildPath[MAX_NAME_LEN]; if (srcColl == NULL) { rodsLog (LOG_ERROR, "phymvCollUtil: NULL srcColl input"); return (USER__NULL_INPUT_ERR); } if (rodsArgs->recursive != True) { rodsLog (LOG_ERROR, "phymvCollUtil: -r option must be used for getting %s collection", srcColl); return (USER_INPUT_OPTION_ERR); } if (rodsArgs->verbose == True) { fprintf (stdout, "C- %s:\n", srcColl); } #if 0 status = rclOpenCollection (conn, srcColl, RECUR_QUERY_FG, &collHandle); #else status = rclOpenCollection (conn, srcColl, 0, &collHandle); #endif if (status < 0) { rodsLog (LOG_ERROR, "phymvCollUtil: rclOpenCollection of %s error. status = %d", srcColl, status); return status; } #if 0 collLen = strlen (srcColl); collLen = getOpenedCollLen (&collHandle); #else if (collHandle.rodsObjStat->specColl != NULL && collHandle.rodsObjStat->specColl->collClass != LINKED_COLL) { /* no trim for mounted coll */ rclCloseCollection (&collHandle); return 0; } #endif while ((status = rclReadCollection (conn, &collHandle, &collEnt)) >= 0) { if (collEnt.objType == DATA_OBJ_T) { snprintf (srcChildPath, MAX_NAME_LEN, "%s/%s", collEnt.collName, collEnt.dataName); status = phymvDataObjUtil (conn, srcChildPath, myRodsEnv, rodsArgs, dataObjInp); if (status < 0) { rodsLogError (LOG_ERROR, status, "phymvCollUtil: phymvDataObjUtil failed for %s. status = %d", srcChildPath, status); /* need to set global error here */ savedStatus = status; status = 0; } } else if (collEnt.objType == COLL_OBJ_T) { dataObjInp_t childDataObjInp; childDataObjInp = *dataObjInp; if (collEnt.specColl.collClass != NO_SPEC_COLL) childDataObjInp.specColl = &collEnt.specColl; status = phymvCollUtil (conn, collEnt.collName, myRodsEnv, rodsArgs, &childDataObjInp); if (status < 0 && status != CAT_NO_ROWS_FOUND) { savedStatus = status; } } } rclCloseCollection (&collHandle); if (savedStatus < 0) { return (savedStatus); } else if (status == CAT_NO_ROWS_FOUND) { return (0); } else { return (status); } }