Example #1
0
int
dataObjCreateAndReg( rsComm_t *rsComm, int l1descInx ) {

    dataObjInfo_t *myDataObjInfo = L1desc[l1descInx].dataObjInfo;
    int status;

    status = dataCreate( rsComm, l1descInx );

    if ( status < 0 ) {
        return ( status );
    }

    /* only register new copy */
    status = svrRegDataObj( rsComm, myDataObjInfo );
    if ( status < 0 ) {
        l3Unlink( rsComm, myDataObjInfo );
        rodsLog( LOG_NOTICE,
                 "dataObjCreateAndReg: rsRegDataObj for %s failed, status = %d",
                 myDataObjInfo->objPath, status );
        return ( status );
    }
    else {
        myDataObjInfo->replNum = status;
        return ( 0 );
    }
}
Example #2
0
/**
 * \fn msiRegisterData(ruleExecInfo_t *rei)
 *
 * \brief Register a new data object 
 *
 * \module framework
 *
 * \since pre-2.1
 *
 * \author Arcot Rajasekar 
 * \date    2008
 *
 * \note  Use this only internally as data object information has to be in rei.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence $doi
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified file metadata
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre none
 * \post none
 * \sa none
**/
int
msiRegisterData(ruleExecInfo_t *rei)
{  
  int status;
  dataObjInfo_t *myDataObjInfo;


  /**** This is Just a Test Stub  ****/
  if (reTestFlag > 0 ) {
    if (reTestFlag == COMMAND_TEST_1 || reTestFlag == HTML_TEST_1) {
      print_doi(rei->doi);
    }
    else {
      rodsLog (LOG_NOTICE,"   Calling chlRegDataObj\n");
      print_doi(rei->doi);
    }
    if (reLoopBackFlag > 0)
      return(0);
  }
  /**** This is Just a Test Stub  ****/

  myDataObjInfo = L1desc[rei->l1descInx].dataObjInfo;
  status = svrRegDataObj (rei->rsComm, myDataObjInfo);
  if (status < 0) {
    rodsLog (LOG_NOTICE,
	     "msiRegisterData: rsRegDataObj for %s failed, status = %d",
	     myDataObjInfo->objPath, status);
    return (status);
  } else {
    myDataObjInfo->replNum = status;
    return (0);
  }
}
Example #3
0
int
_l3DataPutSingleBuf( rsComm_t *rsComm, int l1descInx, dataObjInp_t *dataObjInp,
                     bytesBuf_t *dataObjInpBBuf ) {
    int status = 0;
    int bytesWritten;
    dataObjInfo_t *myDataObjInfo;

    myDataObjInfo = L1desc[l1descInx].dataObjInfo;

    bytesWritten = l3FilePutSingleBuf( rsComm, l1descInx, dataObjInpBBuf );
    if ( bytesWritten >= 0 ) {
        if ( L1desc[l1descInx].replStatus == NEWLY_CREATED_COPY &&
                myDataObjInfo->specColl == NULL &&
                L1desc[l1descInx].remoteZoneHost == NULL ) {
            /* the check for remoteZoneHost host is not needed because
             * the put would have done in the remote zone. But it make
             * the code easier to read (similar ro copy).
             */
            status = svrRegDataObj( rsComm, myDataObjInfo );
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "l3DataPutSingleBuf: rsRegDataObj for %s failed, status = %d",
                         myDataObjInfo->objPath, status );
                if ( status != CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                    l3Unlink( rsComm, myDataObjInfo );
                }
                return ( status );
            }
            else {
                myDataObjInfo->replNum = status;
            }
        }
        /* myDataObjInfo->dataSize = bytesWritten; update size problem */
        if ( bytesWritten == 0 && myDataObjInfo->dataSize > 0 ) {
            /* overwrite with 0 len file */
            L1desc[l1descInx].bytesWritten = 1;
        }
        else {
            L1desc[l1descInx].bytesWritten = bytesWritten;
        }
    }
    L1desc[l1descInx].dataSize = dataObjInp->dataSize;

    return ( bytesWritten );
}
Example #4
0
int
filePathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, 
rescInfo_t *rescInfo)
{
    dataObjInfo_t dataObjInfo;
    int status;

    initDataObjInfoWithInp (&dataObjInfo, phyPathRegInp);
    dataObjInfo.replStatus = NEWLY_CREATED_COPY;
    dataObjInfo.rescInfo = rescInfo;
    rstrcpy (dataObjInfo.rescName, rescInfo->rescName, NAME_LEN);

    if (dataObjInfo.dataSize <= 0 && 
      (dataObjInfo.dataSize = getSizeInVault (rsComm, &dataObjInfo)) < 0) {
	status = (int) dataObjInfo.dataSize;
        rodsLog (LOG_ERROR,
         "filePathReg: getSizeInVault for %s failed, status = %d",
          dataObjInfo.objPath, status);
	return (status);
    }

    status = svrRegDataObj (rsComm, &dataObjInfo);
    if (status < 0) {
        rodsLog (LOG_ERROR,
         "filePathReg: rsRegDataObj for %s failed, status = %d",
          dataObjInfo.objPath, status);
    } else {
        ruleExecInfo_t rei;
        initReiWithDataObjInp (&rei, rsComm, phyPathRegInp);
	rei.doi = &dataObjInfo;
	rei.status = status;
        rei.status = applyRule ("acPostProcForFilePathReg", NULL, &rei,
          NO_SAVE_REI);
    }

    return (status);
}
Example #5
0
int
_l3DataPutSingleBuf( rsComm_t *rsComm, int l1descInx, dataObjInp_t *dataObjInp,
                     bytesBuf_t *dataObjInpBBuf ) {
    int status = 0;
    dataObjInfo_t *myDataObjInfo = L1desc[l1descInx].dataObjInfo;

    int bytesWritten = l3FilePutSingleBuf( rsComm, l1descInx, dataObjInpBBuf );
    if ( bytesWritten >= 0 ) {
        if ( L1desc[l1descInx].replStatus == NEWLY_CREATED_COPY &&
                myDataObjInfo->specColl == NULL &&
                L1desc[l1descInx].remoteZoneHost == NULL ) {

            /* the check for remoteZoneHost host is not needed because
             * the put would have done in the remote zone. But it make
             * the code easier to read (similar ro copy).
             */
            status = svrRegDataObj( rsComm, myDataObjInfo );
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "l3DataPutSingleBuf: rsRegDataObj for %s failed, status = %d",
                         myDataObjInfo->objPath, status );
                if ( status != CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                    l3Unlink( rsComm, myDataObjInfo );
                }
                return status;
            }
            else {
                myDataObjInfo->replNum = status;
            }

        }
        /* myDataObjInfo->dataSize = bytesWritten; update size problem */
        if ( bytesWritten == 0 && myDataObjInfo->dataSize > 0 ) {
            /* overwrite with 0 len file */
            L1desc[l1descInx].bytesWritten = 1;
        }
        else {
            L1desc[l1descInx].bytesWritten = bytesWritten;
        }

        // special case of zero length files, trigger the fileModified
        // operation for execution of coordinating resource logic
        if ( 0 == dataObjInp->dataSize ) {
            irods::file_object_ptr file_obj(
                new irods::file_object(
                    rsComm,
                    myDataObjInfo ) );

            char* pdmo_kw = getValByKey( &myDataObjInfo->condInput, IN_PDMO_KW );
            if ( pdmo_kw != NULL ) {
                file_obj->in_pdmo( pdmo_kw );
            }
            irods::error ret = fileModified( rsComm, file_obj );
            if ( !ret.ok() ) {
                std::stringstream msg;
                msg << "fileModified failed for [";
                msg << myDataObjInfo->objPath;
                msg << "]";
                ret = PASSMSG( msg.str(), ret );
                irods::log( ret );
                status = ret.code();
            }
        }
    }

    L1desc[l1descInx].dataSize = dataObjInp->dataSize;

    return bytesWritten;
}
Example #6
0
int
_rsDataObjCopy( rsComm_t *rsComm, int destL1descInx, int existFlag,
                transferStat_t **transStat ) {
    dataObjInp_t *srcDataObjInp, *destDataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    dataObjInfo_t *srcDataObjInfo, *destDataObjInfo;
    int srcL1descInx;
    int status = 0, status2;

    destDataObjInp  = L1desc[destL1descInx].dataObjInp;
    destDataObjInfo = L1desc[destL1descInx].dataObjInfo;
    srcL1descInx    = L1desc[destL1descInx].srcL1descInx;

    srcDataObjInp  = L1desc[srcL1descInx].dataObjInp;
    srcDataObjInfo = L1desc[srcL1descInx].dataObjInfo;

    if ( destDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInp is NULL" );
        return -1;
    }
    if ( destDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: destDataObjInfo is NULL" );
        return -1;
    }
    if ( srcDataObjInp == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInp is NULL" );
        return -1;
    }
    if ( srcDataObjInfo == NULL ) { // JMC cppcheck - null ptr ref
        rodsLog( LOG_ERROR, "_rsDataObjCopy: :: srcDataObjInfo is NULL" );
        return -1;
    }

    if ( L1desc[srcL1descInx].l3descInx <= 2 ) {

        /* no physical file was opened */
        status = l3DataCopySingleBuf( rsComm, destL1descInx );

        /* has not been registered yet because of NO_OPEN_FLAG_KW */
        if ( status    >= 0                    &&
                existFlag == 0                    &&
                destDataObjInfo->specColl == NULL &&
                L1desc[destL1descInx].remoteZoneHost == NULL ) {
            /* If the dest is in remote zone, register in _rsDataObjClose there */
            status = svrRegDataObj( rsComm, destDataObjInfo );
            if ( status == CAT_UNKNOWN_COLLECTION ) {
                /* collection does not exist. make one */
                char parColl[MAX_NAME_LEN], child[MAX_NAME_LEN];
                splitPathByKey( destDataObjInfo->objPath, parColl, MAX_NAME_LEN, child, MAX_NAME_LEN, '/' );
                status = svrRegDataObj( rsComm, destDataObjInfo );
                rsMkCollR( rsComm, "/", parColl );
                status = svrRegDataObj( rsComm, destDataObjInfo );
            }
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "_rsDataObjCopy: svrRegDataObj for %s failed, status = %d",
                         destDataObjInfo->objPath, status );
                return status;
            }
        }

    }
    else {
        if ( srcDataObjInfo != NULL ) {
            destDataObjInp->numThreads = getNumThreads( rsComm, srcDataObjInfo->dataSize, destDataObjInp->numThreads, NULL,
                                         destDataObjInfo->rescHier, srcDataObjInfo->rescHier, 0 );

        }

        srcDataObjInp->numThreads = destDataObjInp->numThreads;

        status = dataObjCopy( rsComm, destL1descInx );
    }

    memset( &dataObjCloseInp, 0, sizeof( dataObjCloseInp ) );
    dataObjCloseInp.l1descInx = destL1descInx;
    if ( status >= 0 ) {
        *transStat = ( transferStat_t* )malloc( sizeof( transferStat_t ) );
        memset( *transStat, 0, sizeof( transferStat_t ) );
        ( *transStat )->bytesWritten = srcDataObjInfo->dataSize;
        ( *transStat )->numThreads = destDataObjInp->numThreads;
        dataObjCloseInp.bytesWritten = srcDataObjInfo->dataSize;
    }

    status2 = rsDataObjClose( rsComm, &dataObjCloseInp );

    if ( status ) {
        return status;
    }
    return status2;
}
Example #7
0
int
filePathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, 
rescInfo_t *rescInfo)
{
    dataObjInfo_t dataObjInfo;
    int status;
    char *rescGroupName = NULL;
    char *chksum;

    initDataObjInfoWithInp (&dataObjInfo, phyPathRegInp);
    if ((rescGroupName = getValByKey (&phyPathRegInp->condInput, 
      RESC_GROUP_NAME_KW)) != NULL) {
	rstrcpy (dataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
    }      
    dataObjInfo.replStatus = NEWLY_CREATED_COPY;
    dataObjInfo.rescInfo = rescInfo;
    rstrcpy (dataObjInfo.rescName, rescInfo->rescName, NAME_LEN);

    if (dataObjInfo.dataSize <= 0 && 
#ifdef FILESYSTEM_META
      (dataObjInfo.dataSize = getFileMetadataFromVault (rsComm, &dataObjInfo)) < 0 &&
#else
      (dataObjInfo.dataSize = getSizeInVault (rsComm, &dataObjInfo)) < 0 &&
#endif
      dataObjInfo.dataSize != UNKNOWN_FILE_SZ) {
	status = (int) dataObjInfo.dataSize;
        rodsLog (LOG_ERROR,
#ifdef FILESYSTEM_META
         "filePathReg: getFileMetadataFromVault for %s failed, status = %d",
#else
         "filePathReg: getSizeInVault for %s failed, status = %d",
#endif
          dataObjInfo.objPath, status);
	return (status);
    }
#ifdef FILESYSTEM_META
    addKeyVal(&dataObjInfo.condInput, FILE_SOURCE_PATH_KW, filePath);
#endif

    if ((chksum = getValByKey (&phyPathRegInp->condInput, 
      REG_CHKSUM_KW)) != NULL) {
        rstrcpy (dataObjInfo.chksum, chksum, NAME_LEN);
    }
    else if ((chksum = getValByKey (&phyPathRegInp->condInput, 
           VERIFY_CHKSUM_KW)) != NULL) {
        status = _dataObjChksum (rsComm, &dataObjInfo, &chksum);
        if (status < 0) {
            rodsLog (LOG_ERROR, 
             "rodsPathReg: _dataObjChksum for %s failed, status = %d",
             dataObjInfo.objPath, status);
            return (status);
        }
        rstrcpy (dataObjInfo.chksum, chksum, NAME_LEN);
    }

    status = svrRegDataObj (rsComm, &dataObjInfo);
    if (status < 0) {
        rodsLog (LOG_ERROR,
         "filePathReg: rsRegDataObj for %s failed, status = %d",
          dataObjInfo.objPath, status);
    } else {
        ruleExecInfo_t rei;
        initReiWithDataObjInp (&rei, rsComm, phyPathRegInp);
	rei.doi = &dataObjInfo;
	rei.status = status;
        rei.status = applyRule ("acPostProcForFilePathReg", NULL, &rei,
          NO_SAVE_REI);
    }

    return (status);
}
Example #8
0
    int
    rsNcCreate( rsComm_t *rsComm, ncOpenInp_t *ncCreateInp, int **ncid ) {
        int remoteFlag;
        rodsServerHost_t *rodsServerHost;
        specCollCache_t *specCollCache = NULL;
        int status;
        dataObjInp_t dataObjInp;
        int l1descInx, myncid;

        if ( getValByKey( &ncCreateInp->condInput, NATIVE_NETCDF_CALL_KW ) != NULL ) {
            /* just do nc_open with objPath as file nc file path */
            /* must to be called internally */
            if ( rsComm->proxyUser.authInfo.authFlag < REMOTE_PRIV_USER_AUTH ) {
                return( CAT_INSUFFICIENT_PRIVILEGE_LEVEL );
            }
            status = nc_create( ncCreateInp->objPath, ncCreateInp->mode, &myncid );
            if ( status == NC_NOERR ) {
                *ncid = ( int * ) malloc( sizeof( int ) );
                *( *ncid ) = myncid;
                return 0;
            }
            else {
                rodsLog( LOG_ERROR,
                         "rsNccreate: nc_create %s error, status = %d, %s",
                         ncCreateInp->objPath, status, nc_strerror( status ) );
                return ( NETCDF_OPEN_ERR + status );
            }
        }
        bzero( &dataObjInp, sizeof( dataObjInp ) );
        rstrcpy( dataObjInp.objPath, ncCreateInp->objPath, MAX_NAME_LEN );
        replKeyVal( &ncCreateInp->condInput, &dataObjInp.condInput );
        resolveLinkedPath( rsComm, dataObjInp.objPath, &specCollCache,
                           &dataObjInp.condInput );
        remoteFlag = getAndConnRemoteZone( rsComm, &dataObjInp, &rodsServerHost,
                                           REMOTE_OPEN );

        if ( remoteFlag < 0 ) {
            return ( remoteFlag );
        }
        else if ( remoteFlag == LOCAL_HOST ) {
            addKeyVal( &dataObjInp.condInput, NO_OPEN_FLAG_KW, "" );
            l1descInx = _rsDataObjCreate( rsComm, &dataObjInp );
            clearKeyVal( &dataObjInp.condInput );
            if ( l1descInx < 0 ) {
                return l1descInx;
            }
        
            l1desc_t& my_desc = irods::get_l1desc( l1descInx );
            remoteFlag = resoAndConnHostByDataObjInfo( rsComm,
                         my_desc.dataObjInfo, &rodsServerHost );
            if ( remoteFlag < 0 ) {
                return ( remoteFlag );
            }
            else if ( remoteFlag == LOCAL_HOST ) {
                status = nc_create( my_desc.dataObjInfo->filePath,
                                    ncCreateInp->mode, &myncid );
                if ( status != NC_NOERR ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: nc_open %s error, status = %d, %s",
                             ncCreateInp->objPath, status, nc_strerror( status ) );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
            else {
                /* execute it remotely with dataObjInfo->filePath */
                ncOpenInp_t myNcCreateInp;
                bzero( &myNcCreateInp, sizeof( myNcCreateInp ) );
                rstrcpy( myNcCreateInp.objPath,
                         my_desc.dataObjInfo->filePath, MAX_NAME_LEN );
                addKeyVal( &myNcCreateInp.condInput, NATIVE_NETCDF_CALL_KW, "" );
                status = rcNcCreate( rodsServerHost->conn, &myNcCreateInp, &myncid );
                clearKeyVal( &myNcCreateInp.condInput );
                if ( status < 0 ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: _rcNcCreate %s error, status = %d",
                             myNcCreateInp.objPath, status );
                    freeL1desc( l1descInx );
                    return ( status );
                }
            }
            my_desc.l3descInx = myncid;
            /* need to reg here since NO_OPEN_FLAG_KW does not do it */
            if ( my_desc.dataObjInfo->specColl == NULL ) {
                status = svrRegDataObj( rsComm, my_desc.dataObjInfo );
                if ( status < 0 ) {
                    ncCloseInp_t myNcCloseInp;
                    bzero( &myNcCloseInp, sizeof( myNcCloseInp ) );
                    myNcCloseInp.ncid = l1descInx;
                    irods::server_api_call ( NC_CLOSE_AN, rsComm, &myNcCloseInp );
                    l3Unlink( rsComm, my_desc.dataObjInfo );
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: svrRegDataObj for %s failed, status = %d",
                             my_desc.dataObjInfo->objPath, status );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
        }
        else {
            addKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW, "" );
            status = rcNcCreate( rodsServerHost->conn, ncCreateInp, &myncid );
            /* rm it to avoid confusion */
            rmKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsNcCreate: _rcNcCreate %s error, status = %d",
                         ncCreateInp->objPath, status );
                return ( status );
            }
            l1descInx = allocAndSetL1descForZoneOpr( myncid, &dataObjInp,
                        rodsServerHost, NULL );
        }
        
        l1desc_t& my_desc = irods::get_l1desc( l1descInx );
        my_desc.oprType = NC_CREATE;
        *ncid = ( int * ) malloc( sizeof( int ) );
        *( *ncid ) = l1descInx;

        return 0;
    }
Example #9
0
int
dataObjUnlinkS (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
dataObjInfo_t *dataObjInfo)
{
    int status;
    unregDataObj_t unregDataObjInp;

    if (dataObjInfo->specColl == NULL) {
	if (dataObjUnlinkInp->oprType == UNREG_OPR && 
	  rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
	    ruleExecInfo_t rei;

            initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
            rei.doi = dataObjInfo;
            rei.status = DO_CHK_PATH_PERM;         /* default */
            applyRule ("acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI);
            if (rei.status != NO_CHK_PATH_PERM) {
                char *outVaultPath;
                rodsServerHost_t *rodsServerHost;
	        status = resolveHostByRescInfo (dataObjInfo->rescInfo, 
	          &rodsServerHost);
	        if (status < 0) return status;
	        /* unregistering but not an admin user */
	        status = matchVaultPath (rsComm, dataObjInfo->filePath, 
	          rodsServerHost, &outVaultPath);
	        if (status != 0) {
		    /* in the vault */
                    rodsLog (LOG_DEBUG,
                      "dataObjUnlinkS: unregistering in vault file %s",
                      dataObjInfo->filePath);
                    return CANT_UNREG_IN_VAULT_FILE;
		}
	    }
#if 0	/* don't need this since we are doing orphan */
	} else if (RescTypeDef[dataObjInfo->rescInfo->rescTypeInx].driverType 
	  == WOS_FILE_TYPE && dataObjUnlinkInp->oprType != UNREG_OPR) {
	    /* WOS_FILE_TYPE, unlink first before unreg because orphan files
	     * cannot be reclaimed */
            status = l3Unlink (rsComm, dataObjInfo);
            if (status < 0) {
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: l3Unlink error for WOS file %s. status = %d",
                  dataObjUnlinkInp->objPath, status);
		return status;
	    }
            unregDataObjInp.dataObjInfo = dataObjInfo;
            unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
            status = rsUnregDataObj (rsComm, &unregDataObjInp);
            if (status < 0) {
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
                  dataObjUnlinkInp->objPath, status);
            }
            return status;
#endif
	}
        unregDataObjInp.dataObjInfo = dataObjInfo;
        unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
        status = rsUnregDataObj (rsComm, &unregDataObjInp);

        if (status < 0) {
            rodsLog (LOG_NOTICE,
              "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
              dataObjUnlinkInp->objPath, status);
	    return status;
        }
    }
    
    if (dataObjUnlinkInp->oprType != UNREG_OPR) {
        status = l3Unlink (rsComm, dataObjInfo);
        if (status < 0) {
	    int myError = getErrno (status);
            rodsLog (LOG_NOTICE,
              "dataObjUnlinkS: l3Unlink error for %s. status = %d",
              dataObjUnlinkInp->objPath, status);
	    /* allow ENOENT to go on and unregister */
	    if (myError != ENOENT && myError != EACCES) {
		char orphanPath[MAX_NAME_LEN];
		int status1 = 0;
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath);
		while (1) { 
		    if (isOrphanPath (dataObjUnlinkInp->objPath) == 
		      NOT_ORPHAN_PATH) {
			/* don't rename orphan path */
		        status1 = rsMkOrphanPath (rsComm, dataObjInfo->objPath,
		          orphanPath);
		        if (status1 < 0) break;
		        /* reg the orphan path */
		        rstrcpy (dataObjInfo->objPath, orphanPath,MAX_NAME_LEN);
		    }
		    status1 = svrRegDataObj (rsComm, dataObjInfo);
		    if (status1 == CAT_NAME_EXISTS_AS_DATAOBJ ||
		      status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
			continue;
		    } else if (status1 < 0) {
			rodsLogError (LOG_ERROR, status1,
			  "dataObjUnlinkS: svrRegDataObj of orphan %s error",
			  dataObjInfo->objPath);
		    }
		    break;
		}
	        return (status);
	    } else {
	        status = 0;
	    }
	}
    }

    return (status);
}
int 
chkCollForExtAndReg (rsComm_t *rsComm, char *collection, 
rodsObjStat_t **rodsObjStatOut)
{
    dataObjInp_t dataObjInp;
    int status;
    rodsObjStat_t *myRodsObjStat = NULL;

    bzero (&dataObjInp, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, collection, MAX_NAME_LEN);
#if 0	/* allow mounted coll */
    status = collStat (rsComm, &dataObjInp, &myRodsObjStat);
#endif
    status = collStatAllKinds (rsComm, &dataObjInp, &myRodsObjStat);
#if 0
    if (status == CAT_NO_ROWS_FOUND || status == OBJ_PATH_DOES_NOT_EXIST ||
      status == USER_FILE_DOES_NOT_EXIST) {
#endif
    if (status < 0) { 
	status = rsMkCollR (rsComm, "/", collection);
	if (status < 0) {
            rodsLog (LOG_ERROR,
              "chkCollForExtAndReg: rsMkCollR of %s error. status = %d",
              collection, status);
            return (status);
	} else {
#if 0	/* allow mounted coll */
	    status = collStat (rsComm, &dataObjInp, &myRodsObjStat);
#endif
	    status = collStatAllKinds (rsComm, &dataObjInp, &myRodsObjStat);
	}
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: collStat of %s error. status = %d",
          dataObjInp.objPath, status);
        return (status);
    } else if (myRodsObjStat->specColl != NULL && 
      myRodsObjStat->specColl->collClass != MOUNTED_COLL) {
	/* only do mounted coll */
        freeRodsObjStat (myRodsObjStat);
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: %s is a struct file collection",
          dataObjInp.objPath);
        return (SYS_STRUCT_FILE_INMOUNTED_COLL);
    }

    if (myRodsObjStat->specColl == NULL) {
        status = checkCollAccessPerm (rsComm, collection, ACCESS_DELETE_OBJECT);
    } else {
	status = checkCollAccessPerm (rsComm, 
	  myRodsObjStat->specColl->collection, ACCESS_DELETE_OBJECT);
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "chkCollForExtAndReg: no permission to write %s, status = %d",
          collection, status);
        freeRodsObjStat (myRodsObjStat);
    } else {
	if (rodsObjStatOut != NULL) {
	    *rodsObjStatOut = myRodsObjStat;
	} else {
            freeRodsObjStat (myRodsObjStat);
	}
    }
    return (status);
}

/* regUnbunSubfiles - non bulk version of registering all files in phyBunDir 
 * to the collection. Valid values for flags are: 
 *	FORCE_FLAG_FLAG.
 */

int
regUnbunSubfiles (rsComm_t *rsComm, rescInfo_t *rescInfo, char *rescGroupName,
char *collection, char *phyBunDir, int flags, genQueryOut_t *attriArray)
{
#ifndef USE_BOOST_FS
    DIR *dirPtr;
    struct dirent *myDirent;
    struct stat statbuf;
#endif
    char subfilePath[MAX_NAME_LEN];
    char subObjPath[MAX_NAME_LEN];
    dataObjInp_t dataObjInp;
    int status;
    int savedStatus = 0;
    rodsLong_t st_size;

#ifdef USE_BOOST_FS
    path srcDirPath (phyBunDir);
    if (!exists(srcDirPath) || !is_directory(srcDirPath)) {
#else
    dirPtr = opendir (phyBunDir);
    if (dirPtr == NULL) {
#endif
        rodsLog (LOG_ERROR,
        "regUnbunphySubfiles: opendir error for %s, errno = %d",
         phyBunDir, errno);
        return (UNIX_FILE_OPENDIR_ERR - errno);
    }
    bzero (&dataObjInp, sizeof (dataObjInp));
#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 (subfilePath, 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 (subfilePath, MAX_NAME_LEN, "%s/%s",
          phyBunDir, myDirent->d_name);
#endif

#ifdef USE_BOOST_FS
        if (!exists (p)) {
#else
        status = lstat (subfilePath, &statbuf);

        if (status != 0) {
#endif
            rodsLog (LOG_ERROR,
              "regUnbunphySubfiles: stat error for %s, errno = %d",
              subfilePath, errno);
            savedStatus = UNIX_FILE_STAT_ERR - errno;
	    unlink (subfilePath);
	    continue;
        }

#ifdef USE_BOOST_FS
	if (is_symlink (p)) {
#else
	if ((statbuf.st_mode & S_IFLNK) == S_IFLNK) {
#endif
            rodsLogError (LOG_ERROR, SYMLINKED_BUNFILE_NOT_ALLOWED,
              "regUnbunSubfiles: %s is a symlink",
              subfilePath);
            savedStatus = SYMLINKED_BUNFILE_NOT_ALLOWED;
            continue;
        }
#ifdef USE_BOOST_FS
        path childPath = p.filename();
        snprintf (subObjPath, MAX_NAME_LEN, "%s/%s",
          collection, childPath.c_str());

	if (is_directory (p)) {
#else
        snprintf (subObjPath, MAX_NAME_LEN, "%s/%s",
          collection, myDirent->d_name);

        if ((statbuf.st_mode & S_IFDIR) != 0) {
#endif
            status = rsMkCollR (rsComm, "/", subObjPath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: rsMkCollR of %s error. status = %d",
                  subObjPath, status);
                savedStatus = status;
		continue;
	    }
	    status = regUnbunSubfiles (rsComm, rescInfo, rescGroupName,
	      subObjPath, subfilePath, flags, attriArray);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: regUnbunSubfiles of %s error. status=%d",
                  subObjPath, status);
                savedStatus = status;
                continue;
            }
#ifdef USE_BOOST_FS
        } else if (is_regular_file (p)) {
	    st_size = file_size (p);
#else
        } else if ((statbuf.st_mode & S_IFREG) != 0) {
	    st_size = statbuf.st_size;
#endif
	    status = regSubfile (rsComm, rescInfo, rescGroupName,
		subObjPath, subfilePath, st_size, flags);
	    unlink (subfilePath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regUnbunSubfiles: regSubfile of %s error. status=%d",
                  subObjPath, status);
                savedStatus = status;
                continue;
	    }
	}
    }
#ifndef USE_BOOST_FS
    closedir (dirPtr);
#endif
    rmdir (phyBunDir);
    return savedStatus;
}

int
regSubfile (rsComm_t *rsComm, rescInfo_t *rescInfo, char *rescGroupName,
char *subObjPath, char *subfilePath, rodsLong_t dataSize, int flags)
{
    dataObjInfo_t dataObjInfo;
    dataObjInp_t dataObjInp;
#ifndef USE_BOOST_FS
    struct stat statbuf;
#endif
    int status;
    int modFlag = 0;

    bzero (&dataObjInp, sizeof (dataObjInp));
    bzero (&dataObjInfo, sizeof (dataObjInfo));
    rstrcpy (dataObjInp.objPath, subObjPath, MAX_NAME_LEN);
    rstrcpy (dataObjInfo.objPath, subObjPath, MAX_NAME_LEN);
    rstrcpy (dataObjInfo.rescName, rescInfo->rescName, NAME_LEN);
    rstrcpy (dataObjInfo.dataType, "generic", NAME_LEN);
    dataObjInfo.rescInfo = rescInfo;
    rstrcpy (dataObjInfo.rescGroupName, rescGroupName, NAME_LEN);
    dataObjInfo.dataSize = dataSize;

    status = getFilePathName (rsComm, &dataObjInfo, &dataObjInp);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: getFilePathName err for %s. status = %d",
          dataObjInp.objPath, status);
        return (status);
    }

#ifdef USE_BOOST_FS
    path p (dataObjInfo.filePath);
    if (exists (p)) {
	if (is_directory (p)) {
#else
    status = stat (dataObjInfo.filePath, &statbuf);
    if (status == 0 || errno != ENOENT) {
        if ((statbuf.st_mode & S_IFDIR) != 0) {
#endif
	    return SYS_PATH_IS_NOT_A_FILE;
	}

        if (chkOrphanFile (rsComm, dataObjInfo.filePath, rescInfo->rescName, 
	  &dataObjInfo) > 0) {
	    /* an orphan file. just rename it */
	    fileRenameInp_t fileRenameInp;
	    bzero (&fileRenameInp, sizeof (fileRenameInp));
            rstrcpy (fileRenameInp.oldFileName, dataObjInfo.filePath, 
	      MAX_NAME_LEN);
            status = renameFilePathToNewDir (rsComm, ORPHAN_DIR, 
	      &fileRenameInp, rescInfo, 1);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "regSubFile: renameFilePathToNewDir err for %s. status = %d",
                  fileRenameInp.oldFileName, status);
                return (status);
	    }
	} else {
	    /* not an orphan file */
	    if ((flags & FORCE_FLAG_FLAG) != 0 && dataObjInfo.dataId > 0 && 
	      strcmp (dataObjInfo.objPath, subObjPath) == 0) {
		/* overwrite the current file */
		modFlag = 1;
		unlink (dataObjInfo.filePath);
	    } else {
		status = SYS_COPY_ALREADY_IN_RESC;
                rodsLog (LOG_ERROR,
                  "regSubFile: phypath %s is already in use. status = %d",
                  dataObjInfo.filePath, status);
                return (status);
	    }
        }
    }
    /* make the necessary dir */
    mkDirForFilePath (UNIX_FILE_TYPE, rsComm, "/", dataObjInfo.filePath,
      getDefDirMode ());
    /* add a link */

#ifndef windows_platform   /* Windows does not support link */
    status = link (subfilePath, dataObjInfo.filePath);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: link error %s to %s. errno = %d",
          subfilePath, dataObjInfo.filePath, errno);
        return (UNIX_FILE_LINK_ERR - errno);
    }
#endif

    if (modFlag == 0) {
        status = svrRegDataObj (rsComm, &dataObjInfo);
    } else {
        char tmpStr[MAX_NAME_LEN];
        modDataObjMeta_t modDataObjMetaInp;
	keyValPair_t regParam;

	bzero (&modDataObjMetaInp, sizeof (modDataObjMetaInp));
	bzero (&regParam, sizeof (regParam));
        snprintf (tmpStr, MAX_NAME_LEN, "%lld", dataSize);
        addKeyVal (&regParam, DATA_SIZE_KW, tmpStr);
        addKeyVal (&regParam, ALL_REPL_STATUS_KW, tmpStr);
        snprintf (tmpStr, MAX_NAME_LEN, "%d", (int) time (NULL));
        addKeyVal (&regParam, DATA_MODIFY_KW, tmpStr);

        modDataObjMetaInp.dataObjInfo = &dataObjInfo;
        modDataObjMetaInp.regParam = &regParam;

        status = rsModDataObjMeta (rsComm, &modDataObjMetaInp);

        clearKeyVal (&regParam);
    }

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "regSubFile: svrRegDataObj of %s. errno = %d",
          dataObjInfo.objPath, errno);
	unlink (dataObjInfo.filePath);
    } else {
	ruleExecInfo_t rei;
	dataObjInp_t dataObjInp;
	bzero (&dataObjInp, sizeof (dataObjInp));
	rstrcpy (dataObjInp.objPath, dataObjInfo.objPath, MAX_NAME_LEN);
	initReiWithDataObjInp (&rei, rsComm, &dataObjInp);
	rei.doi = &dataObjInfo;
	rei.status = applyRule ("acPostProcForTarFileReg", NULL, &rei,
                    NO_SAVE_REI);
	if (rei.status < 0) {
            rodsLogError (LOG_ERROR, rei.status,
              "regSubFile: acPostProcForTarFileReg error for %s. status = %d",
              dataObjInfo.objPath);
	}
    }
    return status;
}
Example #11
0
int
dataObjUnlinkS( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
                dataObjInfo_t *dataObjInfo ) {
    int status = 0;
    unregDataObj_t unregDataObjInp;

    if ( dataObjInfo->specColl == NULL ) {
        if ( dataObjUnlinkInp->oprType            == UNREG_OPR &&
                rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) {
            ruleExecInfo_t rei;

            initReiWithDataObjInp( &rei, rsComm, dataObjUnlinkInp );
            rei.doi = dataObjInfo;
            rei.status = DO_CHK_PATH_PERM;         /* default */ // JMC - backport 4758

            // make resource properties available as rule session variables
            rei.condInputData = (keyValPair_t *)malloc(sizeof(keyValPair_t));
            memset(rei.condInputData, 0, sizeof(keyValPair_t));
            irods::get_resc_properties_as_kvp(rei.doi->rescHier, rei.condInputData);

            applyRule( "acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI );
            if ( rei.status != NO_CHK_PATH_PERM ) {
                // =-=-=-=-=-=-=-
                // extract the host location from the resource hierarchy
                std::string location;
                irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
                if ( !ret.ok() ) {
                    irods::log( PASSMSG( "dataObjUnlinkS - failed in get_loc_for_hier_string", ret ) );
                    return ret.code();
                }

                rodsHostAddr_t addr;
                rodsServerHost_t *rodsServerHost = 0;

                memset( &addr, 0, sizeof( addr ) );
                rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN );
                int remoteFlag = resolveHost( &addr, &rodsServerHost );
                if ( remoteFlag < 0 ) {
                    // error condition?
                }

                /* unregistering but not an admin user */
                std::string out_path;
                ret = resc_mgr.validate_vault_path( dataObjInfo->filePath, rodsServerHost, out_path );
                if ( !ret.ok() ) {
                    /* in the vault */
                    std::stringstream msg;
                    msg << "unregistering a data object which is in a vault [";
                    msg << dataObjInfo->filePath << "]";
                    irods::log( PASSMSG( msg.str(), ret ) );
                    return CANT_UNREG_IN_VAULT_FILE;
                }
            }
        }

        unregDataObjInp.dataObjInfo = dataObjInfo;
        unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
        status = rsUnregDataObj( rsComm, &unregDataObjInp );

        if ( status < 0 ) {
            rodsLog( LOG_NOTICE,
                     "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
                     dataObjUnlinkInp->objPath, status );
            return status;
        }
    }

    if ( dataObjUnlinkInp->oprType != UNREG_OPR ) {

        // Set the in_pdmo flag
        char* in_pdmo = getValByKey( &dataObjUnlinkInp->condInput, IN_PDMO_KW );
        if ( in_pdmo != NULL ) {
            rstrcpy( dataObjInfo->in_pdmo, in_pdmo, MAX_NAME_LEN );
        }
        else {
            dataObjInfo->in_pdmo[0] = '\0';
        }

        status = l3Unlink( rsComm, dataObjInfo );
        if ( status < 0 ) {
            int myError = getErrno( status );
            rodsLog( LOG_NOTICE,
                     "dataObjUnlinkS: l3Unlink error for %s. status = %d",
                     dataObjUnlinkInp->objPath, status );
            /* allow ENOENT to go on and unregister */
            if ( myError != ENOENT && myError != EACCES ) {
                char orphanPath[MAX_NAME_LEN];
                int status1 = 0;
                rodsLog( LOG_NOTICE,
                         "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath );
                while ( 1 ) {
                    if ( isOrphanPath( dataObjUnlinkInp->objPath ) ==
                            NOT_ORPHAN_PATH ) {
                        /* don't rename orphan path */
                        status1 = rsMkOrphanPath( rsComm, dataObjInfo->objPath,
                                                  orphanPath );
                        if ( status1 < 0 ) {
                            break;
                        }
                        /* reg the orphan path */
                        rstrcpy( dataObjInfo->objPath, orphanPath, MAX_NAME_LEN );
                    }
                    status1 = svrRegDataObj( rsComm, dataObjInfo );
                    if ( status1 == CAT_NAME_EXISTS_AS_DATAOBJ ||
                            status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                        continue;
                    }
                    else if ( status1 < 0 ) {
                        rodsLogError( LOG_ERROR, status1,
                                      "dataObjUnlinkS: svrRegDataObj of orphan %s error",
                                      dataObjInfo->objPath );
                    }
                    break;
                }
                return status;
            }
            else {
                status = 0;
            }
        }
    }

    return status;
}