int _rsFileChksum( rsComm_t *rsComm, fileChksumInp_t *fileChksumInp, char **chksumStr ) { int status; if ( !*chksumStr ) { *chksumStr = ( char* )malloc( sizeof( char ) * NAME_LEN ); } status = fileChksum( rsComm, fileChksumInp->objPath, fileChksumInp->fileName, fileChksumInp->rescHier, fileChksumInp->orig_chksum, *chksumStr ); if ( status < 0 ) { rodsLog( LOG_DEBUG, "_rsFileChksum: fileChksum for %s, status = %d", fileChksumInp->fileName, status ); free( *chksumStr ); *chksumStr = NULL; } return status; }
int bundleAndRegSubFiles( rsComm_t *rsComm, int l1descInx, char *phyBunDir, char *collection, bunReplCacheHeader_t *bunReplCacheHeader, int chksumFlag ) { // JMC - backport 4528 int status; openedDataObjInp_t dataObjCloseInp; bunReplCache_t *tmpBunReplCache, *nextBunReplCache; regReplica_t regReplicaInp; dataObjInp_t dataObjUnlinkInp; keyValPair_t regParam; // JMC - backport 4528 modDataObjMeta_t modDataObjMetaInp; // JMC - backport 4528 int savedStatus = 0; bzero( &dataObjCloseInp, sizeof( dataObjCloseInp ) ); dataObjCloseInp.l1descInx = l1descInx; if ( bunReplCacheHeader->numSubFiles == 0 ) { bzero( &dataObjUnlinkInp, sizeof( dataObjUnlinkInp ) ); rstrcpy( dataObjUnlinkInp.objPath, L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN ); dataObjUnlinkS( rsComm, &dataObjUnlinkInp, L1desc[l1descInx].dataObjInfo ); L1desc[l1descInx].bytesWritten = 0; rsDataObjClose( rsComm, &dataObjCloseInp ); bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) ); return 0; } status = phyBundle( rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir, collection, CREATE_TAR_OPR ); // JMC - backport 4643 if ( status < 0 ) { rodsLog( LOG_ERROR, "bundleAndRegSubFiles: rsStructFileSync of %s error. stat = %d", L1desc[l1descInx].dataObjInfo->objPath, status ); rmLinkedFilesInUnixDir( phyBunDir ); rmdir( phyBunDir ); rsDataObjClose( rsComm, &dataObjCloseInp ); tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead; while ( tmpBunReplCache != NULL ) { nextBunReplCache = tmpBunReplCache->next; free( tmpBunReplCache ); tmpBunReplCache = nextBunReplCache; // JMC - backport 4579 } bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) ); return status; } else { /* mark it was written so the size would be adjusted */ L1desc[l1descInx].bytesWritten = 1; } /* now register a replica for each subfile */ tmpBunReplCache = bunReplCacheHeader->bunReplCacheHead; if ( tmpBunReplCache == NULL ) { rmdir( phyBunDir ); bzero( &dataObjUnlinkInp, sizeof( dataObjUnlinkInp ) ); rstrcpy( dataObjUnlinkInp.objPath, L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN ); dataObjUnlinkS( rsComm, &dataObjUnlinkInp, L1desc[l1descInx].dataObjInfo ); L1desc[l1descInx].bytesWritten = 0; rsDataObjClose( rsComm, &dataObjCloseInp ); bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) ); return 0; } bzero( ®ReplicaInp, sizeof( regReplicaInp ) ); regReplicaInp.srcDataObjInfo = ( dataObjInfo_t* )malloc( sizeof( dataObjInfo_t ) ); regReplicaInp.destDataObjInfo = ( dataObjInfo_t* )malloc( sizeof( dataObjInfo_t ) ); bzero( regReplicaInp.srcDataObjInfo, sizeof( dataObjInfo_t ) ); bzero( regReplicaInp.destDataObjInfo, sizeof( dataObjInfo_t ) ); addKeyVal( ®ReplicaInp.condInput, ADMIN_KW, "" ); rstrcpy( regReplicaInp.destDataObjInfo->rescName, BUNDLE_RESC, NAME_LEN ); rstrcpy( regReplicaInp.destDataObjInfo->filePath, L1desc[l1descInx].dataObjInfo->objPath, MAX_NAME_LEN ); rstrcpy( regReplicaInp.destDataObjInfo->rescHier, L1desc[l1descInx].dataObjInfo->rescHier, MAX_NAME_LEN ); // =-=-=-=-=-=-=- // JMC - backport 4528 if ( chksumFlag != 0 ) { bzero( &modDataObjMetaInp, sizeof( modDataObjMetaInp ) ); bzero( ®Param, sizeof( regParam ) ); modDataObjMetaInp.dataObjInfo = regReplicaInp.destDataObjInfo; modDataObjMetaInp.regParam = ®Param; } // =-=-=-=-=-=-=- /* close here because dataObjInfo is still being used */ rsDataObjClose( rsComm, &dataObjCloseInp ); while ( tmpBunReplCache != NULL ) { char subPhyPath[MAX_NAME_LEN]; nextBunReplCache = tmpBunReplCache->next; /* rm the hard link here */ snprintf( subPhyPath, MAX_NAME_LEN, "%s/%lld", phyBunDir, tmpBunReplCache->dataId ); // =-=-=-=-=-=-=- // JMC - backport 4528 if ( chksumFlag != 0 ) { status = fileChksum( rsComm, regReplicaInp.destDataObjInfo->filePath, subPhyPath, regReplicaInp.destDataObjInfo->rescHier, 0, tmpBunReplCache->chksumStr ); if ( status < 0 ) { savedStatus = status; rodsLogError( LOG_ERROR, status, "bundleAndRegSubFiles: fileChksum error for %s", tmpBunReplCache->objPath ); } } // =-=-=-=-=-=-=- unlink( subPhyPath ); /* register the replica */ rstrcpy( regReplicaInp.srcDataObjInfo->objPath, tmpBunReplCache->objPath, MAX_NAME_LEN ); regReplicaInp.srcDataObjInfo->dataId = regReplicaInp.destDataObjInfo->dataId = tmpBunReplCache->dataId; regReplicaInp.srcDataObjInfo->replNum = tmpBunReplCache->srcReplNum; status = rsRegReplica( rsComm, ®ReplicaInp ); if ( status < 0 ) { savedStatus = status; rodsLog( LOG_ERROR, "bundleAndRegSubFiles: rsRegReplica error for %s. stat = %d", tmpBunReplCache->objPath, status ); } // =-=-=-=-=-=-=- // JMC - backport 4528 if ( chksumFlag != 0 ) { addKeyVal( ®Param, CHKSUM_KW, tmpBunReplCache->chksumStr ); // avoid triggering file operations addKeyVal( ®Param, IN_PDMO_KW, "" ); status = rsModDataObjMeta( rsComm, &modDataObjMetaInp ); clearKeyVal( ®Param ); if ( status < 0 ) { savedStatus = status; rodsLogError( LOG_ERROR, status, "bundleAndRegSubFiles: rsModDataObjMeta error for %s.", tmpBunReplCache->objPath ); } } // =-=-=-=-=-=-=- free( tmpBunReplCache ); tmpBunReplCache = nextBunReplCache; } clearKeyVal( ®ReplicaInp.condInput ); free( regReplicaInp.srcDataObjInfo ); free( regReplicaInp.destDataObjInfo ); bzero( bunReplCacheHeader, sizeof( bunReplCacheHeader_t ) ); rmdir( phyBunDir ); if ( status >= 0 && savedStatus < 0 ) { return savedStatus; } else { return status; } }