<commit_before>// =-=-=-=-=-=-=-
// irods includes
#include "msParam.hpp"
#include "reGlobalsExtern.hpp"
#include "generalAdmin.hpp"
#include "physPath.hpp"
#include "reIn2p3SysRule.hpp"
#include "miscServerFunct.hpp"

// =-=-=-=-=-=-=-
#include "irods_resource_plugin.hpp"
#include "irods_file_object.hpp"
#include "irods_physical_object.hpp"
#include "irods_collection_object.hpp"
#include "irods_string_tokenize.hpp"
#include "irods_hierarchy_parser.hpp"
#include "irods_resource_redirect.hpp"
#include "irods_stacktrace.hpp"

// =-=-=-=-=-=-=-
// stl includes
#include <iostream>
#include <sstream>
#include <vector>
#include <string>

// =-=-=-=-=-=-=-
// boost includes
#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
#include <boost/any.hpp>
#include <boost/algorithm/string.hpp>

/// =-=-=-=-=-=-=-
/// @brief Check the general parameters passed in to most plugin functions
template< typename DEST_TYPE >
inline irods::error univ_mss_check_param(
    irods::resource_plugin_context& _ctx ) {
    // =-=-=-=-=-=-=-
    // ask the context if it is valid
    irods::error ret = _ctx.valid< DEST_TYPE >();
    if ( !ret.ok() ) {
        return PASSMSG( "resource context is invalid", ret );

    }

    return SUCCESS();

} // univ_mss_check_param


extern "C" {

#define NB_READ_TOUT_SEC        60      /* 60 sec timeout */
#define NB_WRITE_TOUT_SEC       60      /* 60 sec timeout */

    // =-=-=-=-=-=-=-
    /// @brief token to index the script property
    const std::string SCRIPT_PROP( "script" );

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX create
    irods::error univ_mss_file_create(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_create

    // =-=-=-=-=-=-=-
    // interface for POSIX Open
    irods::error univ_mss_file_open(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_open

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Read
    irods::error univ_mss_file_read(
        irods::resource_plugin_context& ,
        void*,
        int ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_read

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Write
    irods::error univ_mss_file_write(
        irods::resource_plugin_context&,
        void*,
        int ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_write

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Close
    irods::error univ_mss_file_close(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_close

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Unlink
    irods::error univ_mss_file_unlink(
        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 status;
        execCmd_t execCmdInp;
        char cmdArgv[HUGE_NAME_LEN] = "";
        execCmdOut_t *execCmdOut = NULL;

        bzero( &execCmdInp, sizeof( execCmdInp ) );
        rstrcpy( execCmdInp.cmd, script.c_str(), LONG_NAME_LEN );
        strcat( cmdArgv, "rm" );
        strcat( cmdArgv, " '" );
        strcat( cmdArgv, filename.c_str() );
        strcat( cmdArgv, "'" );
        rstrcpy( execCmdInp.cmdArgv, cmdArgv, HUGE_NAME_LEN );
        rstrcpy( execCmdInp.execAddr, "localhost", LONG_NAME_LEN );
        status = _rsExecCmd( &execCmdInp, &execCmdOut );
<commit_msg>[#2212] CID37652:<commit_after>// =-=-=-=-=-=-=-
// irods includes
#include "msParam.hpp"
#include "reGlobalsExtern.hpp"
#include "generalAdmin.hpp"
#include "physPath.hpp"
#include "reIn2p3SysRule.hpp"
#include "miscServerFunct.hpp"

// =-=-=-=-=-=-=-
#include "irods_resource_plugin.hpp"
#include "irods_file_object.hpp"
#include "irods_physical_object.hpp"
#include "irods_collection_object.hpp"
#include "irods_string_tokenize.hpp"
#include "irods_hierarchy_parser.hpp"
#include "irods_resource_redirect.hpp"
#include "irods_stacktrace.hpp"

// =-=-=-=-=-=-=-
// stl includes
#include <iostream>
#include <sstream>
#include <vector>
#include <string>

// =-=-=-=-=-=-=-
// boost includes
#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
#include <boost/any.hpp>
#include <boost/algorithm/string.hpp>

/// =-=-=-=-=-=-=-
/// @brief Check the general parameters passed in to most plugin functions
template< typename DEST_TYPE >
inline irods::error univ_mss_check_param(
    irods::resource_plugin_context& _ctx ) {
    // =-=-=-=-=-=-=-
    // ask the context if it is valid
    irods::error ret = _ctx.valid< DEST_TYPE >();
    if ( !ret.ok() ) {
        return PASSMSG( "resource context is invalid", ret );

    }

    return SUCCESS();

} // univ_mss_check_param


extern "C" {

#define NB_READ_TOUT_SEC        60      /* 60 sec timeout */
#define NB_WRITE_TOUT_SEC       60      /* 60 sec timeout */

    // =-=-=-=-=-=-=-
    /// @brief token to index the script property
    const std::string SCRIPT_PROP( "script" );

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX create
    irods::error univ_mss_file_create(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_create

    // =-=-=-=-=-=-=-
    // interface for POSIX Open
    irods::error univ_mss_file_open(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_open

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Read
    irods::error univ_mss_file_read(
        irods::resource_plugin_context& ,
        void*,
        int ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_read

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Write
    irods::error univ_mss_file_write(
        irods::resource_plugin_context&,
        void*,
        int ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_write

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Close
    irods::error univ_mss_file_close(
        irods::resource_plugin_context& ) {
        return ERROR( SYS_NOT_SUPPORTED, __FUNCTION__ );

    } // univ_mss_file_close

    /// =-=-=-=-=-=-=-
    /// @brief interface for POSIX Unlink
    irods::error univ_mss_file_unlink(
        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();

        execCmd_t execCmdInp;
        memset( &execCmdInp, 0, sizeof( execCmdInp ) );
        snprintf( execCmdInp.cmd, sizeof( execCmdInp.cmd ), "%s", script.c_str() );
        snprintf( execCmdInp.cmdArgv, sizeof( execCmdInp.cmdArgv ), "rm '%s'", filename.c_str() );
        snprintf( execCmdInp.execAddr, sizeof( execCmdInp.execAddr ), "localhost" );

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

{'fraction_non_alphanumeric': 0.16729902774484232, 'fraction_numerical': 0.0035570310647379654, 'mean_word_length': 2.4414524683802528, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5923834', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2807, 'n_words': 565}