Exemplo n.º 1
0
static rc_t CC visitor(const KDirectory* dir,
    uint32_t type, const char* name, void* data)
{
    rc_t rc = 0;
    Total* total = (Total*) data;
    if (type & kptAlias)
    {   return rc; }
    assert(total);
    switch (type) {
        case kptFile: {
            uint64_t size = 0;
            rc = KDirectoryFileSize(dir, &size, "%s", name);
            if (rc == 0) {
                total->sz += size;
            }
            ++total->files;
            break;
        }
        case kptDir: 
            rc = KDirectoryVisit(dir, false, visitor, total, "%s", name);
            break;
        default:
            rc = RC(rcVDB, rcDirectory, rcVisiting, rcType, rcUnexpected);
            break;
    }
    return rc;
}
Exemplo n.º 2
0
/* you cannot addref to this dir object cause it's created on stack silently */
static
rc_t CC DirVisitor(const KDirectory *dir, uint32_t type, const char *name, void *data)
{
    rc_t rc = 0;
    DirVisit_Data* d = (DirVisit_Data*)data;

    if( (type & ~kptAlias) == kptFile ) {
        if (strcmp(&name[strlen(name) - 4], ".tsv") == 0 ||
            strcmp(&name[strlen(name) - 8], ".tsv.bz2") == 0 ||
            strcmp(&name[strlen(name) - 7], ".tsv.gz") == 0)
        {
            char buf[4096];
            const CGLoaderFile* file;
            FGroupKey key;
            if( (rc = KDirectoryResolvePath(dir, true, buf, sizeof(buf), name)) == 0 &&
                (rc = CGLoaderFile_Make(&file, d->dir, buf, NULL, !d->param->no_read_ahead)) == 0 &&
                (rc = FGroupKey_Make(&key, file, d->param)) == 0 ) {

                FGroupMAP* found = (FGroupMAP*)BSTreeFind(d->tree, &key, FGroupMAP_Cmp);
                DEBUG_MSG(5, ("file %s recognized\n", name));
                if( found != NULL ) {
                    rc = FGroupMAP_Set(found, file);
                } else {
                    FGroupMAP* x = calloc(1, sizeof(*x));
                    if( x == NULL ) {
                        rc = RC(rcExe, rcFile, rcInserting, rcMemory, rcExhausted);
                    } else {
                        memcpy(&x->key, &key, sizeof(key));
                        if( (rc = FGroupMAP_Set(x, file)) == 0 ) {
                            rc = BSTreeInsertUnique(d->tree, &x->dad, NULL, FGroupMAP_Sort);
                        }
                    }
                }
            } else if( GetRCObject(rc) == rcItem && GetRCState(rc) == rcIgnored ) {
                DEBUG_MSG(5, ("file %s ignored\n", name));
                rc = CGLoaderFile_Release(file, true);
                file = NULL;
            }
            if( rc != 0 && file != NULL ) {
                CGLoaderFile_LOG(file, klogErr, rc, NULL, NULL);
                CGLoaderFile_Release(file, true);
            }
        } else if( strcmp(&name[strlen(name) - 4], ".tar") == 0 ) {
            const KDirectory* tmp = d->dir;
            if( (rc = KDirectoryOpenArcDirRead(dir, &d->dir, true, name, tocKFile, KArcParseTAR, NULL, NULL)) == 0 ) {
                rc = KDirectoryVisit(d->dir, true, DirVisitor, d, ".");
                KDirectoryRelease(d->dir);
            }
            d->dir = tmp;
        }
    }
    return rc;
}
Exemplo n.º 3
0
static rc_t ReportDir(const ReportFuncs *f, uint32_t indent, const KTable* tbl) {
    rc_t rc = 0;
    const KDirectory* dir = NULL;
    if (tbl == NULL) {
        report(indent, "Error", 1, "KTable" , 's', "NULL");
        return rc;
    }
    rc = KTableOpenDirectoryRead(tbl, &dir);
    if (rc != 0) {
        reportError(indent, rc, "KTableOpenDirectoryRead");
    }
    else {
        Total total;
        memset(&total, 0, sizeof total);
        rc = KDirectoryVisit(dir, false, visitor, &total, NULL);
        report(indent, "Directory", 2,
            "size", 'l', total.sz, "files", 'l', total.files);
    }
    RELEASE(KDirectory, dir);
    return rc;
}
Exemplo n.º 4
0
static
void CC KDlsetVisitDir ( const KDirectory *dir, void *data )
{
    KDirectoryVisit ( dir, false, KDlsetTryLib, data, "." );
}
Exemplo n.º 5
0
static rc_t Load( SParam* param )
{
    rc_t rc = 0, rc1 = 0;
    BSTree slides, evidence;
    

    param->map_dir = NULL;
    param->asm_dir = NULL;
    param->output_dir = ( KDirectory * )param->input_dir;
    BSTreeInit( &slides );
    BSTreeInit( &evidence );

    rc = open_dir_or_tar( param->input_dir, &param->map_dir, param->map_path );
    if ( rc == 0 )
    {
        DirVisit_Data dv;

        dv.param = param;
        dv.tree = &slides;
        dv.dir = param->map_dir;
        rc = KDirectoryVisit( param->map_dir, true, DirVisitor, &dv, NULL );
        if ( rc == 0 )
        {
            if ( param->asm_path != NULL )
            {
                rc_t rc2 = open_dir_or_tar( param->input_dir, &param->asm_dir, param->asm_path );
                if ( rc2 == 0 )
                {
                    dv.tree = &evidence;
                    dv.dir = param->asm_dir;
                    rc = KDirectoryVisit( param->asm_dir, true, DirVisitor, &dv, NULL );
                }
            }
            if ( rc == 0 )
            {
                /* SHOULD HAVE A BSTreeEmpty FUNCTION OR SOMETHING...
                   MAKE ONE HERE - WITH KNOWLEDGE THAT TREE IS NOT NULL: */
#ifndef BSTreeEmpty
#define BSTreeEmpty( bst ) \
    ( ( bst ) -> root == NULL )
#endif
                if ( BSTreeEmpty ( & slides ) && BSTreeEmpty ( & evidence ) )
                    rc = RC( rcExe, rcFile, rcReading, rcData, rcInsufficient );
                else
                {
                    /* CORRECTED SETTING OF "rc" IN "FGroupMAP_Validate" */
                    assert ( rc == 0 );
                    BSTreeForEach( &slides, false, FGroupMAP_Validate, &rc );
                    BSTreeForEach( &evidence, false, FGroupMAP_Validate, &rc );
                }

                if ( rc == 0 )
                {
                    FGroupMAP_LoadData data;

                    PLOGMSG( klogInfo, ( klogInfo, "file set validation complete", "severity=status" ) );
                    memset( &data, 0, sizeof( data ) );
                    data.rc = 0;
                    data.param = param;
                    data.reads = &slides;
                    rc = DB_Init( param, &data.db );
                    if ( rc == 0 )
                    {
                        BSTreeDoUntil( &slides, false, FGroupMAP_LoadReads, &data );
                        rc = data.rc;
                        if ( rc == 0 )
                        {
                            PLOGMSG( klogInfo, ( klogInfo, "MAP loaded", "severity=status" ) );
                            BSTreeDoUntil( &evidence, false, FGroupMAP_LoadEvidence, &data );
                            rc = data.rc;
                            if ( rc == 0 )
                                PLOGMSG( klogInfo, ( klogInfo, "ASM loaded", "severity=status" ) );
                        }
                    }
                    rc1 = DB_Fini( param, &data.db, rc != 0 );
                    if ( rc == 0 )
                        rc = rc1;
                }
            }
        }

        /* copy the extra library ( file or recursive directory ) */
        if ( rc == 0 && param->library != NULL )
        {
            const KDirectory *lib_src;
            rc = open_dir_or_tar( param->input_dir, &lib_src, param->library );
            if ( rc == 0 )
            {
                rc = copy_library( param->input_dir, param->output_dir,
                                   param->library, param->out );
                if ( rc == 0 )
                    STSMSG( 0, ( "extra lib copied" ) );
                else
                    LOGERR( klogErr, rc, "failed to copy extra library" );
                KDirectoryRelease( lib_src );
            }
/*
            else
            {
                rc = copy_library( param->input_dir, param->output_dir,
                                   ".", param->out );
                if ( rc == 0 )
                    STSMSG( 0, ( "extra lib copied" ) );
                else
                    LOGERR( klogErr, rc, "failed to copy extra library" );
            }
*/
        }
        KDirectoryRelease( param->map_dir );
        KDirectoryRelease( param->asm_dir );
    }
    BSTreeWhack( &slides, FGroupMAP_Whack, NULL );
    BSTreeWhack( &evidence, FGroupMAP_Whack, NULL );
    return rc;
}
Exemplo n.º 6
0
int KDBPathTypeDir (const KDirectory * dir, int type, bool * pHasZombies, const char * path)
{
    const char * leaf, * parent;
    uint32_t bits;
    rc_t rc;

    bits = 0;

    assert ((type == kptDir) || (type == (kptDir|kptAlias)));

    rc = KDirectoryVisit ( dir, false, scan_dbdir, & bits, "%s", path );
    if ( rc == 0 ) do
    {
        if ( ( bits & scan_zombie ) != 0 ) {
            bits &= ~scan_zombie;
            if (pHasZombies)
                *pHasZombies = true;
        }
        /* look for a column */
        if ( ( bits & scan_idxN ) != 0 &&
             ( bits & ( scan_data | scan_dataN ) ) != 0 )
        {
            if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                type += kptColumn - kptDir;
            break;
        }

        /* look for a table */
        if ( ( bits & scan_col ) != 0 )
        {
            /* can't have sub-tables or a db */
            if ( ( bits & ( scan_db | scan_tbl ) ) == 0 )
            {
                /* look for an old-structure table */
                if ( ( bits & ( scan_meta | scan_md ) ) == scan_meta ||
                     ( bits & ( scan_skey | scan_idx ) ) == scan_skey )
                    type += kptPrereleaseTbl - kptDir;
                else
                    type += kptTable - kptDir;
            }
            break;
        }

        /* look for metadata */
        if ( ( bits & ( scan_cur | scan_rNNN ) ) != 0 )
        {
            if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                type += kptMetadata - kptDir;
            break;
        }

        /* look for a database */
        if ( ( bits & scan_tbl ) != 0 )
        {
            if ( ( bits & scan_col ) == 0 )
                type += kptDatabase - kptDir;
            break;
        }

        /* look for a structured column */
        if ( ( bits & scan_odir ) != 0 )
        {
            leaf = strrchr ( path, '/' );
            if ( leaf != NULL )
            {
                parent = string_rchr ( path, leaf - path, '/' );
                if ( parent ++ == NULL )
                    parent = path;
                if ( memcmp ( parent, "col/", 4 ) != 0 )
                    break;

                bits = 0;
                if ( KDirectoryVisit ( dir, 1, scan_dbdir, & bits, "%s", path ) == 0 )
                {
                    if ( ( bits & scan_idxN ) != 0 &&
                         ( bits & ( scan_data | scan_dataN ) ) != 0 )
                    {
                        if ( ( bits & ( scan_db | scan_tbl | scan_idx | scan_col ) ) == 0 )
                            type += kptColumn - kptDir;
                        break;
                    }
                }
            }
        }
    } while (0);

    return type;
}