int rsCollRepl (rsComm_t *rsComm, collInp_t *collReplInp, collOprStat_t **collOprStat) { int status; dataObjInp_t dataObjInp; collEnt_t *collEnt; int handleInx; transferStat_t myTransStat; int totalFileCnt; int fileCntPerStatOut; int savedStatus = 0; int remoteFlag; rodsServerHost_t *rodsServerHost; /* try to connect to dest resc */ bzero (&dataObjInp, sizeof (dataObjInp)); rstrcpy (dataObjInp.objPath, collReplInp->collName, MAX_NAME_LEN); remoteFlag = getAndConnRemoteZone (rsComm, &dataObjInp, &rodsServerHost, REMOTE_CREATE); if (remoteFlag < 0) { return (remoteFlag); } else if (remoteFlag == REMOTE_HOST) { int retval; retval = _rcCollRepl (rodsServerHost->conn, collReplInp, collOprStat); if (retval < 0) return retval; status = svrSendZoneCollOprStat (rsComm, rodsServerHost->conn, *collOprStat, retval); return status; } fileCntPerStatOut = FILE_CNT_PER_STAT_OUT; if (collOprStat != NULL) *collOprStat = NULL; collReplInp->flags = RECUR_QUERY_FG; handleInx = rsOpenCollection (rsComm, collReplInp); if (handleInx < 0) { rodsLog (LOG_ERROR, "rsCollRepl: rsOpenCollection of %s error. status = %d", collReplInp->collName, handleInx); return (handleInx); } if (collOprStat != NULL) { *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t)); memset (*collOprStat, 0, sizeof (collOprStat_t)); } if (CollHandle[handleInx].rodsObjStat->specColl != NULL) { rodsLog (LOG_ERROR, "rsCollRepl: unable to replicate mounted collection %s", collReplInp->collName); rsCloseCollection (rsComm, &handleInx); return (0); } while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) { if (collEnt->objType == DATA_OBJ_T) { if (totalFileCnt == 0) totalFileCnt = CollHandle[handleInx].dataObjSqlResult.totalRowCount; bzero (&dataObjInp, sizeof (dataObjInp)); snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s", collEnt->collName, collEnt->dataName); dataObjInp.condInput = collReplInp->condInput; memset (&myTransStat, 0, sizeof (myTransStat)); status = _rsDataObjRepl (rsComm, &dataObjInp, &myTransStat, NULL); if (status == SYS_COPY_ALREADY_IN_RESC) { savedStatus = status; status = 0; } if (status < 0) { rodsLogError (LOG_ERROR, status, "rsCollRepl: rsDataObjRepl failed for %s. status = %d", dataObjInp.objPath, status); savedStatus = status; break; } else { if (collOprStat != NULL) { (*collOprStat)->bytesWritten += myTransStat.bytesWritten; (*collOprStat)->filesCnt ++; } } if (collOprStat != NULL && (*collOprStat)->filesCnt >= fileCntPerStatOut) { rstrcpy ((*collOprStat)->lastObjPath, dataObjInp.objPath, MAX_NAME_LEN); (*collOprStat)->totalFileCnt = totalFileCnt; status = svrSendCollOprStat (rsComm, *collOprStat); if (status < 0) { rodsLogError (LOG_ERROR, status, "rsCollRepl: svrSendCollOprStat failed for %s. status = %d", dataObjInp.objPath, status); *collOprStat = NULL; savedStatus = status; break; } *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t)); memset (*collOprStat, 0, sizeof (collOprStat_t)); } } free (collEnt); /* just free collEnt but not content */ } rsCloseCollection (rsComm, &handleInx); return (savedStatus); }
int _rsPhyRmColl( rsComm_t *rsComm, collInp_t *rmCollInp, dataObjInfo_t *dataObjInfo, collOprStat_t **collOprStat ) { char *tmpValue; int status; collInp_t openCollInp; collEnt_t *collEnt; int handleInx; dataObjInp_t dataObjInp; collInp_t tmpCollInp; int rmtrashFlag = 0; int savedStatus = 0; int fileCntPerStatOut = FILE_CNT_PER_STAT_OUT; int entCnt = 0; ruleExecInfo_t rei; collInfo_t collInfo; memset( &openCollInp, 0, sizeof( openCollInp ) ); rstrcpy( openCollInp.collName, rmCollInp->collName, MAX_NAME_LEN ); /* cannot query recur because collection is sorted in wrong order */ openCollInp.flags = 0; handleInx = rsOpenCollection( rsComm, &openCollInp ); if ( handleInx < 0 ) { rodsLog( LOG_ERROR, "_rsPhyRmColl: rsOpenCollection of %s error. status = %d", openCollInp.collName, handleInx ); return handleInx; } memset( &dataObjInp, 0, sizeof( dataObjInp ) ); memset( &tmpCollInp, 0, sizeof( tmpCollInp ) ); /* catch the UNREG_OPR */ dataObjInp.oprType = tmpCollInp.oprType = rmCollInp->oprType; if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) { if ( CollHandle[handleInx].rodsObjStat != NULL ) { /* when a collection is moved, the modfiyTime of the object in * the collectin does not change. So, we'll depend on the * modfiyTime of the collection */ int ageLimit = atoi( tmpValue ) * 60; int modifyTime = atoi( CollHandle[handleInx].rodsObjStat->modifyTime ); if ( ( time( 0 ) - modifyTime ) < ageLimit ) { rsCloseCollection( rsComm, &handleInx ); return 0; } } addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue ); addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue ); } addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" ); addKeyVal( &tmpCollInp.condInput, FORCE_FLAG_KW, "" ); if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) { addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue ); addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue ); } if ( collOprStat != NULL && *collOprStat == NULL ) { *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) ); memset( *collOprStat, 0, sizeof( collOprStat_t ) ); } if ( getValByKey( &rmCollInp->condInput, ADMIN_RMTRASH_KW ) != NULL ) { if ( isTrashPath( rmCollInp->collName ) == False ) { return SYS_INVALID_FILE_PATH; } if ( rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) { return CAT_INSUFFICIENT_PRIVILEGE_LEVEL; } addKeyVal( &tmpCollInp.condInput, ADMIN_RMTRASH_KW, "" ); addKeyVal( &dataObjInp.condInput, ADMIN_RMTRASH_KW, "" ); rmtrashFlag = 2; } else if ( getValByKey( &rmCollInp->condInput, RMTRASH_KW ) != NULL ) { if ( isTrashPath( rmCollInp->collName ) == False ) { return SYS_INVALID_FILE_PATH; } addKeyVal( &tmpCollInp.condInput, RMTRASH_KW, "" ); addKeyVal( &dataObjInp.condInput, RMTRASH_KW, "" ); rmtrashFlag = 1; } // =-=-=-=-=-=-=- // JMC - backport 4552 if ( getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) { addKeyVal( &tmpCollInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" ); addKeyVal( &dataObjInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" ); } // =-=-=-=-=-=-=- while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) { if ( entCnt == 0 ) { entCnt ++; /* cannot rm non-empty home collection */ if ( isHomeColl( rmCollInp->collName ) ) { return CANT_RM_NON_EMPTY_HOME_COLL; } } if ( collEnt->objType == DATA_OBJ_T ) { snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s", collEnt->collName, collEnt->dataName ); status = rsDataObjUnlink( rsComm, &dataObjInp ); if ( status < 0 ) { rodsLog( LOG_ERROR, "_rsPhyRmColl:rsDataObjUnlink failed for %s. stat = %d", dataObjInp.objPath, status ); /* need to set global error here */ savedStatus = status; } else if ( collOprStat != NULL ) { ( *collOprStat )->filesCnt ++; if ( ( *collOprStat )->filesCnt >= fileCntPerStatOut ) { rstrcpy( ( *collOprStat )->lastObjPath, dataObjInp.objPath, MAX_NAME_LEN ); status = svrSendCollOprStat( rsComm, *collOprStat ); if ( status < 0 ) { rodsLogError( LOG_ERROR, status, "_rsPhyRmColl: svrSendCollOprStat failed for %s. status = %d", rmCollInp->collName, status ); *collOprStat = NULL; savedStatus = status; break; } *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) ); memset( *collOprStat, 0, sizeof( collOprStat_t ) ); } } } else if ( collEnt->objType == COLL_OBJ_T ) { if ( strcmp( collEnt->collName, rmCollInp->collName ) == 0 ) { continue; /* duplicate */ } rstrcpy( tmpCollInp.collName, collEnt->collName, MAX_NAME_LEN ); if ( collEnt->specColl.collClass != NO_SPEC_COLL ) { if ( strcmp( collEnt->collName, collEnt->specColl.collection ) == 0 ) { continue; /* no mount point */ } } initReiWithCollInp( &rei, rsComm, &tmpCollInp, &collInfo ); status = applyRule( "acPreprocForRmColl", NULL, &rei, NO_SAVE_REI ); if ( status < 0 ) { if ( rei.status < 0 ) { status = rei.status; } rodsLog( LOG_ERROR, "_rsPhyRmColl:acPreprocForRmColl error for %s,stat=%d", tmpCollInp.collName, status ); return status; } status = _rsRmCollRecur( rsComm, &tmpCollInp, collOprStat ); rei.status = status; rei.status = applyRule( "acPostProcForRmColl", NULL, &rei, NO_SAVE_REI ); if ( rei.status < 0 ) { rodsLog( LOG_ERROR, "_rsRmColl:acPostProcForRmColl error for %s,stat=%d", tmpCollInp.collName, status ); } } if ( status < 0 ) { savedStatus = status; } free( collEnt ); /* just free collEnt but not content */ } rsCloseCollection( rsComm, &handleInx ); if ( ( rmtrashFlag > 0 && ( isTrashHome( rmCollInp->collName ) > 0 || // JMC - backport 4561 isOrphanPath( rmCollInp->collName ) == is_ORPHAN_HOME ) ) || ( isBundlePath( rmCollInp->collName ) == True && getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) ) { /* don't rm user's home trash coll or orphan collection */ status = 0; } else { if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL ) { if ( dataObjInfo->specColl->collClass == LINKED_COLL ) { rstrcpy( rmCollInp->collName, dataObjInfo->objPath, MAX_NAME_LEN ); status = svrUnregColl( rsComm, rmCollInp ); } else { status = l3Rmdir( rsComm, dataObjInfo ); } } else { status = svrUnregColl( rsComm, rmCollInp ); if ( status < 0 ) { savedStatus = status; } } } clearKeyVal( &tmpCollInp.condInput ); clearKeyVal( &dataObjInp.condInput ); return savedStatus; }