示例#1
0
文件: reref.c 项目: mariux/sratoolkit
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;
}
示例#2
0
文件: reref.c 项目: ncbi/sra-tools
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;
}
示例#3
0
static
rc_t KDatabaseMakeVPath ( KDatabase **dbp, const KDirectory *dir,
    const VPath *path, KMD5SumFmt *md5, bool read_only )
{
    const String* dbpathStr;
    rc_t rc = VPathMakeString ( path, &dbpathStr );    /* NUL-terminated */
    if ( rc == 0 )
    {
        rc = KDatabaseMake ( dbp, dir, dbpathStr->addr, md5, read_only );
        StringWhack(dbpathStr);
    }
    return rc;
}
示例#4
0
string CVPath::ToString(EType type) const
{
    const String* str = 0;
    if (type == eSys) {
        if (rc_t rc = VPathMakeSysPath(*this, &str)) {
            NCBI_THROW2(CSraException, eOtherError,
                "Cannot get path from VPath", rc);
        }
    }
    else {
        if (rc_t rc = VPathMakeString(*this, &str)) {
            NCBI_THROW2(CSraException, eOtherError,
                "Cannot get path from VPath", rc);
        }
    }
    string ret(str->addr, str->size);
    StringWhack(str);
    return ret;
}
示例#5
0
FIXTURE_TEST_CASE(Test1YesDep, RefseqFixture) {
    if (siteless) {
        TEST_MESSAGE("Test skipped because site repository does not exist");
        return;
    }

    rc_t rc = 0;

    const VDatabase *db = NULL;
    const char SRR619505[] = "SRR619505";
    REQUIRE_RC(VDBManagerOpenDBRead(mgr, &db, NULL, SRR619505));
    RELEASE(VDatabase, db);

    VPath* acc = NULL;
    REQUIRE_RC(VFSManagerMakePath(vmgr, &acc, SRR619505));
    const VPath *local = NULL;
    REQUIRE_RC(VResolverLocal(resolver, acc, &local));
    RELEASE(VPath, acc);
    const String *s = NULL;
    REQUIRE_RC(VPathMakeString(local, &s));
    REQUIRE(s && s->addr);

    REQUIRE_RC(VDBManagerOpenDBRead(mgr, &db, NULL, s->addr));

    const VDBDependencies *dep = NULL;

    //                                             missing
    REQUIRE_RC(VDatabaseListDependencies(db, &dep, true));
    uint32_t count = 1;
    REQUIRE_RC(VDBDependenciesCount(dep, &count));
    CHECK_EQUAL(count, (uint32_t)0);
    RELEASE(VDBDependencies, dep);

    REQUIRE_RC(VDatabaseListDependencies(db, &dep, false));
    REQUIRE_RC(VDBDependenciesCount(dep, &count));
    CHECK_EQUAL(count, (uint32_t)1);
    RELEASE(VDBDependencies, dep);

    RELEASE(VDatabase, db);
    free(const_cast<String*>(s));
    RELEASE(VPath, local);
}
示例#6
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;
}
示例#7
0
文件: services.c 项目: ncbi/sra-tools
static
rc_t KSrvResponse_Print ( const KSrvResponse * self, bool cache, bool pPath )
{
    rc_t rc = 0;
    rc_t re = 0;
    uint32_t i = 0;
    uint32_t l = KSrvResponseLength  ( self );

    if ( ! pPath )
        OUTMSG ( ( "%u #\n\n", l ) );

    for ( i = 0; i < l; ++ i ) {
        bool printed = false;
        int j = 0;
        if ( ! pPath )
            OUTMSG ( ( "#%u {", i ) );
        for ( j = 0; j < sizeof PROTOCOLS / sizeof PROTOCOLS [ 0 ];
              ++ j )
        {
            const TProtocol * p = & PROTOCOLS [ j ];
            const VPath * path = NULL;
            const VPath * vdbcache = NULL;
            const KSrvError * error = NULL;
            rc_t r2 = KSrvResponseGetPath ( self,
                i, p -> p, & path, & vdbcache, & error );
            if ( r2 != 0 )
                PLOGERR ( klogErr, ( klogErr, r2, "Cannot get response path"
                    "($(i), $(s))", "i=%u,s=%s", i, p -> n ) );
            else {
                if ( ! ( pPath || printed ) )
                    printed = printCommon ( path, error );
                if ( error != NULL ) {
                    rc_t r = 0;
                    KSrvErrorRc ( error, & r );
                    assert ( r );
                    if ( re == 0 )
                        re = r;
                }
                if ( path != NULL ) {
                    const String * tmp = NULL;
                    r2 = VPathMakeString ( path, & tmp );
                    if ( ! pPath || r2 != 0 )
                        OUTMSG ( ( "\n\t%s: ", p -> n ) );
                    if ( r2 == 0 )
                        if ( pPath ) {
                            if ( printed )
                                OUTMSG ( ( "\n" ) );
                            OUTMSG ( ( "%S", tmp ) );
                            printed = true;
                        }
                        else
                            OUTMSG ( ( "path=\"%S\"", tmp ) );
                    else
                        OUTMSG ( ( "%R", r2 ) );
                    free ( ( void * ) tmp );
                }
                if ( vdbcache != NULL ) {
                    const String * tmp = NULL;
                    r2 = VPathMakeString ( vdbcache, & tmp );
                    if ( r2 == 0 )
                        if ( pPath )
                            OUTMSG ( ( "\n%S", tmp ) );
                        else
                            OUTMSG ( ( " vdbcache=\"%S\"", tmp ) );
                    else
                        OUTMSG ( ( "%R", r2 ) );
                    free ( ( void * ) tmp );
                }
            }
            RELEASE ( VPath, path );
            RELEASE ( VPath, vdbcache );
            if ( error != NULL ) {
                RELEASE ( KSrvError, error );
                break;
            }
        }

        if ( cache & ! pPath ) {
            const VPath * cache = NULL;
            rc_t r2 = KSrvResponseGetCache ( self, i, & cache );
            OUTMSG ( ( "\n     Cache=" ) );
            if ( r2 != 0 )
                OUTMSG ( ( "%R\n", r2 ) );
            else {
                const String * tmp = NULL;
                r2 = VPathMakeString ( cache, & tmp );
                if ( r2 == 0 )
                    OUTMSG ( ( "\"%S\"\n", tmp ) );
                else
                    OUTMSG ( ( "\"%R\"\n", r2 ) );
                free ( ( void * ) tmp );
            }
            RELEASE ( VPath, cache );
        }

        if ( ! pPath )
            OUTMSG ( ( " }" ) );
        OUTMSG ( ( "\n" ) );
    }

    if ( rc == 0 && re != 0 )
        rc = re;
    return rc;
}