Exemple #1
0
static rc_t AppCtxInit(rc_t rc, AppCtx* ctx) {
    assert(ctx);
    memset(ctx, 0 , sizeof *ctx);
    if (rc) {
        return rc;
    }
    if (rc == 0) {
        rc = SRAMgrMakeUpdate(&ctx->s_mgr, NULL);
        DISP_RC(rc, "while calling SRAMgrMakeUpdate");
    }
    if (rc == 0) {
        rc = KXMLMgrMakeRead(&ctx->x_mgr);
        DISP_RC(rc, "while calling KXMLMgrMakeRead");
    }
    if (rc == 0) {
        rc = KDirectoryNativeDir(&ctx->dir);
        DISP_RC(rc, "while calling KDirectoryNativeDir");
    }
    return rc;
}
Exemple #2
0
static rc_t SDataInit(struct SData* self,
    const char* tablePath, const SRAMgr* rdMgr, rc_t rc)
{
    SRAMgr* wrMgr = NULL;

    assert(self);
    memset(self, 0, sizeof *self);
    if (rc)
    {   return rc; }

    rc = SRAMgrMakeUpdate(&wrMgr, NULL);
    if (rc != 0) {
        logerr(klogErr, rc, "while calling SRAMgrMakeUpdate");
    }
    else {
        plogmsg(klogInfo,
            "Opening Table $(path) for read", "path=%s", tablePath);
        rc = SRAMgrOpenTableRead(rdMgr, &self->_rdTbl, "%s", tablePath);
        if (rc != 0) {
            plogerr(klogErr, rc,
                "cannot open table $(path) for read", "path=%s", tablePath);
        }
    }

    if (rc == 0) {
        plogmsg(klogInfo,
            "Opening Table $(path) for update", "path=%s", tablePath);
        rc = SRAMgrOpenTableUpdate(wrMgr, &self->_wrTbl, "%s", tablePath);
        if (rc != 0) {
            plogerr(klogErr, rc,
                "cannot open table $(path) for update", "path=%s", tablePath);
        }
    }

    SRAMgrRelease(wrMgr);

    return rc;
}
Exemple #3
0
rc_t KMain(int argc, char *argv[])
{
    rc_t rc = 0;
    Args* args = NULL;
    const char* errmsg = NULL, *table_dir = NULL;
    char accn[1024];
    
    if( (rc = ArgsMakeAndHandle(&args, argc, argv, 1, MainArgs, MainArgsQty)) == 0 ) {
        const char* blksz = NULL;
        uint32_t count, dump = 0, gzip = 0;

        if( (rc = ArgsParamCount(args, &count)) != 0 || count != 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, count > 1 ? rcExcessive : rcInsufficient);
            errmsg = "table";

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_BlockSize].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_BlockSize].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_BlockSize].name, 0, (const void **)&blksz)) != 0 ) {
            errmsg = MainArgs[eopt_BlockSize].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_Accession].name, &count)) != 0 || count > 1 ) {
            rc = rc ? rc : RC(rcExe, rcArgv, rcParsing, rcParam, rcExcessive);
            errmsg = MainArgs[eopt_Accession].name;
        } else if( count > 0 && (rc = ArgsOptionValue(args, MainArgs[eopt_Accession].name, 0, (const void **)&g_accession)) != 0 ) {
            errmsg = MainArgs[eopt_Accession].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_DumpIndex].name, &dump)) != 0 ) {
            errmsg = MainArgs[eopt_DumpIndex].name;

        } else if( (rc = ArgsOptionCount(args, MainArgs[eopt_noGzip].name, &gzip)) != 0 ) {
            errmsg = MainArgs[eopt_noGzip].name;
        }
        while( rc == 0 ) {
            long val = 0;
            char* end = NULL;

            if( blksz != NULL ) {
                errno = 0;
                val = strtol(blksz, &end, 10);
                if( errno != 0 || blksz == end || *end != '\0' || val <= 0 ) {
                    rc = RC(rcExe, rcArgv, rcReading, rcParam, rcInvalid);
                    errmsg = MainArgs[eopt_BlockSize].name;
                    break;
                } else if( val <= 128 || val > (1024 * 1024 * 1024) ) {
                    rc = RC(rcExe, rcArgv, rcValidating, rcParam, rcEmpty);
                    errmsg = "block size invalid";
                    break;
                }
                g_file_block_sz = val;
            }
            if( (rc = ArgsParamValue(args, 0, (const void **)&table_dir)) != 0 ) {
                errmsg = "table";
                break;
            }
            if( g_accession == NULL ) {
                const char* p = strchr(table_dir, '/');
                size_t l = 0;

                g_accession = accn;
                if( p == NULL ) {
                    p = strchr(table_dir, '\\');
                }
                strncpy(accn, p == NULL ? table_dir : p + 1, sizeof(accn) - 1);
                if( accn[0] == '\0' ) {
                    rc = RC(rcExe, rcArgv, rcValidating, rcParam, rcEmpty);
                    errmsg = "accession";
                }
                l = strlen(accn);
                if( accn[l - 1] == '/' || accn[l - 1] == '\\') {
                    accn[--l] = '\0';
                }
                if( strncmp(&accn[l - 9], ".lite.sra", 9) == 0 ) {
                    accn[l - 9] = '\0';
                } else if( strncmp(&accn[l - 4], ".sra", 4) == 0 ) {
                    accn[l - 4] = '\0';
                }
            }
            g_dump = dump > 0;
            g_ungzip = gzip > 0;
            break;
        }
    }
    if( rc == 0 ) {
        SRAMgr* smgr = NULL;
        KDBManager* kmgr = NULL;

        DEBUG_MSG(5, ("table %s, accession %s\n", table_dir, g_accession));
        if( (rc = SRAMgrMakeUpdate(&smgr, NULL)) == 0 ) {
            if( (rc = KDBManagerMakeUpdate(&kmgr, NULL)) == 0 ) {
                bool relock = true;
                if( (rc = KDBManagerUnlock(kmgr, table_dir)) != 0 ) {
                    relock = false;
                    rc = GetRCState(rc) == rcUnlocked ? 0 : rc;
                } else {
                    PLOGMSG(klogInfo, (klogInfo, "Table $(p) locked, unlocking", PLOG_S(p), table_dir));
                }
                if( rc == 0 ) {
                    KTable* ktbl = NULL;
                    if( (rc = KDBManagerOpenTableUpdate(kmgr, &ktbl, table_dir)) == 0 ) {
                        KMetadata* meta = NULL;
                        if( (rc = KTableOpenMetadataUpdate(ktbl, &meta)) == 0 ) {
                            const SRATable* stbl = NULL;
                            if( (rc = SRAMgrOpenTableRead(smgr, &stbl, table_dir)) == 0 ) {
                                rc = MakeIndexes(stbl, ktbl, meta);
                                SRATableRelease(stbl);
                            }
                        }
                        KMetadataRelease(meta);
                    }
                    KTableRelease(ktbl);
                }
                if( rc == 0 && relock ) {
                    rc = KDBManagerLock(kmgr, table_dir);
                }
                KDBManagerRelease(kmgr);
            }
            SRAMgrRelease(smgr);
        }
    }
    if( rc != 0 && rc != KLogLastErrorCode() ) {
        if( errmsg ) {
            Usage(args);
        }
        LOGERR(klogErr, rc, errmsg ? errmsg : "stop");
    }
    ArgsWhack(args);
    return rc;
}