Exemple #1
0
static rc_t resolve_accession( VFSManager * vfs_mgr, const char * accession, const String ** path )
{
    VResolver * resolver;
    rc_t rc = VFSManagerGetResolver( vfs_mgr, &resolver );
    if ( rc == 0 )
    {
        const VPath * vpath;
        rc = VPathMakeSysPath( ( VPath** )&vpath, accession );
        if ( rc == 0 )
        {
            const VPath * rpath;
            rc = VResolverLocal( resolver, vpath, &rpath );
            if ( GetRCState( rc ) == rcNotFound )
                rc = VResolverRemote( resolver, vpath, &rpath, NULL );
            if ( rc == 0 )
            {
                const String * s;
                rc = VPathMakeString( rpath, &s );
                if ( rc == 0 )
                {
                    rc = StringCopy ( path, s );
                    free ((void*)s);
                }
                VPathRelease ( rpath );
            }
            VPathRelease ( vpath );
        }
        VResolverRelease( resolver );
    }
    return rc;
}
Exemple #2
0
static rc_t resolve_accession( VFSManager * vfs_mgr, const char * acc, const String ** resolved )
{
    VResolver * resolver;
    rc_t rc = VFSManagerGetResolver( vfs_mgr, &resolver );
    if ( rc != 0 )
    {
        (void)LOGERR( klogErr, rc, "VFSManagerGetResolver() failed" );
    }
    else
    {
        VPath * acc_vpath;
        rc = VFSManagerMakePath( vfs_mgr, &acc_vpath, "ncbi-acc:%s", acc );
        if ( rc != 0 )
        {
            (void)LOGERR( klogErr, rc, "VFSManagerMakePath() failed" );
        }
        else
        {
            const VPath * local = NULL;
            const VPath * remote = NULL;
            rc = VResolverQuery ( resolver, 0, acc_vpath, &local, &remote, NULL );
            if ( rc != 0 )
            {
                (void)LOGERR( klogErr, rc, "VResolverQuery() failed" );
            }
            else
            {
                if ( local != NULL )
                    rc = VPathMakeString( local, resolved );
                else if ( remote != NULL )
                    rc = VPathMakeString( remote, resolved );
                else
                    rc = KOutMsg( "cannot resolve '%s'\n", acc );

                if ( local != NULL ) VPathRelease ( local );
                if ( remote != NULL ) VPathRelease ( remote );
            }
            VPathRelease ( acc_vpath );
        }
        VResolverRelease( resolver );
    }
    return rc;
}
Exemple #3
0
/* Whack
 *  will not refuse request, and ignores errors
 */
static
rc_t SRAMgrWhack ( const SRAMgr *that )
{
    SRAMgr *self = ( SRAMgr* ) that;

    VSchemaRelease ( self -> schema );
    VDBManagerRelease ( self -> vmgr );

    /* must check here for NULL because
       SRAPathRelease is weak-linked */
    if ( self -> _pmgr != NULL )
    {
#if OLD_SRAPATH_MGR
        SRAPathRelease ( self -> _pmgr );
#else
        VResolverRelease ( ( const VResolver* ) self -> _pmgr );
#endif
    }

    free ( self );
    return 0;
}
Exemple #4
0
/* KMain
 */
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 0);
    if (rc)
        LOGERR (klogInt, rc, "failed to parse arguments");
    else do
    {
        uint32_t acount;
        rc = ArgsParamCount (args, &acount);
        if (rc)
        {
            LOGERR (klogInt, rc, "failed to count parameters");
            break;
        }

        if (acount == 0)
        {
            rc = MiniUsage (args);
            break;
        }
        else
        {
            VFSManager* mgr;
            rc = VFSManagerMake(&mgr);
            if (rc)
                LOGERR ( klogErr, rc, "failed to create VFSManager object" );
            else
            {
                VResolver * resolver;

                rc = VFSManagerGetResolver (mgr, &resolver);
                if (rc == 0)
                {
                    uint32_t ix;
                    for ( ix = 0; ix < acount; ++ ix )
                    {
                        const char * pc;
                        rc = ArgsParamValue (args, ix, &pc );
                        if (rc)
                            LOGERR (klogInt, rc,
                                    "failed to retrieve parameter value");
                        else
                        {
                            const VPath * upath = NULL;
                            rc = VFSManagerMakePath ( mgr, (VPath**)&upath, "%s", pc);
                            if (rc == 0)
                            {
                                const VPath * local;
                                const VPath * remote;

                                rc = VResolverQuery (resolver, eProtocolHttp, upath, &local, &remote, NULL);

                                if (rc == 0)
                                {
                                    const String * s;

                                    if (local != NULL)
                                        rc = VPathMakeString (local, &s);
                                    else 
                                        rc = VPathMakeString (remote, &s);
                                    if (rc == 0)
                                    {
                                        OUTMSG (("%S\n", s));
                                        free ((void*)s);
                                    }
                                    VPathRelease (local);
                                    VPathRelease (remote);
                                }
                                else
                                {
                                    KDirectory * cwd;
                                    rc_t orc = VFSManagerGetCWD (mgr, &cwd);
                                    if (orc == 0)
                                    {
                                        KPathType kpt
                                            = KDirectoryPathType(cwd, "%s", pc);
                                        switch (kpt &= ~kptAlias)
                                        {
                                        case kptNotFound:
                                            STSMSG(1, ("'%s': not found while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        case kptBadPath:
                                            STSMSG(1, ("'%s': bad path while "
                                                "searching the file system",
                                                pc));
                                            break;
                                        default:
                                            STSMSG(1, ("'%s': "
                                                "found in the file system",
                                                pc));
                                            rc = 0;
                                            break;
                                        }
                                    }
                                    if (orc == 0 && rc == 0) {
                                        if (rc != 0) {
                                            PLOGMSG(klogErr, (klogErr,
                                                              "'$(name)': not found",
                                                              "name=%s", pc));
                                        }
                                        else {
                                            char resolved[PATH_MAX] = "";
                                            rc = KDirectoryResolvePath(cwd, true,
                                                                       resolved, sizeof resolved, "%s", pc);
                                            if (rc == 0) {
                                                STSMSG(1, ("'%s': found in "
                                                           "the current directory at '%s'",
                                                           pc, resolved));
                                                OUTMSG (("%s\n", resolved));
                                            }
                                            else {
                                                STSMSG(1, ("'%s': cannot resolve "
                                                           "in the current directory",
                                                           pc));
                                                OUTMSG (("./%s\n", pc));
                                            }
                                        }
                                    }
                                    KDirectoryRelease(cwd);
                                }
                            }

                            RELEASE(VPath, upath);
                        }
                    }
                    VResolverRelease (resolver);
                }
                VFSManagerRelease(mgr);
            }
        }
        ArgsWhack (args);

    } while (0);

    return rc;
}