Example #1
0
int
getRescForGetInDataObj( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
                        hostSearchStat_t *hostSearchStat ) {
    int status, i;
    dataObjInfo_t *dataObjInfoHead = NULL;

    if ( dataObjInp == NULL || hostSearchStat == NULL ) {
        return USER__NULL_INPUT_ERR;
    }

    status = getDataObjInfoIncSpecColl( rsComm, dataObjInp, &dataObjInfoHead );
    if ( status < 0 ) {
        return status;
    }

    sortObjInfoForOpen( &dataObjInfoHead, &dataObjInp->condInput, 0 );
    if ( dataObjInfoHead ) {
        if ( hostSearchStat->numHost >= MAX_HOST_TO_SEARCH ||
                hostSearchStat->totalCount >= MAX_HOST_TO_SEARCH ) {
            freeAllDataObjInfo( dataObjInfoHead );
            return 0;
        }
        for ( i = 0; i < hostSearchStat->numHost; i++ ) {
            if ( dataObjInfoHead->rescInfo == hostSearchStat->rescInfo[i] ) {
                hostSearchStat->count[i]++;
                hostSearchStat->totalCount++;
                freeAllDataObjInfo( dataObjInfoHead );
                return 0;
            }
        }
        /* no match. add one */
        hostSearchStat->rescInfo[hostSearchStat->numHost] =
            dataObjInfoHead->rescInfo;
        hostSearchStat->count[hostSearchStat->numHost] = 1;
        hostSearchStat->numHost++;
        hostSearchStat->totalCount++;
    }
    freeAllDataObjInfo( dataObjInfoHead );
    return 0;
}
int
_rsModDataObjMeta( rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp ) {
#ifdef RODS_CAT
    int status = 0;
    dataObjInfo_t *dataObjInfo;
    keyValPair_t *regParam;
    int i;
    ruleExecInfo_t rei2;

    memset( ( char* )&rei2, 0, sizeof( ruleExecInfo_t ) );
    rei2.rsComm = rsComm;
    if ( rsComm != NULL ) {
        rei2.uoic = &rsComm->clientUser;
        rei2.uoip = &rsComm->proxyUser;
    }
    rei2.doi = modDataObjMetaInp->dataObjInfo;
    rei2.condInputData = modDataObjMetaInp->regParam;
    regParam = modDataObjMetaInp->regParam;
    dataObjInfo = modDataObjMetaInp->dataObjInfo;

    if ( regParam->len == 0 ) {
        return ( 0 );
    }

    /* In dataObjInfo, need just dataId. But it will accept objPath too,
     * but less efficient
     */

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    rei2.doi = dataObjInfo;
    i =  applyRule( "acPreProcForModifyDataObjMeta", NULL, &rei2, NO_SAVE_REI );
    if ( i < 0 ) {
        if ( rei2.status < 0 ) {
            i = rei2.status;
        }
        rodsLog( LOG_ERROR, "_rsModDataObjMeta:acPreProcForModifyDataObjMeta error stat=%d", i );

        return i;
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    if ( getValByKey( regParam, ALL_KW ) != NULL ) {
        /* all copies */
        dataObjInfo_t *dataObjInfoHead = NULL;
        dataObjInfo_t *tmpDataObjInfo;
        dataObjInp_t dataObjInp;

        bzero( &dataObjInp, sizeof( dataObjInp ) );
        rstrcpy( dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN );
        status = getDataObjInfoIncSpecColl( rsComm, &dataObjInp, &dataObjInfoHead );

        if ( status < 0 )  {
            rodsLog( LOG_NOTICE, "%s - Failed to get data objects.", __FUNCTION__ );
            return status;
        }
        tmpDataObjInfo = dataObjInfoHead;
        while ( tmpDataObjInfo != NULL ) {
            if ( tmpDataObjInfo->specColl != NULL ) {
                break;
            }
            status = chlModDataObjMeta( rsComm, tmpDataObjInfo, regParam );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "_rsModDataObjMeta:chlModDataObjMeta %s error stat=%d",
                         tmpDataObjInfo->objPath, status );
            }
            tmpDataObjInfo = tmpDataObjInfo->next;
        }
        freeAllDataObjInfo( dataObjInfoHead );
    }
    else {
        status = chlModDataObjMeta( rsComm, dataObjInfo, regParam );
        if ( status < 0 ) {
            char* sys_error;
            char* rods_error = rodsErrorName( status, &sys_error );
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - Failed to modify the database for object \"";
            msg << dataObjInfo->objPath;
            msg << "\" - " << rods_error << " " << sys_error;
            irods::error ret = ERROR( status, msg.str() );
            irods::log( ret );
        }
    }

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    if ( status >= 0 ) {
        i =  applyRule( "acPostProcForModifyDataObjMeta", NULL, &rei2, NO_SAVE_REI );
        if ( i < 0 ) {
            if ( rei2.status < 0 ) {
                i = rei2.status;
            }
            rodsLog( LOG_ERROR,
                     "_rsModDataObjMeta:acPostProcForModifyDataObjMeta error stat=%d", i );
            return i;
        }
    }
    else {
        rodsLog( LOG_NOTICE, "%s - Failed updating the database with object info.", __FUNCTION__ );
        return status;
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    return ( status );
#else
    return ( SYS_NO_RCAT_SERVER_ERR );
#endif

}
int _call_file_modified_for_modification(
    rsComm_t*         rsComm,
    modDataObjMeta_t* modDataObjMetaInp ) {
    int status = 0;
    dataObjInfo_t *dataObjInfo;
    keyValPair_t *regParam;
    ruleExecInfo_t rei2;

    memset( ( char* )&rei2, 0, sizeof( ruleExecInfo_t ) );
    rei2.rsComm = rsComm;
    if ( rsComm != NULL ) {
        rei2.uoic = &rsComm->clientUser;
        rei2.uoip = &rsComm->proxyUser;
    }
    rei2.doi = modDataObjMetaInp->dataObjInfo;
    rei2.condInputData = modDataObjMetaInp->regParam;
    regParam = modDataObjMetaInp->regParam;
    dataObjInfo = modDataObjMetaInp->dataObjInfo;

    if ( regParam->len == 0 ) {
        return ( 0 );
    }

    if ( getValByKey( regParam, ALL_KW ) != NULL ) {
        /* all copies */
        dataObjInfo_t *dataObjInfoHead = NULL;
        dataObjInfo_t *tmpDataObjInfo;
        dataObjInp_t dataObjInp;

        bzero( &dataObjInp, sizeof( dataObjInp ) );
        rstrcpy( dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN );
        status = getDataObjInfoIncSpecColl( rsComm, &dataObjInp, &dataObjInfoHead );

        if ( status < 0 )  {
            rodsLog( LOG_NOTICE, "%s - Failed to get data objects.", __FUNCTION__ );
            return status;
        }
        tmpDataObjInfo = dataObjInfoHead;
        while ( tmpDataObjInfo != NULL ) {
            if ( tmpDataObjInfo->specColl != NULL ) {
                break;
            }

            irods::file_object_ptr file_obj(
                new irods::file_object(
                    rsComm,
                    tmpDataObjInfo ) );

            char* pdmo_kw = getValByKey( regParam, 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 << __FUNCTION__;
                msg << " - Failed to signal resource that the data object \"";
                msg << tmpDataObjInfo->objPath;
                msg << " was modified.";
                ret = PASSMSG( msg.str(), ret );
                irods::log( ret );
                status = ret.code();
            }

            tmpDataObjInfo = tmpDataObjInfo->next;
        }
        freeAllDataObjInfo( dataObjInfoHead );
    }
    else {
        irods::file_object_ptr file_obj(
            new irods::file_object(
                rsComm,
                dataObjInfo ) );

        char* pdmo_kw = getValByKey( regParam, 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 << __FUNCTION__;
            msg << " - Failed to signal the resource that the data object \"";
            msg << dataObjInfo->objPath;
            msg << "\" was modified.";
            ret = PASSMSG( msg.str(), ret );
            irods::log( ret );
            status = ret.code();
        }

    }

    return status;

}
int
_rsModDataObjMeta (rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
{
#ifdef RODS_CAT
    int status;
    dataObjInfo_t *dataObjInfo;
    keyValPair_t *regParam;
    int i;
    ruleExecInfo_t rei2;

    memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
    rei2.rsComm = rsComm;
    if (rsComm != NULL) {
      rei2.uoic = &rsComm->clientUser;
      rei2.uoip = &rsComm->proxyUser;
    }
    rei2.doi = modDataObjMetaInp->dataObjInfo;
    rei2.condInputData = modDataObjMetaInp->regParam;
    regParam = modDataObjMetaInp->regParam;
    dataObjInfo = modDataObjMetaInp->dataObjInfo;

    if (regParam->len == 0) {
        rodsLog(LOG_NOTICE, "Warning, _rsModDataObjMeta called with empty regParam, returning success");
        return (0);
    }

    /* In dataObjInfo, need just dataId. But it will accept objPath too,
     * but less efficient 
     */

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    rei2.doi = dataObjInfo;
    i =  applyRule("acPreProcForModifyDataObjMeta",NULL, &rei2, NO_SAVE_REI);
    if (i < 0) {
      if (rei2.status < 0) {
        i = rei2.status;
      }
      rodsLog (LOG_ERROR,
               "_rsModDataObjMeta:acPreProcForModifyDataObjMeta error stat=%d", i);
      return i;
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    if (getValByKey (regParam, ALL_KW) != NULL) {
	/* all copies */
	dataObjInfo_t *dataObjInfoHead = NULL;
	dataObjInfo_t *tmpDataObjInfo;
	dataObjInp_t dataObjInp;

	bzero (&dataObjInp, sizeof (dataObjInp));
	rstrcpy (dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
        status = getDataObjInfoIncSpecColl (rsComm, &dataObjInp,
          &dataObjInfoHead);
	if (status < 0) return status;
	tmpDataObjInfo = dataObjInfoHead;
        while (tmpDataObjInfo != NULL) {
	    if (tmpDataObjInfo->specColl != NULL) break;
            status = chlModDataObjMeta (rsComm, tmpDataObjInfo, regParam);
	    if (status < 0) {
                rodsLog (LOG_ERROR,
                  "_rsModDataObjMeta:chlModDataObjMeta %s error stat=%d",
	          tmpDataObjInfo->objPath, status);
	    }
	    tmpDataObjInfo = tmpDataObjInfo->next;
	}
	freeAllDataObjInfo (dataObjInfoHead);
    } else {
        status = chlModDataObjMeta (rsComm, dataObjInfo, regParam);
    }

    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/
    if (status >= 0) {
      i =  applyRule("acPostProcForModifyDataObjMeta",NULL, &rei2, NO_SAVE_REI);
      if (i < 0) {
        if (rei2.status < 0) {
          i = rei2.status;
        }
        rodsLog (LOG_ERROR,
           "_rsModDataObjMeta:acPostProcForModifyDataObjMeta error stat=%d",i);
        return i;
      }
    }
    /** RAJA ADDED June 1 2009 for pre-post processing rule hooks **/

    return (status);
#else
    return (SYS_NO_RCAT_SERVER_ERR);
#endif

}
Example #5
0
int
structFileReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
{
    collInp_t collCreateInp;
    int status;
    dataObjInfo_t *dataObjInfo = NULL;
    char *structFilePath = NULL;
    dataObjInp_t dataObjInp;
    char *collType;
    int len;
    rodsObjStat_t *rodsObjStatOut = NULL;
    specCollCache_t *specCollCache = NULL;
    rescInfo_t *rescInfo = NULL;

#if 0	/* fixed */
    /* make it a privileged call for now */
    if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH)
      return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
#endif

    if ((structFilePath = getValByKey (&phyPathRegInp->condInput, FILE_PATH_KW))
      == NULL) {
        rodsLog (LOG_ERROR,
          "structFileReg: No structFilePath input for %s",
          phyPathRegInp->objPath);
        return (SYS_INVALID_FILE_PATH);
    }

    collType = getValByKey (&phyPathRegInp->condInput, COLLECTION_TYPE_KW);
    if (collType == NULL) {
        rodsLog (LOG_ERROR,
          "structFileReg: Bad COLLECTION_TYPE_KW for structFilePath %s",
              dataObjInp.objPath);
            return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    len = strlen (phyPathRegInp->objPath);
    if (strncmp (structFilePath, phyPathRegInp->objPath, len) == 0 &&
     (structFilePath[len] == '\0' || structFilePath[len] == '/')) {
        rodsLog (LOG_ERROR,
          "structFileReg: structFilePath %s inside collection %s",
          structFilePath, phyPathRegInp->objPath);
        return (SYS_STRUCT_FILE_INMOUNTED_COLL);
    }

    /* see if the struct file is in spec coll */

    if (getSpecCollCache (rsComm, structFilePath, 0,  &specCollCache) >= 0) {
        rodsLog (LOG_ERROR,
          "structFileReg: structFilePath %s is in a mounted path",
          structFilePath);
        return (SYS_STRUCT_FILE_INMOUNTED_COLL);
    }

    status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut);
    if (status < 0) return status;
 
    if (rodsObjStatOut->specColl != NULL) {
	freeRodsObjStat (rodsObjStatOut);
        rodsLog (LOG_ERROR,
          "structFileReg: %s already mounted", phyPathRegInp->objPath);
	return (SYS_MOUNT_MOUNTED_COLL_ERR);
    }

    freeRodsObjStat (rodsObjStatOut);

    if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) {
        rodsLog (LOG_ERROR,
          "structFileReg: collection %s not empty", phyPathRegInp->objPath);
        return (SYS_COLLECTION_NOT_EMPTY);
    }

    memset (&dataObjInp, 0, sizeof (dataObjInp));
    rstrcpy (dataObjInp.objPath, structFilePath, sizeof (dataObjInp));
    /* user need to have write permission */
    dataObjInp.openFlags = O_WRONLY;
    status = getDataObjInfoIncSpecColl (rsComm, &dataObjInp, &dataObjInfo);
    if (status < 0) {
	int myStatus;
	/* try to make one */
	dataObjInp.condInput = phyPathRegInp->condInput;
	/* have to remove FILE_PATH_KW because getFullPathName will use it */
	rmKeyVal (&dataObjInp.condInput, FILE_PATH_KW);
	myStatus = rsDataObjCreate (rsComm, &dataObjInp);
	if (myStatus < 0) {
            rodsLog (LOG_ERROR,
              "structFileReg: Problem with open/create structFilePath %s, status = %d",
              dataObjInp.objPath, status);
            return (status);
	} else {
	    openedDataObjInp_t dataObjCloseInp;
	    bzero (&dataObjCloseInp, sizeof (dataObjCloseInp));
	    rescInfo = L1desc[myStatus].dataObjInfo->rescInfo;
	    dataObjCloseInp.l1descInx = myStatus;
	    rsDataObjClose (rsComm, &dataObjCloseInp);
	}
    } else {
	rescInfo = dataObjInfo->rescInfo;
    }

    if (!structFileSupport (rsComm, phyPathRegInp->objPath, 
      collType, rescInfo)) {
        rodsLog (LOG_ERROR,
          "structFileReg: structFileDriver type %s does not exist for %s",
          collType, dataObjInp.objPath);
        return (SYS_NOT_SUPPORTED);
    }

    /* mk the collection */

    memset (&collCreateInp, 0, sizeof (collCreateInp));
    rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN);
    addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, collType);

    /* have to use dataObjInp.objPath because structFile path was removed */ 
    addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, 
     dataObjInp.objPath);

    /* try to mod the coll first */
    status = rsModColl (rsComm, &collCreateInp);

    if (status < 0) {	/* try to create it */
       status = rsRegColl (rsComm, &collCreateInp);
    }

    return (status);
}
Example #6
0
int
rsDataObjUnlink (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp)
{
    int status;
    ruleExecInfo_t rei;
    int trashPolicy;
    dataObjInfo_t *dataObjInfoHead = NULL;
    rodsServerHost_t *rodsServerHost = NULL;
    int rmTrashFlag = 0;
    specCollCache_t *specCollCache = NULL;

    resolveLinkedPath (rsComm, dataObjUnlinkInp->objPath, &specCollCache,
      &dataObjUnlinkInp->condInput);
    status = getAndConnRcatHost (rsComm, MASTER_RCAT,
     dataObjUnlinkInp->objPath, &rodsServerHost);

    if (status < 0) {
        return (status);
    } else if (rodsServerHost->rcatEnabled == REMOTE_ICAT) {
        int retval;
        retval = rcDataObjUnlink (rodsServerHost->conn, dataObjUnlinkInp);
        return status;
    }

    if (getValByKey (
      &dataObjUnlinkInp->condInput, IRODS_ADMIN_RMTRASH_KW) != NULL ||
      getValByKey (
      &dataObjUnlinkInp->condInput, IRODS_RMTRASH_KW) != NULL) {
        if (isTrashPath (dataObjUnlinkInp->objPath) == False) {
            return (SYS_INVALID_FILE_PATH);
        }
	rmTrashFlag = 1;
    }

    dataObjUnlinkInp->openFlags = O_WRONLY;  /* set the permission checking */
    status = getDataObjInfoIncSpecColl (rsComm, dataObjUnlinkInp, 
      &dataObjInfoHead);

    if (status < 0) return (status);

    if (rmTrashFlag == 1) {
        char *tmpAge;
        int ageLimit;
        if ((tmpAge = getValByKey (&dataObjUnlinkInp->condInput, AGE_KW))
          != NULL) {
	    ageLimit = atoi (tmpAge) * 60;
	    if ((time (0) - atoi (dataObjInfoHead->dataModify)) < ageLimit) {
		/* younger than ageLimit. Nothing to do */
    		freeAllDataObjInfo (dataObjInfoHead);
		return 0;
	    }
	}
    }
    if (dataObjUnlinkInp->oprType == UNREG_OPR ||
      getValByKey (&dataObjUnlinkInp->condInput, FORCE_FLAG_KW) != NULL ||
      getValByKey (&dataObjUnlinkInp->condInput, REPL_NUM_KW) != NULL ||
      dataObjInfoHead->specColl != NULL || rmTrashFlag == 1) {
        status = _rsDataObjUnlink (rsComm, dataObjUnlinkInp, &dataObjInfoHead);
    } else {
        initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
        status = applyRule ("acTrashPolicy", NULL, &rei, NO_SAVE_REI);
        trashPolicy = rei.status;

        if (trashPolicy != NO_TRASH_CAN) {
            status = rsMvDataObjToTrash (rsComm, dataObjUnlinkInp, 
	      &dataObjInfoHead);
    	    freeAllDataObjInfo (dataObjInfoHead);
            return status;
        } else {
            status = _rsDataObjUnlink (rsComm, dataObjUnlinkInp, 
	      &dataObjInfoHead);
        }
    }

    initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
    rei.doi = dataObjInfoHead;
    rei.status = status;
    rei.status = applyRule ("acPostProcForDelete", NULL, &rei, NO_SAVE_REI);

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

    /* dataObjInfoHead may be outdated */
    freeAllDataObjInfo (dataObjInfoHead);

    return (status);
}
Example #7
0
int
_rsDataObjUnlink (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
dataObjInfo_t **dataObjInfoHead)
{
    int status;
    int retVal = 0;
    dataObjInfo_t *tmpDataObjInfo, *myDataObjInfoHead;

    status = chkPreProcDeleteRule (rsComm, dataObjUnlinkInp, *dataObjInfoHead);
    if (status < 0) return status;

#if 0	/* done in chkPreProcDeleteRule */
    ruleExecInfo_t rei;
    initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
    rei.doi = *dataObjInfoHead;

    status = applyRule ("acDataDeletePolicy", NULL, &rei, NO_SAVE_REI);

    if (status < 0 && status != NO_MORE_RULES_ERR &&
      status != SYS_DELETE_DISALLOWED) {
        rodsLog (LOG_NOTICE,
          "_rsDataObjUnlink: acDataDeletePolicy error for %s. status = %d",
          dataObjUnlinkInp->objPath, status);
        return (status);
    }

    if (rei.status == SYS_DELETE_DISALLOWED) {
        rodsLog (LOG_NOTICE,
        "_rsDataObjUnlink:disallowed for %s via acDataDeletePolicy,stat=%d",
          dataObjUnlinkInp->objPath, rei.status);
        return (rei.status);
    }
#endif

    myDataObjInfoHead = *dataObjInfoHead;
    if (strstr (myDataObjInfoHead->dataType, BUNDLE_STR) != NULL) {
	int numSubfiles;
        if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
            return CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
	}
	if (getValByKey (&dataObjUnlinkInp->condInput, REPL_NUM_KW) != NULL) {
	    return SYS_CANT_MV_BUNDLE_DATA_BY_COPY;
	}
	numSubfiles = getNumSubfilesInBunfileObj (rsComm, 
	  myDataObjInfoHead->objPath);
	if (numSubfiles > 0) {
	    if (getValByKey (&dataObjUnlinkInp->condInput, 
	      EMPTY_BUNDLE_ONLY_KW) != NULL) {
		/* not empty. Nothing yo do */
		return 0;
	    } else {
	        status = _unbunAndStageBunfileObj (rsComm, dataObjInfoHead, 
		  NULL, 1);
	        if (status < 0) {
	            /* go ahead and unlink the obj if the phy file does not 
		     * exist or have problem untaring it */
	            if (getErrno (status) != EEXIST && 
	                getIrodsErrno (status) != 
			  SYS_TAR_STRUCT_FILE_EXTRACT_ERR) {
                        rodsLogError (LOG_ERROR, status,
                        "_rsDataObjUnlink:_unbunAndStageBunfileObj err for %s",
                          myDataObjInfoHead->objPath);
                        return (status);
	            }
                }
	        /* dataObjInfoHead may be outdated */
	        *dataObjInfoHead = NULL;
                status = getDataObjInfoIncSpecColl (rsComm, dataObjUnlinkInp,
                  dataObjInfoHead);

                if (status < 0) return (status);
            }
	}
    }
    tmpDataObjInfo = *dataObjInfoHead;
    while (tmpDataObjInfo != NULL) {
	status = dataObjUnlinkS (rsComm, dataObjUnlinkInp, tmpDataObjInfo);
	if (status < 0) {
	    if (retVal == 0) {
	        retVal = status;
	    }
	}
        if (dataObjUnlinkInp->specColl != NULL) 	/* do only one */
	    break;
	tmpDataObjInfo = tmpDataObjInfo->next;
    }

    if ((*dataObjInfoHead)->specColl == NULL)
        resolveDataObjReplStatus (rsComm, dataObjUnlinkInp);

    return (retVal);
}
Example #8
0
int
rsDataObjUnlink( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp ) {
    int status;
    ruleExecInfo_t rei;
    int trashPolicy;
    dataObjInfo_t *dataObjInfoHead = NULL;
    rodsServerHost_t *rodsServerHost = NULL;
    int rmTrashFlag = 0;
    specCollCache_t *specCollCache = NULL;

    resolveLinkedPath( rsComm, dataObjUnlinkInp->objPath, &specCollCache,
                       &dataObjUnlinkInp->condInput );
    status = getAndConnRcatHost( rsComm, MASTER_RCAT,
                                 ( const char* )dataObjUnlinkInp->objPath, &rodsServerHost );

    if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
        return status;
    }
    else if ( rodsServerHost->rcatEnabled == REMOTE_ICAT ) {
        rcDataObjUnlink( rodsServerHost->conn, dataObjUnlinkInp );
        return status;
    }

    // =-=-=-=-=-=-=-
    // working on the "home zone", determine if we need to redirect to a different
    // server in this zone for this operation.  if there is a RESC_HIER_STR_KW then
    // we know that the redirection decision has already been made

    // =-=-=-=-=-=-=-
    // determine the resource hierarchy if one is not provided
    addKeyVal(
        &dataObjUnlinkInp->condInput,
        irods::UNLINK_OPERATION.c_str(),
        "true" );
    if ( getValByKey( &dataObjUnlinkInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
        std::string       hier;
        irods::error ret = irods::resolve_resource_hierarchy( irods::OPEN_OPERATION,
                           rsComm, dataObjUnlinkInp, hier );
        if ( !ret.ok() ) {
            std::stringstream msg;
            msg << "failed in irods::resolve_resource_hierarchy for [";
            msg << dataObjUnlinkInp->objPath << "]";
            irods::log( PASSMSG( msg.str(), ret ) );
            return ret.code();
        }

        // =-=-=-=-=-=-=-
        // we resolved the redirect and have a host, set the hier str for subsequent
        // api calls, etc.
        addKeyVal( &dataObjUnlinkInp->condInput, RESC_HIER_STR_KW, hier.c_str() );

    } // if keyword

    if ( getValByKey(
                &dataObjUnlinkInp->condInput, ADMIN_RMTRASH_KW ) != NULL ||
            getValByKey(
                &dataObjUnlinkInp->condInput, RMTRASH_KW ) != NULL ) {
        if ( isTrashPath( dataObjUnlinkInp->objPath ) == False ) {
            return SYS_INVALID_FILE_PATH;
        }
        rmTrashFlag = 1;
    }

    dataObjUnlinkInp->openFlags = O_WRONLY;  /* set the permission checking */
    status = getDataObjInfoIncSpecColl( rsComm, dataObjUnlinkInp,
                                        &dataObjInfoHead );

    if ( status < 0 ) {
        char* sys_error = NULL;
        const char* rods_error = rodsErrorName( status, &sys_error );
        std::stringstream msg;
        msg << __FUNCTION__;
        msg << " - Failed to get data objects.";
        msg << " - " << rods_error << " " << sys_error;
        irods::error result = ERROR( status, msg.str() );
        irods::log( result );
        free( sys_error );
        return status;
    }

    if ( rmTrashFlag == 1 ) {
        char *tmpAge;
        int ageLimit;
        if ( ( tmpAge = getValByKey( &dataObjUnlinkInp->condInput, AGE_KW ) )
                != NULL ) {
            ageLimit = atoi( tmpAge ) * 60;
            if ( ( time( 0 ) - atoi( dataObjInfoHead->dataModify ) ) < ageLimit ) {
                /* younger than ageLimit. Nothing to do */
                freeAllDataObjInfo( dataObjInfoHead );
                return 0;
            }
        }
    }

    if ( dataObjUnlinkInp->oprType == UNREG_OPR ||
            getValByKey( &dataObjUnlinkInp->condInput, FORCE_FLAG_KW ) != NULL ||
            getValByKey( &dataObjUnlinkInp->condInput, REPL_NUM_KW ) != NULL ||
            getValByKey( &dataObjUnlinkInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ||
            dataObjInfoHead->specColl != NULL || rmTrashFlag == 1 ) {
        status = _rsDataObjUnlink( rsComm, dataObjUnlinkInp, &dataObjInfoHead );
    }
    else {
        initReiWithDataObjInp( &rei, rsComm, dataObjUnlinkInp );
        status = applyRule( "acTrashPolicy", NULL, &rei, NO_SAVE_REI );
        trashPolicy = rei.status;

        if ( trashPolicy != NO_TRASH_CAN ) {
            status = rsMvDataObjToTrash( rsComm, dataObjUnlinkInp,
                                         &dataObjInfoHead );
            freeAllDataObjInfo( dataObjInfoHead );
            return status;
        }
        else {
            status = _rsDataObjUnlink( rsComm, dataObjUnlinkInp,
                                       &dataObjInfoHead );
        }
    }

    initReiWithDataObjInp( &rei, rsComm, dataObjUnlinkInp );
    rei.doi = dataObjInfoHead;
    rei.status = status;

    // 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);

    rei.status = applyRule( "acPostProcForDelete", NULL, &rei, NO_SAVE_REI );

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

    /* dataObjInfoHead may be outdated */
    freeAllDataObjInfo( dataObjInfoHead );

    return status;
}
Example #9
0
int
_rsDataObjUnlink( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
                  dataObjInfo_t **dataObjInfoHead ) {
    int status;
    int retVal = 0;
    dataObjInfo_t *tmpDataObjInfo, *myDataObjInfoHead;

    status = chkPreProcDeleteRule( rsComm, dataObjUnlinkInp, *dataObjInfoHead );
    if ( status < 0 ) {
        return status;
    }


    myDataObjInfoHead = *dataObjInfoHead;
    if ( strstr( myDataObjInfoHead->dataType, BUNDLE_STR ) != NULL ) { // JMC - backport 4658
        int numSubfiles; // JMC - backport 4552
        if ( rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH ) {
            return CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
        }
        if ( getValByKey( &dataObjUnlinkInp->condInput, REPL_NUM_KW ) != NULL ) {
            return SYS_CANT_MV_BUNDLE_DATA_BY_COPY;
        }

        // =-=-=-=-=-=-=-
        // JMC - backport 4552
        numSubfiles = getNumSubfilesInBunfileObj( rsComm, myDataObjInfoHead->objPath );
        if ( numSubfiles > 0 ) {
            if ( getValByKey( &dataObjUnlinkInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) {
                /* not empty. Nothing to do */
                return 0;
            }
            else {
                status = _unbunAndStageBunfileObj( rsComm, dataObjInfoHead, &dataObjUnlinkInp->condInput, NULL, 1 );
                if ( status < 0 ) {
                    /* go ahead and unlink the obj if the phy file does not
                     * exist or have problem untaring it */
                    if ( getErrno( status ) != EEXIST && getIrodsErrno( status ) != SYS_TAR_STRUCT_FILE_EXTRACT_ERR ) {
                        rodsLogError( LOG_ERROR, status, "_rsDataObjUnlink:_unbunAndStageBunfileObj err for %s",
                                      myDataObjInfoHead->objPath );
                        return status;
                    }
                } // status < 0
                /* dataObjInfoHead may be outdated */
                *dataObjInfoHead = NULL;
                status = getDataObjInfoIncSpecColl( rsComm, dataObjUnlinkInp, dataObjInfoHead );

                if ( status < 0 ) {
                    return status;
                }
            } // else
        } // if numSubfiles
    } // if strcmp
    // =-=-=-=-=-=-=-

    tmpDataObjInfo = *dataObjInfoHead;
    while ( tmpDataObjInfo != NULL ) {
        status = dataObjUnlinkS( rsComm, dataObjUnlinkInp, tmpDataObjInfo );
        if ( status < 0 ) {
            if ( retVal == 0 ) {
                retVal = status;
            }
        }
        if ( dataObjUnlinkInp->specColl != NULL ) {     /* do only one */
            break;
        }
        tmpDataObjInfo = tmpDataObjInfo->next;
    }

    if ( ( *dataObjInfoHead )->specColl == NULL ) {
        resolveDataObjReplStatus( rsComm, dataObjUnlinkInp );
    }

    return retVal;
}