Esempio n. 1
0
rc_t vdi_repo( const Vector * v )
{
    KConfig * cfg;
    rc_t rc = KConfigMake( &cfg, NULL );
    if ( rc == 0 )
    {
        const KRepositoryMgr * repomgr;
        rc = KConfigMakeRepositoryMgrRead( cfg, &repomgr );
        {
            if ( VectorLength( v ) < 2 )
            {
                rc = vdi_repo_all( repomgr, true );
            }
            else
            {
                const String * which_repo = VectorGet( v, 1 );
                if ( which_repo != NULL )
                {
                    int32_t repo_id = index_of_match( which_repo, 4, "user", "site", "remote", "all" );
                    if ( repo_id < 0 || repo_id > 3 )
                        rc = KOutMsg( "unknow repository '%S'", which_repo );
                    else
                        rc = vdi_sub_repo( repomgr, v, which_repo, repo_id );
                }
            }

            KRepositoryMgrRelease( repomgr );
        }
        KConfigRelease ( cfg );
    }
    return rc;
}
Esempio n. 2
0
/* Make
 */
static
rc_t SRAMgrInitPath ( SRAMgr *mgr, const KDirectory *wd )
{
#if OLD_SRAPATH_MGR
    /* try to make the path manager */
    rc_t rc = SRAPathMake ( & mgr -> _pmgr, wd );

    if ( GetRCState ( rc ) == rcNotFound && GetRCTarget ( rc ) == rcDylib )
    {
        /* we are operating outside of the archive */
        assert ( mgr -> _pmgr == NULL );
        rc = 0;
    }

    return rc;
#else
    KConfig *kfg;
    rc_t rc = KConfigMake ( & kfg, NULL );
    if ( rc == 0 )
    {
        VFSManager *vfs;
        rc = VFSManagerMake ( & vfs );
        if ( rc == 0 )
        {
            rc = VFSManagerMakeResolver ( vfs, ( VResolver** ) & mgr -> _pmgr, kfg );
            VFSManagerRelease ( vfs );
        }
        KConfigRelease ( kfg );
    }
    if ( rc != 0 )
        mgr -> _pmgr = NULL;

    return 0;
#endif
}
Esempio n. 3
0
LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file,
    bool use_config, bool status)
{
    static const char *bin = NULL;
    static const char *key = NULL;
    rc_t rc = 0;
    KConfig *cfg = NULL;
    bool found = false;
    if (ascp_bin == NULL || private_file == NULL) {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    *ascp_bin = *private_file = NULL;
    rc = returnAscp(bin, key, ascp_bin, private_file, &found);
    if (rc != 0 || found) {
        return rc;
    }
    rc = KConfigMake(&cfg, NULL);
    if (rc != 0) {
        return rc;
    }
    if (_KConfigAscpDisabled(cfg, status)) {
        if (status) {
            STSMSG(STS_INFO, ("Use of Aspera transfer is disabled "
                "by the configuration, using HTTP transfer"));
        }
    }
    else {
        KDirectory *dir = NULL;
        rc = _KConfigGetAscp(cfg, &bin, &key);
        if (bin != NULL) {
            assert(key && !rc);
            RELEASE(KConfig, cfg);
            rc = returnAscp(bin, key, ascp_bin, private_file, &found);
            if (rc != 0 || found) {
                return rc;
            }
        }
        rc = KDirectoryNativeDir(&dir);
        if (rc != 0) {
            return rc;
        }
        while (ascp_path(&bin, &key)) {
            if (_SystemHelp(bin, status)) {
                if (_KDirectoryFileFound(dir, key, status)) {
                    break;
                }
            }
        }
        RELEASE(KDirectory, dir);
    }
    RELEASE(KConfig, cfg);

    rc = returnAscp(bin, key, ascp_bin, private_file, &found);
    if (rc != 0 || found) {
        return rc;
    }
    else {
        return RC(rcNS, rcFile, rcCopying, rcFile, rcNotFound);
    }
}
Esempio n. 4
0
    DepFixture(const char *path)
        : mgr(NULL)
        , vmgr(NULL)
        , resolver(NULL)
        , siteless(false)
    {
        rc_t rc = 0;

        KDirectory *wd = NULL;
        if (KDirectoryNativeDir(&wd)) {
            FAIL("failed to KDirectoryNativeDir");
        }

        const KDirectory *dir = NULL;
        KConfig *cfg = NULL;

        if (KDirectoryOpenDirRead(wd, &dir, false, path)) {
            FAIL("failed to KDirectoryOpenDirRead()");
        }
        if (KConfigMake(&cfg, dir)) {
            FAIL("failed to KConfigMake()");
        }
        RELEASE(KDirectory, dir);
        if (VFSManagerMakeFromKfg(&vmgr, cfg)) {
            FAIL("failed to VFSManagerMakeFromKfg()");
        }
        if (VFSManagerGetResolver(vmgr, &resolver)) {
            FAIL("failed to VFSManagerGetResolver");
        }

        String *result = NULL;
        rc = KConfigReadString(cfg, "repository/site/main/tracearc/root",
            &result);
        if (rc != 0) {
            if (rc == SILENT_RC(rcKFG, rcNode, rcOpening, rcPath, rcNotFound)) {
                rc = 0;
                siteless = true;
            }
            else {
                FAIL(
              "failed to KConfigReadString(repository/site/main/tracearc/root)");
            }
        }
        else {
            assert(result);
            KPathType t = KDirectoryPathType(wd, result->addr);
            if (t != kptDir) {
                siteless = true;
            }
        }
        RELEASE(String, result);

        RELEASE(KConfig, cfg);
        if (VDBManagerMakeReadWithVFSManager(&mgr, NULL, vmgr)) {
            FAIL("failed to VDBManagerMakeReadWithVFSManager()");
        }

        RELEASE(KDirectory, wd);
    }
Esempio n. 5
0
CKConfig::CKConfig(void)
{
    KConfig* cfg;
    if ( rc_t rc = KConfigMake(&cfg, 0) ) {
        *x_InitPtr() = 0;
        NCBI_THROW2(CSraException, eInitFailed,
                    "Cannot create KConfig", rc);
    }
    *x_InitPtr() = cfg;
}
Esempio n. 6
0
LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file,
    bool use_config, bool status)
{
    rc_t rc = 0;
    KConfig *cfg = NULL;
    if (ascp_bin == NULL || private_file == NULL) {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    *ascp_bin = *private_file = NULL;
    rc = KConfigMake(&cfg, NULL);
    if (rc != 0) {
        return rc;
    }
    if (_KConfigAscpDisabled(cfg, status)) {
        if (status) {
            STSMSG(STS_INFO, ("Use of Aspera transfer is disabled "
                "by the configuration, using HTTP transfer"));
        }
    }
    else {
        KDirectory *dir = NULL;
        const char *bin = NULL;
        const char *key = NULL;
        rc = _KConfigGetAscp(cfg, ascp_bin, private_file);
        if (*ascp_bin != NULL) {
            assert(*private_file && !rc);
            RELEASE(KConfig, cfg);
            return 0;
        }
        rc = KDirectoryNativeDir(&dir);
        if (rc != 0) {
            return rc;
        }
        while (ascp_path(&bin, &key)) {
            if (_SystemHelp(bin, status)) {
                if (_KDirectoryFileFound(dir, key, status)) {
                    *ascp_bin = string_dup_measure(bin, NULL);
                    *private_file = string_dup_measure(key, NULL);
                    if (*ascp_bin == NULL || *private_file == NULL) {
                        free((void*)*ascp_bin);
                        free((void*)*private_file);
                        *ascp_bin = *private_file = NULL;
                        return RC(rcNS,
                            rcStorage, rcAllocating, rcMemory, rcExhausted);
                    }
                    break;
                }
            }
        }
        RELEASE(KDirectory, dir);
    }
    RELEASE(KConfig, cfg);
    return rc;
}
Esempio n. 7
0
rc_t CC KMain(int argc, char* argv[]) {
    rc_t rc = 0;

    Params prm;
    KConfig* cfg = NULL;

    if (rc == 0)
    {   rc = ParamsConstruct(argc, argv, &prm); }

    if (rc == 0) {
        rc = KConfigMake(&cfg, NULL);
        DISP_RC(rc, "while calling KConfigMake");
    }

    if (rc == 0) {
        if (prm.modeSetNode)
        {   rc = SetNode(cfg, &prm); }
        if (prm.modeShowCfg)
        {   rc = ShowConfig(cfg, &prm); }
        if (prm.modeShowFiles) {
            rc_t rc3 = ShowFiles(cfg, &prm);
            if (rc3 != 0 && rc == 0)
            {   rc = rc3; }
        }
        if (prm.modeShowModules) {
            rc_t rc3 = ShowModules(cfg, &prm);
            if (rc3 != 0 && rc == 0)
            {   rc = rc3; }
        }
        if (prm.modeShowLoadPath) {
            const char* path = NULL;
            rc_t rc3 = KConfigGetLoadPath(cfg, &path);
            if (rc3 == 0) {
                if (path != NULL && path[0])
                {   OUTMSG(("%s\n", path)); }
            }
            else if (rc == 0)
            {   rc = rc3; }
        }
    }

    if (prm.modeShowEnv)
    {   ShowEnv(&prm); }

    RELEASE(KConfig, cfg);

    if (rc == 0 && prm.modeCreate)
    {   rc = CreateConfig(argv[0]); }

    ParamsDestruct(&prm);
    return rc;
}
Esempio n. 8
0
LIB_EXPORT rc_t CC aspera_options(AscpOptions *opt) {
    KConfig *cfg = NULL;
    rc_t rc = 0;
    if (opt == NULL) {
        return RC(rcNS, rcFile, rcVisiting, rcParam, rcNull);
    }
    memset(opt, 0, sizeof *opt);
    rc = KConfigMake(&cfg, NULL);
    if (rc == 0) {
        rc = _KConfigGetAscpRate(cfg, &opt->target_rate);
        opt->disabled = _KConfigAscpDisabled(cfg, false);
    }
    RELEASE(KConfig, cfg);
    return rc;
}
Esempio n. 9
0
LIB_EXPORT rc_t CC RefSeqMgr_Make( const RefSeqMgr** cself, const VDBManager* vmgr,
                                   uint32_t reader_options, size_t cache, uint32_t keep_open_num )
{
    rc_t rc = 0;
    RefSeqMgr* obj = NULL;
    
    if ( cself == NULL || vmgr == NULL )
    {
        rc = RC( rcAlign, rcIndex, rcConstructing, rcParam, rcNull );
    }
    else
    {
        obj = calloc( 1, sizeof( *obj ) );
        if ( obj == NULL )
        {
            rc = RC( rcAlign, rcIndex, rcConstructing, rcMemory, rcExhausted );
        }
        else
        {
            rc = KConfigMake( &obj->kfg, NULL );
            if ( rc == 0 )
            {
                rc = VDBManagerAddRef( vmgr );
                if ( rc == 0 )
                {
                    obj->vmgr = vmgr;
                    obj->cache = cache;
                    obj->num_open_max = keep_open_num;
                    obj->reader_options = reader_options;
                }
            }
        }
    }

    if ( rc == 0 )
    {
        *cself = obj;
/*        ALIGN_DBG( "max_open: %u", obj->num_open_max ); */
    }
    else
    {
        RefSeqMgr_Release( obj );
        ALIGN_DBGERR( rc );
    }
    return rc;
}
Esempio n. 10
0
LIB_EXPORT rc_t CC KNSManagerMake ( KNSManager **mgrp )
{
    KConfig* kfg;
    rc_t rc = KConfigMake(&kfg, NULL);
    if ( rc == 0 )
    {
        rc_t rc2;
        rc = KNSManagerMakeConfig ( mgrp, kfg );
        if ( rc == 0 )
            KNSManagerLoadAWS ( *mgrp );

        rc2 = KConfigRelease ( kfg );
        if ( rc == 0 )
        {   
            rc = rc2;
        }
    }
    return rc;
}
Esempio n. 11
0
/*))  Loading config. BTW, resource is a name of file or URL
 ((*/
LIB_EXPORT
rc_t CC
XFS_LoadConfig_ZHR (
                const char * Resource,
                const struct KConfig ** Config
)
{
    rc_t RCt;
    const struct KFile * File;
    struct KConfig * TmpConfig;

    RCt = 0;
    TmpConfig = NULL;
    File = NULL;

    if ( Resource == NULL || Config == NULL ) {
        return XFS_RC ( rcNull );
    }

    * Config = NULL;

        /* Trying to open resource as file */
    RCt = XFS_OpenResourceRead_MHR ( Resource, & File );
    if ( RCt == 0 ) {
        RCt = KConfigMake (
                        & TmpConfig,
                        NULL    /* We need new clear config each time */
                        );
        if ( RCt == 0 ) {
            RCt = KConfigLoadFile ( TmpConfig, Resource, File );
            if ( RCt == 0 ) {
                * Config = TmpConfig;
            }
            else {
                KConfigRelease ( TmpConfig );
            }
        }

        KFileRelease ( File );
    }
    return RCt;
}   /* XFS_LoadConfig_ZHR () */
Esempio n. 12
0
static rc_t check_if_schema_exists( KDirectory * dir, const char * schema_name )
{
    KConfig * cfg;
    rc_t rc = KConfigMake ( &cfg, NULL );
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "check_if_schema_exists:KConfigMake() failed" );
    }
    else
    {
        const KConfigNode *node;
        rc = KConfigOpenNodeRead ( cfg, &node, "vdb/schema/paths" );
        if ( rc !=  0 )
        {
            LOGERR( klogErr, rc, "check_if_schema_exists:KConfigOpenNodeRead( 'vdb/schema/paths' ) failed" );
        }
        else
        {
            char buffer[ 1024 ];
            size_t num_read;
            rc = KConfigNodeRead ( node, 0, buffer, sizeof buffer, &num_read, NULL );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "check_if_schema_exists:KConfigNodeRead() failed" );
            }
            else
            {
                uint32_t path_type;
                buffer[ num_read ] = 0;
                path_type = KDirectoryPathType ( dir, "%s/%s", buffer, schema_name );
                if ( ( path_type & kptFile ) == 0 )
                {
                    rc = RC( rcExe, rcFile, rcConstructing, rcParam, rcInvalid );
                }
            }
            KConfigNodeRelease ( node );
        }
        KConfigRelease ( cfg );
    }
    return rc;
}
Esempio n. 13
0
LIB_EXPORT rc_t CC aspera_get(
    const char *ascp_bin, const char *private_file, const char *aSrc,
    const char *dest, AscpOptions *opt)
{
    char path[PATH_MAX] = "";
    AscpOptions dummy;
    bool status = false;
    int64_t prev = -1;
    int attempt = 0;
    KDirectory *dir = NULL;
    TQuitting *quitting = NULL;
    const char *src = aSrc;
    rc_t rc = KDirectoryNativeDir(&dir);
    if (rc != 0) {
        return rc;
    }
    if (ascp_bin == NULL || private_file == NULL ||
        src == NULL || dest == NULL)
    {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    if (opt == NULL) {
        memset(&dummy, 0, sizeof dummy);
        opt = &dummy;
    }

    if (opt->ascp_options == NULL && opt->target_rate[0] == '\0') {
        KConfig *cfg = NULL;
        rc_t rc = KConfigMake(&cfg, NULL);
        DISP_RC(rc, "cannot KConfigMake");
        if (rc == 0) {
            rc = _KConfigGetAscpRate(cfg,
                opt->target_rate, sizeof opt->target_rate);
            DISP_RC(rc, "cannot get aspera max rate");
        }
        RELEASE(KConfig, cfg);
    }

    sStatus = status = opt->status;
    quitting = opt->quitting;

    {
        /* remove trailing #... or ?... from src path:
           it could come from Revolver */
        size_t s = string_size(aSrc);
        const char *n = string_chr(aSrc, s, '#');
        const char *q = string_chr(aSrc, s, '?');
        if (q != NULL && (n == NULL || q < n)) {
            n = q;
        }
        if (n != NULL) {
            if (n - aSrc + 1 > sizeof path) {
                return RC(rcNS, rcFile, rcCopying, rcBuffer, rcInsufficient);
            }
            else {
#if _DEBUGGING
                size_t s =
#endif
                    string_copy(path, sizeof path, aSrc, n - aSrc);
                assert(s <= sizeof path);
                src = path;
            }
        }
    }

    while (true) {
        rc = run_ascp(ascp_bin, private_file, src, dest, opt);
        if (rc == 0) {
            if (status) {
                STSMSG(STS_DBG, ("ascp finished with success"));
            }
            break;
        }
        else if (rc == SILENT_RC(rcExe,
            rcProcess, rcExecuting, rcMemory, rcExhausted))
        {
            if (status) {
                STSMSG(STS_DBG, ("ascp failed: %R", rc));
            }
            break;
        }
        else {
            rc_t rc2 = 0;
            uint64_t size = 0;
            if (quitting != NULL) {
                rc2 = quitting();
                if (rc2 != 0) {
                    break;
                }
            }
            if (status) {
                STSMSG(STS_DBG, ("ascp failed: %R", rc));
            }
            rc2 = KDirectoryFileSize(dir, &size, "%s", dest);
            if (rc2 ==
                SILENT_RC(rcFS, rcDirectory, rcAccessing, rcPath, rcNotFound))
            {
                if (prev < 0) {
                    if (status) {
                        STSMSG(0, ("fasp download failed. "
                            "File not found. Retrying..."));
                    }
                    prev = 0;
                }
                else {
                    if (status) {
                        STSMSG(0, ("fasp download failed. File not found."));
                    }
                    break;
                }
            }
            else if (rc2 != 0 || (int64_t)size < prev) {
                if (status) {
                    STSMSG(0, ("fasp download failed. KDirectoryFileSize "
                        "after ascp run: rc = %ld, size = %ld", rc, size));
                }
                break;
            }
            else if ((int64_t)size > prev) {
                if (status) {
                    STSMSG(STS_INFO, ("  fasp download failed. %ld bytes "
                        "received so far. Retrying...", size));
                }
                attempt = 0;
                prev = size;
            }
            else {
                if (attempt++ > 3) {
                    break;
                }
                if (status) {
                    STSMSG(STS_INFO, ("  fasp download failed. %ld bytes "
                        "received so far. Retrying %d...", size, attempt));
                }
            }
        }
    }

    RELEASE(KDirectory, dir);
    return rc;
}
Esempio n. 14
0
LIB_EXPORT rc_t CC aspera_get(
    const char *ascp_bin, const char *private_file, const char *src,
    const char *dest, AscpOptions *opt)
{
    AscpOptions dummy;
    bool status = false;
    uint64_t prev = 0;
    int attempt = 0;
    KDirectory *dir = NULL;
    TQuitting *quitting = NULL;
    rc_t rc = KDirectoryNativeDir(&dir);
    if (rc != 0) {
        return rc;
    }
    if (ascp_bin == NULL || private_file == NULL ||
        src == NULL || dest == NULL)
    {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    if (opt == NULL) {
        memset(&dummy, 0, sizeof dummy);
        opt = &dummy;
    }

    if (opt->target_rate == NULL) {
        KConfig *cfg = NULL;
        rc_t rc = KConfigMake(&cfg, NULL);
        DISP_RC(rc, "cannot KConfigMake");
        if (rc == 0) {
            rc = _KConfigGetAscpRate(cfg, &opt->target_rate);
            DISP_RC(rc, "cannot get aspera max rate");
        }
        RELEASE(KConfig, cfg);
    }

    sStatus = status = opt->status;
    quitting = opt->quitting;

    while (true) {
        rc = run_ascp(ascp_bin, private_file, src, dest, opt);
        if (rc == 0) {
            if (status) {
                STSMSG(STS_DBG, ("ascp finished with success"));
            }
            break;
        }
        else if (rc == SILENT_RC(rcExe,
            rcProcess, rcExecuting, rcMemory, rcExhausted))
        {
            if (status) {
                STSMSG(STS_DBG, ("ascp failed: %R", rc));
            }
            break;
        }
        else {
            rc_t rc = 0;
            uint64_t size = 0;
            if (quitting != NULL) {
                rc = quitting();
                if (rc != 0) {
                    break;
                }
            }
            if (status) {
                STSMSG(STS_DBG, ("ascp failed: %R", rc));
            }
            rc = KDirectoryFileSize(dir, &size, dest);
            if (rc != 0 || size < prev) {
            if (status) {
STSMSG(0, ("KDirectoryFileSize after ascp run: "
"rc = %ld, size = %ld", rc, size));
            }
                break;
            }
            else if (size > prev) {
                if (status) {
                    STSMSG(STS_INFO, ("  fasp download failed. %ld bytes "
                        "received so far. Retrying...", size));
                }
                attempt = 0;
                prev = size;
            } else {
                if (attempt++ > 3) {
                    break;
                }
                if (status) {
                    STSMSG(STS_INFO, ("  fasp download failed. %ld bytes "
                        "received so far. Retrying %d...", size, attempt));
                }
            }
        }
    }
    RELEASE(KDirectory, dir);
    return rc;
}
Esempio n. 15
0
static rc_t get_cache_path_from_repo_mgr( tool_options * options )
{
    KConfig * cfg;
    rc_t rc = KConfigMake ( &cfg, NULL );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "KConfigMake() failed in $(func)", "func=%s", __func__ ) );
    }
    else
    {
        const KRepositoryMgr *repo_mgr;
        rc = KConfigMakeRepositoryMgrRead ( cfg, &repo_mgr );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc,
                     "KConfigMakeRepositoryMgrRead() failed in $(func)", "func=%s", __func__ ) );
        }
        else
        {
            KRepositoryVector repos;
            VectorInit ( &repos, 0, 5 );
            rc = KRepositoryMgrUserRepositories ( repo_mgr, &repos );
            if ( rc != 0 )
            {
                rc = 0; /* we do not have a user-repository, but that is OK, the caller will display the lack of it ... */
            }
            else
            {
                uint32_t idx;
                for ( idx = 0; idx < VectorLength( &repos ) && rc == 0; ++idx )
                {
                    const KRepository *repo = VectorGet( &repos, idx );
                    if ( repo != 0 )
                    {
                        char path[ 4096 ];
                        rc = KRepositoryRoot ( repo, path, sizeof path, NULL );
                        if ( rc != 0 )
                        {
                            PLOGERR( klogErr, ( klogErr, rc,
                                     "KRepositoryRoot( for repo # $(idx) ) failed in $(func)", "idx=%u,func=%s", idx, __func__ ) );
                        }
                        else
                        {
                            bool add = true;
                            if ( options->user_repo_name != NULL )
                            {
                                char name[ 1024 ];
                                rc = KRepositoryName ( repo, name, sizeof name, NULL );
                                if ( rc != 0 )
                                {
                                    PLOGERR( klogErr, ( klogErr, rc,
                                             "KRepositoryName( for repo # $(idx) ) failed in $(func)", "idx=%u,func=%s", idx, __func__ ) );
                                }
                                else
                                    add = string_cmp_1( options->user_repo_name, name );
                            }
                            if ( add )
                            {
                                rc = add_tool_options_path( options, path );
                                if ( options->detailed )
                                    KOutMsg( "source: %s\n", path );
                            }
                        }
                    }
                }
                {
                    rc_t rc2 = KRepositoryVectorWhack ( &repos );
                    if ( rc2 != 0 )
                    {
                        PLOGERR( klogErr, ( klogErr, rc2,
                                 "KRepositoryVectorWhack() failed in $(func)", "func=%s", __func__ ) );
                    }
                }
            }
            {
                rc_t rc2 = KRepositoryMgrRelease ( repo_mgr );
                if ( rc2 != 0 )
                {
                    PLOGERR( klogErr, ( klogErr, rc2,
                             "KRepositoryMgrRelease() failed in $(func)", "func=%s", __func__ ) );
                }
            }
        }
        {
            rc_t rc2 = KConfigRelease ( cfg );
            if ( rc2 != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc2,
                         "KConfigRelease() failed in $(func)", "func=%s", __func__ ) );
            }
        }
    }
    return rc;
}
Esempio n. 16
0
static rc_t perform( tool_options * options, Args * args )
{
    visit_ctx octx;
    rc_t rc2, rc = KDirectoryNativeDir( &octx.dir );
    if ( rc != 0 )
    {
        PLOGERR( klogErr, ( klogErr, rc,
                 "KDirectoryNativeDir() failed in $(func)", "func=%s", __func__ ) );
    }
    else
    {
        rc = KConfigMake ( &octx.cfg, NULL );
        if ( rc != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc,
                     "KConfigMake() failed in $(func)", "func=%s", __func__ ) );
        }
        else
        {
            rc = KConfigMakeRepositoryMgrRead ( octx.cfg, &octx.repo_mgr );
            if ( rc != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc,
                         "KConfigMakeRepositoryMgrRead() failed in $(func)", "func=%s", __func__ ) );
            }
            else
            {
                octx.options = options;
                octx.data = NULL;
                switch( options->main_function )
                {
                    case tf_report  : rc = perform_report( &octx ); break;
                    case tf_rreport : rc = perform_rreport( &octx ); break;
                    case tf_unlock  : rc = perform_unlock( &octx ); break;
                    case tf_clear   : rc = perform_clear( &octx ); break;
                    case tf_enable  : rc = perform_set_disable( &octx, false ); break;
                    case tf_disable : rc = perform_set_disable( &octx, true ); break;
                    case tf_unknown : rc = Usage( args ); break;
                }

                rc2 = KRepositoryMgrRelease ( octx.repo_mgr );
                if ( rc2 != 0 )
                {
                    PLOGERR( klogErr, ( klogErr, rc2,
                             "KRepositoryMgrRelease() failed in $(func)", "func=%s", __func__ ) );
                }
            }

            rc2 = KConfigRelease ( octx.cfg );
            if ( rc2 != 0 )
            {
                PLOGERR( klogErr, ( klogErr, rc2,
                         "KConfigRelease() failed in $(func)", "func=%s", __func__ ) );
            }
        }

        rc2 = KDirectoryRelease( octx.dir );
        if ( rc2 != 0 )
        {
            PLOGERR( klogErr, ( klogErr, rc2,
                     "KDirectoryRelease() failed in $(func)", "func=%s", __func__ ) );
        }
    }
    return rc;
}