Exemple #1
0
    /// =-=-=-=-=-=-=-
    /// @brief This routine is for testing the TEST_STAGE_FILE_TYPE.
    ///        Just copy the file from filename to cacheFilename. optionalInfo info
    ///        is not used.
    irods::error univ_mss_file_stage_to_cache(
        irods::resource_plugin_context& _ctx,
        const char*                         _cache_file_name ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::file_object_ptr fco = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        int status = 0;

        std::stringstream cmdArgv;
        cmdArgv << "stageToCache '" << filename << "' '" << _cache_file_name << "'";

        execCmd_t execCmdInp;
        bzero( &execCmdInp, sizeof( execCmdInp ) );
        snprintf( execCmdInp.cmd, sizeof( execCmdInp.cmd ), "%s",  script.c_str() );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "%s", cmdArgv.str().c_str() );
        snprintf( execCmdInp.execAddr, sizeof( execCmdInp.execAddr ), "%s", "localhost" );

        execCmdOut_t *execCmdOut = NULL;
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
        freeCmdExecOut( execCmdOut );

        if ( status < 0 ) {
            status = UNIV_MSS_STAGETOCACHE_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_stage_to_cache: staging from [";
            msg << _cache_file_name;
            msg << "] to [";
            msg << filename;
            msg << "] failed.";
            return ERROR( status, msg.str() );
        }

        return CODE( status );

    } // univ_mss_file_stage_to_cache
Exemple #2
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX chmod
    irods::error univ_mss_file_chmod(
        irods::resource_plugin_context& _ctx ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::data_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::data_object_ptr fco = boost::dynamic_pointer_cast< irods::data_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        int mode = fco->mode();
        int status = 0;
        execCmd_t execCmdInp;

        if ( mode != getDefDirMode() ) {
            mode = getDefFileMode();
        }

        bzero( &execCmdInp, sizeof( execCmdInp ) );
        snprintf( execCmdInp.cmd, sizeof( execCmdInp.cmd ), "%s", script.c_str() );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "chmod '%s' %o", filename.c_str(), mode );
        snprintf( execCmdInp.execAddr, sizeof( execCmdInp.execAddr ), "%s", "localhost" );
        execCmdOut_t *execCmdOut = NULL;
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
        freeCmdExecOut( execCmdOut );

        if ( status < 0 ) {
            status = UNIV_MSS_CHMOD_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_chmod - failed for [";
            msg << filename;
            msg << "]";
            return ERROR( status, msg.str() );

        }

        return CODE( status );

    } // univ_mss_file_chmod
Exemple #3
0
/*
 * Set retOutParam to 1 if you need to retrieve the output parameters from inMsParamArray and 0 if not
 */
Res *parseAndComputeExpressionAdapter( char *inAction, msParamArray_t *inMsParamArray, int retOutParams, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { // JMC - backport 4540
    /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */
    int recclearDelayed = ruleEngineConfig.clearDelayed;
    ruleEngineConfig.clearDelayed = 0;
    int freeRei = 0;
    if ( rei == NULL ) {
        rei = ( ruleExecInfo_t * ) malloc( sizeof( ruleExecInfo_t ) );
        memset( rei, 0, sizeof( ruleExecInfo_t ) );
        freeRei = 1;
    }
    rei->status = 0;
    Env *env = defaultEnv( r );
    /* retrieve generated data here as it may be overridden by convertMsParamArrayToEnv */
    execCmdOut_t *execOut = addCmdExecOutToEnv( globalEnv( env ), r );
    Res *res;
    rError_t errmsgBuf;
    errmsgBuf.errMsg = NULL;
    errmsgBuf.len = 0;

    msParamArray_t *orig = rei->msParamArray;
    rei->msParamArray = NULL;

    if ( inMsParamArray != NULL ) {
        convertMsParamArrayToEnv( inMsParamArray, env, r );
    }

    res = parseAndComputeExpression( inAction, env, rei, reiSaveFlag, &errmsgBuf, r );
    if ( retOutParams ) { // JMC - backport 4540
        if ( inMsParamArray != NULL ) {
            clearMsParamArray( inMsParamArray, 0 );
            convertEnvToMsParamArray( inMsParamArray, env, &errmsgBuf, r );
        }
    }
    rei->msParamArray = orig;

    freeCmdExecOut( execOut );
    /* deleteEnv(env, 3); */
    if ( getNodeType( res ) == N_ERROR && !freeRei ) {
        logErrMsg( &errmsgBuf, &rei->rsComm->rError );
        rei->status = RES_ERR_CODE( res );
    }
    freeRErrorContent( &errmsgBuf );
    if ( freeRei ) {
        free( rei );
    }
    if ( recclearDelayed ) {
        clearDelayed();
    }
    ruleEngineConfig.clearDelayed = recclearDelayed;
    return res;

}
Exemple #4
0
    /// =-=-=-=-=-=-=-
    /// @brief This routine is for testing the TEST_STAGE_FILE_TYPE.
    ///        Just copy the file from cacheFilename to filename. optionalInfo info
    ///        is not used.
    irods::error univ_mss_file_sync_to_arch(
        irods::resource_plugin_context& _ctx,
        const char*                         _cache_file_name ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::file_object_ptr fco = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        // =-=-=-=-=-=-=-
        // first create the directory name
        char  dirname[MAX_NAME_LEN] = "";
        const char* lastpart = strrchr( filename.c_str(), '/' );
        int   lenDir   = strlen( filename.c_str() ) - strlen( lastpart );
        strncpy( dirname, filename.c_str(), lenDir );

        // =-=-=-=-=-=-=-
        // create a context to call the mkdir operation
        irods::collection_object_ptr coll_obj(
            new irods::collection_object(
                dirname,
                fco->resc_hier(),
                fco->mode(), 0 ) );
        irods::resource_plugin_context context(
            _ctx.prop_map(),
            coll_obj, "",
            _ctx.comm(),
            _ctx.child_map() );

        // =-=-=-=-=-=-=-
        // create the directory on the MSS
        int status = 0;
        err = univ_mss_file_mkdir( context );

        execCmdOut_t* execCmdOut = NULL;

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        execCmd_t execCmdInp;
        bzero( &execCmdInp, sizeof( execCmdInp ) );
        rstrcpy( execCmdInp.cmd, script.c_str(), LONG_NAME_LEN );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "syncToArch %s %s", _cache_file_name, filename.c_str() );
        rstrcpy( execCmdInp.execAddr, "localhost", LONG_NAME_LEN );
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
        if ( status == 0 ) {
            err = univ_mss_file_chmod( _ctx );
            if ( !err.ok() ) {
                PASSMSG( "univ_mss_file_sync_to_arch - failed.", err );
            }
        }
        else {
            status = UNIV_MSS_SYNCTOARCH_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_sync_to_arch: copy of [";
            msg << _cache_file_name;
            msg << "] to [";
            msg << filename;
            msg << "] failed.";
            msg << "   stdout buff [";
            msg << execCmdOut->stdoutBuf.buf;
            msg << "]   stderr buff [";
            msg << execCmdOut->stderrBuf.buf;
            msg << "]  status [";
            msg << execCmdOut->status << "]";
            freeCmdExecOut( execCmdOut );
            return ERROR( status, msg.str() );
        }

        return CODE( status );

    } // univ_mss_file_sync_to_arch
Exemple #5
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX rename
    irods::error univ_mss_file_rename(
        irods::resource_plugin_context& _ctx,
        const char*                      _new_file_name ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::file_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::file_object_ptr fco = boost::dynamic_pointer_cast< irods::file_object >( _ctx.fco() );
        std::string filename = fco->physical_path();

        // =-=-=-=-=-=-=-
        // first create the directory name
        char  dirname[MAX_NAME_LEN] = "";
        const char* lastpart = strrchr( _new_file_name, '/' );
        int   lenDir   = strlen( _new_file_name ) - strlen( lastpart );
        strncpy( dirname, _new_file_name, lenDir );

        // =-=-=-=-=-=-=-
        // create a context to call the mkdir operation
        irods::collection_object_ptr coll_obj(
            new irods::collection_object(
                dirname,
                fco->resc_hier(),
                fco->mode(), 0 ) );
        irods::resource_plugin_context context(
            _ctx.prop_map(),
            coll_obj, "",
            _ctx.comm(),
            _ctx.child_map() );

        // =-=-=-=-=-=-=-
        // create the directory on the MSS
        int status = 0;
        err = univ_mss_file_mkdir( context );

        execCmd_t execCmdInp;

        bzero( &execCmdInp, sizeof( execCmdInp ) );
        snprintf( execCmdInp.cmd, sizeof( execCmdInp.cmd ), "%s", script.c_str() );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "mv '%s' '%s'", filename.c_str(), _new_file_name );
        snprintf( execCmdInp.execAddr, sizeof( execCmdInp.execAddr ), "%s", "localhost" );
        execCmdOut_t *execCmdOut = NULL;
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
        freeCmdExecOut( execCmdOut );

        if ( status < 0 ) {
            status = UNIV_MSS_RENAME_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_rename - failed for [";
            msg << filename;
            msg << "]";
            return ERROR( status, msg.str() );

        }

        return CODE( status );

    } // univ_mss_file_rename
Exemple #6
0
    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Stat
    irods::error univ_mss_file_stat(
        irods::resource_plugin_context& _ctx,
        struct stat*                     _statbuf ) {
        // =-=-=-=-=-=-=-
        // check context
        irods::error err = univ_mss_check_param< irods::data_object >( _ctx );
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " - invalid context";
            return PASSMSG( msg.str(), err );

        }

        // =-=-=-=-=-=-=-
        // get the script property
        std::string script;
        err = _ctx.prop_map().get< std::string >( SCRIPT_PROP, script );
        if ( !err.ok() ) {
            return PASSMSG( __FUNCTION__, err );
        }

        // =-=-=-=-=-=-=-
        // snag a ref to the fco
        irods::data_object_ptr fco = boost::dynamic_pointer_cast< irods::data_object >( _ctx.fco() );
        std::string filename = fco->physical_path();


        int i, status;
        execCmd_t execCmdInp;
        char cmdArgv[HUGE_NAME_LEN] = "";
        char *outputStr;
        const char *delim1 = ":\n";
        const char *delim2 = "-";
        const char *delim3 = ".";
        execCmdOut_t *execCmdOut = NULL;
        struct tm mytm;
        time_t myTime;

        bzero( &execCmdInp, sizeof( execCmdInp ) );
        rstrcpy( execCmdInp.cmd, script.c_str(), LONG_NAME_LEN );
        snprintf( cmdArgv, sizeof( cmdArgv ), "stat '%s' ", filename.c_str() );
        rstrcpy( execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN );
        rstrcpy( execCmdInp.execAddr, "localhost", LONG_NAME_LEN );
        status = _rsExecCmd( &execCmdInp, &execCmdOut );

        if ( status == 0 && NULL != execCmdOut ) { // JMC cppcheck - nullptr
            if ( execCmdOut->stdoutBuf.buf != NULL ) {
                outputStr = ( char* )execCmdOut->stdoutBuf.buf;
                std::vector<std::string> output_tokens;
                boost::algorithm::split( output_tokens, outputStr, boost::is_any_of( delim1 ) );
                _statbuf->st_dev = atoi( output_tokens[0].c_str() );
                _statbuf->st_ino = atoi( output_tokens[1].c_str() );
                _statbuf->st_mode = atoi( output_tokens[2].c_str() );
                _statbuf->st_nlink = atoi( output_tokens[3].c_str() );
                _statbuf->st_uid = atoi( output_tokens[4].c_str() );
                _statbuf->st_gid = atoi( output_tokens[5].c_str() );
                _statbuf->st_rdev = atoi( output_tokens[6].c_str() );
                _statbuf->st_size = atoll( output_tokens[7].c_str() );
                _statbuf->st_blksize = atoi( output_tokens[8].c_str() );
                _statbuf->st_blocks = atoi( output_tokens[9].c_str() );
                for ( i = 0; i < 3; i++ ) {
                    std::vector<std::string> date_tokens;
                    boost::algorithm::split( date_tokens, output_tokens[10 + i], boost::is_any_of( delim2 ) );
                    mytm.tm_year = atoi( date_tokens[0].c_str() ) - 1900;
                    mytm.tm_mon = atoi( date_tokens[1].c_str() ) - 1;
                    mytm.tm_mday = atoi( date_tokens[2].c_str() );
                    std::vector<std::string> time_tokens;
                    boost::algorithm::split( time_tokens, date_tokens[3], boost::is_any_of( delim3 ) );
                    mytm.tm_hour = atoi( time_tokens[0].c_str() );
                    mytm.tm_min = atoi( time_tokens[1].c_str() );
                    mytm.tm_sec = atoi( time_tokens[2].c_str() );
                    myTime = mktime( &mytm );
                    switch ( i ) {
                    case 0:
                        _statbuf->st_atime = myTime;
                        break;
                    case 1:
                        _statbuf->st_mtime = myTime;
                        break;
                    case 2:
                        _statbuf->st_ctime = myTime;
                        break;
                    }
                }
            }
        }
        else {
            status = UNIV_MSS_STAT_ERR - errno;
            std::stringstream msg;
            msg << "univ_mss_file_stat - failed for [";
            msg << filename;
            msg << "]";
            freeCmdExecOut( execCmdOut );
            return ERROR( status, msg.str() );

        }

        freeCmdExecOut( execCmdOut );
        return CODE( status );

    } // univ_mss_file_stat