示例#1
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);
}
示例#2
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;
}