Пример #1
0
/* AddSearchPath
 *  add a search path to loader for locating library files
 */
LIB_EXPORT rc_t CC KDyldVAddSearchPath ( KDyld *self, const char *path, va_list args )
{
    rc_t rc;
    if ( self == NULL )
        rc = RC ( rcFS, rcDylib, rcUpdating, rcSelf, rcNull );
    else
    {
        KDirectory *wd;
        rc = KDirectoryNativeDir ( & wd );
        if ( rc == 0 )
        {
            const KDirectory *dir;
            rc = KDirectoryVOpenDirRead ( wd, & dir, false, path, args );
            if ( rc == 0 )
            {
                rc = VectorAppend ( & self -> search, NULL, dir );
                if ( rc != 0 )
                    KDirectoryRelease ( dir );
            }

            KDirectoryRelease ( wd );
        }
    }
    return rc;
}
Пример #2
0
static rc_t KDBOpenPathTypeReadInt ( const KDBManager * mgr, const KDirectory * dir, const char * path,
                                     const KDirectory ** pdir, int * type,
                                     int pathtype, uint32_t rcobj, bool try_srapath )
{
    VFSManager * vmgr = mgr->vfsmgr;
    const KDirectory * ldir = NULL;
    rc_t rc = 0;

    /* object relative opens can be done using KFS - we hacked in VFS after all */
    if (! try_srapath)
    {
        rc = KDirectoryOpenDirUpdate ((KDirectory*)dir, (KDirectory**)pdir, false, path);
        if ((rc) && (GetRCState(rc) != rcNotFound))
            rc = KDirectoryOpenDirRead (dir, pdir, false, path);
    }
    else
    {
        VPath * vpath;

        /*
         * We've got to decide if the path coming in is a full or relative
         * path and if relative make it relative to dir or possibly its a srapath
         * accession
         *
         */
        rc = VPathMakeDirectoryRelative ( &vpath, dir, path );
        if ( rc == 0 )
        {
            rc = VFSManagerOpenDirectoryReadDirectoryRelativeDecrypt ( vmgr, dir, &ldir, vpath );

            if ( rc == 0 )
            {
                *type = (~kptAlias) & KDBPathType ( ldir, NULL, "." );

                /* just a directory, not a kdb type */
                if ( *type == kptDir )
                    rc = RC (rcDB, rcMgr, rcOpening, rcPath, rcIncorrect);

                else if ( *type != pathtype )
                {
                    KDirectoryRelease( ldir );
                    rc = RC ( rcDB, rcMgr, rcOpening, rcobj, rcIncorrect );
                }
                else
                {
                    if ( pdir != NULL )
                        *pdir = ldir;
                    else
                        KDirectoryRelease( ldir );
                }
            }
            VPathRelease ( vpath );
        }
    }
    return rc;
}
Пример #3
0
static rc_t copy2_main( Args * args )
{
    const char * source_path;
    rc_t rc = ArgsParamValue( args, 0, &source_path );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "ArgsParamValue( 0 ) failed" );
    else
    {
        const char * dest_path;
        rc = ArgsParamValue( args, 1, &dest_path );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ArgsParamValue( 1 ) failed" );
        else
        {
            KDirectory *dir, *dest_dir;
            const KDirectory *source_dir;
            rc = KDirectoryNativeDir ( &dir );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
            else
            {
                rc = KDirectoryOpenDirRead( dir, &source_dir, false,
                                            source_path );
                if ( rc != 0 )
                    LOGERR( klogInt, rc, "KDirectoryOpenDirRead() failed" );
                else
                {
                    rc = KDirectoryOpenDirUpdate( dir, &dest_dir, false,
                                            dest_path );
                    if ( rc != 0 )
                        LOGERR( klogInt, rc,
                                "KDirectoryOpenDirUpdate() failed" );
                    else
                    {
                        rc = KDirectoryCopy( source_dir, dest_dir, true,
                                             source_path, dest_path );
                        if ( rc != 0 )
                            LOGERR( klogInt, rc, "copy_dirs() failed" );
                        else
                            OUTMSG(( "copy successful!\n" ));
                        KDirectoryRelease ( dest_dir );
                    }
                    KDirectoryRelease ( source_dir );
                }
                KDirectoryRelease ( dir );
            }
        }
    }
    return rc;
}
Пример #4
0
static
void CCSraWhack (CCSra * self)
{
    rc_t rc, orc;
    rc = KDirectoryRelease (self->ndir);
    orc = KDirectoryRelease (self->adir);
    if (rc == 0)
        rc = orc;
    orc = KFileRelease (self->file);
    if (rc == 0)
        rc = orc;
    if (rc)
        LOGERR(klogWarn, rc, "error releaseing CCSra");
    free (self);
}
Пример #5
0
void txt2kdb_release (void)
{
    KDirectoryRelease (G.dir);
    KFileRelease (G.txt);
    KDBManagerRelease (G.mgr);
    KColumnRelease (G.col);
}
Пример #6
0
/* Whack
 */
static
rc_t KTableWhack ( KTable *self )
{
    rc_t rc = 0;

    KRefcountWhack ( & self -> refcount, "KTable" );

    if ( self -> db != NULL )
    {
        rc = KDatabaseSever ( self -> db );
        if ( rc == 0 )
            self -> db = NULL;
    }

    if ( rc == 0 )
        rc = KDBManagerSever ( self -> mgr );

    if ( rc == 0 )
    {
        KDirectoryRelease ( self -> dir );
        free ( self );
        return 0;
    }

    KRefcountInit ( & self -> refcount, 1, "KTable", "whack", "ktbl" );

    return rc;
}
Пример #7
0
struct rna_splice_log * make_rna_splice_log( const char * filename, const char * toolname )
{
    struct rna_splice_log * res = NULL;
    KDirectory * dir;
    rc_t rc = KDirectoryNativeDir ( &dir );
    if ( rc == 0 )
    {
        KFile * f;
        rc = KDirectoryCreateFile ( dir, &f, false, 0664, kcmInit, "%s", filename );
        if ( rc == 0 )
        {
            res = calloc( 1, sizeof * res );
            if ( res != NULL )
            {
                res->log_file = f;
                if ( toolname != NULL )
                    res->tool_name = string_dup_measure ( toolname, NULL );
            }
            else
                KFileRelease ( f );
        }
        KDirectoryRelease ( dir );
    }
    return res;
}
Пример #8
0
/* GetPathModDate
 *  extract mod date from a path
 */
rc_t KDBVGetPathModDate ( const KDirectory *dir,
    KTime_t *mtime, const char *path, va_list args )
{
    rc_t rc;
    uint32_t ptype;
    const KDirectory *obj_dir;

    va_list cpy;
    va_copy ( cpy, args );
    ptype = KDirectoryVPathType ( dir, path, cpy );
    va_end ( cpy );

    switch ( ptype )
    {
    case kptDir:
    case kptDir | kptAlias:
        break;

    default:
        return KDirectoryVDate ( dir, mtime, path, args );
    }

    * mtime = 0;
    rc = KDirectoryVOpenDirRead ( dir, & obj_dir, true, path, args );
    if ( rc == 0 )
    {
        rc = KDBGetObjModDate ( obj_dir, mtime );
        KDirectoryRelease ( obj_dir );
    }

    return rc;
}
Пример #9
0
LIB_EXPORT rc_t CC WriteNamelistToFileByName( const VNamelist * namelist, const char * filename,
        const char * delim )
{
    rc_t rc;
    if ( namelist == NULL || filename == NULL || delim == NULL )
        rc = RC( rcFS, rcFile, rcValidating, rcParam, rcNull );
    else
    {
        KDirectory * dir;
        rc = KDirectoryNativeDir ( &dir );
        if ( rc == 0 )
        {
            KFile * f;
            rc = KDirectoryCreateFile ( dir, &f, true, 0664, kcmCreate, filename );
            if ( rc == 0 )
            {
                if ( rc == 0 )
                    rc = SaveToFile( f, namelist, delim );
                KFileRelease ( f );
            }
            KDirectoryRelease ( dir );
        }
    }
    return rc;
}
Пример #10
0
LIB_EXPORT rc_t CC LoadFileByNameToNameList( VNamelist * namelist, const char * filename )
{
    rc_t rc;
    if ( namelist == NULL || filename == NULL )
        rc = RC( rcFS, rcFile, rcValidating, rcParam, rcNull );
    else
    {
        KDirectory * dir;
        rc = KDirectoryNativeDir ( &dir );
        if ( rc == 0 )
        {
            KFile const * f;
            rc = KDirectoryOpenFileRead ( dir, &f, "%s", filename );
            if ( rc == 0 )
            {
                if ( rc == 0 )
                    rc = LoadFromFile( f, namelist );
                KFileRelease ( f );
            }
            KDirectoryRelease ( dir );
        }
    }
    return rc;

}
Пример #11
0
static rc_t cg_dump_src_dst_rows_cur( cg_dump_opts * opts, cg_dump_ctx * cg_ctx )
{
    /* preparations */
    rc_t rc = cg_dump_prepare_seq_tab( cg_ctx );
/*
    if ( rc == 0 )
        rc = cg_dump_prepare_prim_tab( cg_ctx );
*/
    if ( rc == 0 )
        rc = cg_dump_adjust_rowrange( cg_ctx );
    if ( rc == 0 )
        rc = cg_dump_setup_progressbar( cg_ctx );
    if ( rc == 0 )
        rc = cg_dump_prepare_output( opts, cg_ctx );

    /* loop through the SEQUENCE-table */
    if ( rc == 0 )
    {
        rc = cg_dump_loop( opts, cg_ctx ); /* <================== */

        if ( cg_ctx->progress != NULL )
            destroy_progressbar( cg_ctx->progress );
        BSTreeWhack ( &cg_ctx->lanes, whack_lanes_nodes, NULL );
        KDirectoryRelease( cg_ctx->out_dir );
    }
    return rc;
}
Пример #12
0
static
rc_t CCSraInit (CCSra ** pself, CCTree * tree, const KFile * sf, const char * name)
{
    CCSra * self;
    rc_t rc;

    assert (pself);
    assert (sf);
    assert (name);

    self = malloc (sizeof (*self));
    if (self == NULL)
        rc = RC (rcExe, rcMemory, rcAllocating, rcMemory, rcExhausted);
    else
    {
        KFileAddRef (self->file = sf);

        rc = KDirectoryMakeSraNodeDir (&self->ndir, sf, name);
        if (rc == 0)
        {
            rc = KDirectoryOpenSraArchiveReadUnbounded (self->ndir, &self->adir, true, "%s", name);
            if (rc == 0)
            {
                self->tree = tree;
                *pself = self;
                return 0;
            }
            KDirectoryRelease (self->ndir);
        }
        free (self);
    }
    return rc; /* error out */
}
Пример #13
0
/* OpenColumnRead
 * VOpenColumnRead
 *  open a column for read
 *
 *  "col" [ OUT ] - return parameter for newly opened column
 *
 *  "path" [ IN ] - NUL terminated string in UTF-8 giving path to col
 *  where "." acts as a structure name separator, i.e. struct.member
 */
static
rc_t KDBManagerVOpenColumnReadInt ( const KDBManager *self,
    const KColumn **colp, const KDirectory *wd, bool try_srapath,
    const char *path, va_list args )
{
    char colpath [ 4096 ];
    rc_t rc;
    size_t z;

/*    rc = KDirectoryVResolvePath ( wd, 1,
        colpath, sizeof colpath, path, args ); */
    rc = string_vprintf( colpath, sizeof colpath, &z, path, args );
    if ( rc == 0 )
    {
        KColumn *col;
        const KDirectory *dir;

        /* open table directory */
        rc = KDBOpenPathTypeRead ( self, wd, colpath, &dir, kptColumn, NULL, try_srapath );
        if ( rc == 0 )
        {
            rc = KColumnMakeRead ( & col, dir, colpath );
            if ( rc == 0 )
            {
                col -> mgr = KDBManagerAttach ( self );
                * colp = col;
                return 0;
            }

            KDirectoryRelease ( dir );
        }
    }
    
    return rc;
}
Пример #14
0
/* OpenDBRead
 * VOpenDBRead
 *  open a database for read
 *
 *  "db" [ OUT ] - return parameter for newly opened database
 *
 *  "path" [ IN ] - NUL terminated string in
 *  wd-native character set giving path to database
 */
static
rc_t KDBManagerVOpenDBReadInt ( const KDBManager *self,
    const KDatabase **dbp, const KDirectory *wd,
    const char *path, va_list args )
{
    /* generate absolute path to db */
    char dbpath [ 4096 ];
    rc_t rc = KDirectoryVResolvePath ( wd, true,
        dbpath, sizeof dbpath, path, args );
    if ( rc == 0 )
    {
        KDatabase *db;
        const KDirectory *dir;

        /* open the directory if its a database */
        rc = KDBOpenPathTypeRead ( wd, dbpath, &dir, kptDatabase, NULL );
        if ( rc == 0 )
        {
            /* allocate a new guy */
            rc = KDatabaseMake ( & db, dir, dbpath );
            if ( rc == 0 )
            {
                db -> mgr = KDBManagerAttach ( self );
                * dbp = db;
                return 0;
            }

            KDirectoryRelease ( dir );
        }
    }
    
    return rc;
}
Пример #15
0
static rc_t SpotIteratorDestroy(struct SpotIterator* self)
{
    assert(self);
    KDirectoryRelease(__SpotIteratorDirectory);
    __SpotIteratorDirectory = NULL;
    return KFileRelease(self->m_file);
}
Пример #16
0
static
rc_t KDBManagerMakeDBUpdate ( KDBManager *self,
    KDatabase **dbp, KDirectory *wd, const char *path, KMD5SumFmt *md5 )
{
    rc_t rc;
    KDirectory *dir;

    rc = KDirectoryOpenDirUpdate ( wd, & dir, false, "%s", path );
    if ( rc == 0 )
    {
        KDatabase *db;
	    
        /* Make the base object */
        rc = KDatabaseMake ( & db, dir, path, md5, false );
        if ( rc == 0 )
        {
            rc = KDBManagerInsertDatabase ( self, db );

            if ( rc == 0 )
            {
                * dbp = db;
                return 0;   /* successful exit */
            }

            rc = RC ( rcDB, rcMgr, rcOpening, rcDatabase, rcBusy );
                
            free ( db );
        }
        KDirectoryRelease ( dir );
    }
    return rc;
}
Пример #17
0
rc_t KeyRingInit ( KKeyRing* self, const char* path )
{
    rc_t rc;
    
    memset ( self, 0, sizeof * self );
    KRefcountInit ( & self -> refcount, 0, "KKeyRing", "init", "" );
    
    rc = KDirectoryNativeDir(&self->wd);
    if (rc == 0)
    {
        self->path = string_dup(path, string_size(path));
        if (self->path)
        {
            self->data = (KeyRingData*) malloc(sizeof(*self->data));
            if (self->data)
            {
                rc = KeyRingDataInit ( self->data );
                if (rc != 0)
                    free(self->data);
            }
            else
                rc = RC ( rcApp, rcDatabase, rcOpening, rcMemory, rcExhausted );
                
            if (rc != 0)
                free(self->path);
        }
        else
            rc = RC ( rcApp, rcDatabase, rcOpening, rcMemory, rcExhausted );
            
        if (rc != 0)
            KDirectoryRelease(self->wd);
    }
        
    return rc;
}
Пример #18
0
rc_t vds_diff( const char * f1, const char * f2 )
{
    KDirectory * dir;
    rc_t rc = KDirectoryNativeDir( &dir );
    if ( rc != 0 )
		KOutMsg( "KDirectoryNativeDir() failed\n" );
    else
    {
		const KFile * kf1;
		rc = KDirectoryOpenFileRead ( dir, &kf1, "%s", f1 );
		if ( rc != 0 )
			KOutMsg( "cannot open file '%s'\n", f1 );
		else
		{
			const KFile * kf2;
			rc = KDirectoryOpenFileRead ( dir, &kf2, "%s", f2 );
			if ( rc != 0 )
				KOutMsg( "cannot open file '%s'\n", f2 );
			else
			{
				rc = vds_diff_files( kf1, kf2 );
				KFileRelease( kf2 );
			}
			KFileRelease( kf1 );
		}
		KDirectoryRelease( dir );
	}
	clear_recorded_errors();
	
	return rc;
}
Пример #19
0
int KDBPathType ( const KDirectory *dir, bool *pHasZombies, const char *path )
{
    const char *leaf, *parent;


    rc_t rc;
    int type = KDirectoryPathType ( dir, "%s", path );
    
    if (pHasZombies)
        *pHasZombies = false;

    switch ( type )
    {
    case kptDir:
    case kptDir | kptAlias:
        type = KDBPathTypeDir (dir, type, pHasZombies, path);
        break;

    case kptFile:
    case kptFile | kptAlias:
    {
        /* if we hit a file first try it as an archive */
        const KDirectory * ldir;

        rc = KDirectoryOpenSraArchiveRead_silent ( dir, &ldir, false, "%s", path );
#if SUPPORT_KDB_TAR
        if ( rc != 0 )
            rc = KDirectoryOpenTarArchiveRead_silent ( dir, &ldir, false, "%s", path );
#endif
        /* it was an archive so recur */
        if ( rc == 0 )
        {
            /* recheck this newly opened directory for KDB/KFS type */
            int type2;

            type2 = KDBPathType ( ldir, NULL, "." );
            if ((type2 != kptDir) || (type != (kptDir|kptAlias)))
                type = type2;

            KDirectoryRelease (ldir);
        }
        /* it was not an archive so see if it it's an idx file */
        else
        {
            leaf = strrchr ( path, '/' );
            if ( leaf != NULL )
            {
                parent = string_rchr ( path, leaf - path, '/' );
                if ( parent ++ == NULL )
                    parent = path;
                if ( memcmp ( parent, "idx/", 4 ) == 0 )
                    type += kptIndex - kptFile;
            }
        }
        break;
    }
    }
    return type;
}
Пример #20
0
static
rc_t CC KRemoveLockFileTaskWhack ( KRemoveLockFileTask *self )
{
    rc_t rc = KDirectoryRelease ( self -> dir );
    KTaskDestroy ( & self -> dad, "KRemoveLockFileTask" );
    free ( self );
    return rc;
}
Пример #21
0
rc_t CC KMain (int argc, char * argv[])
{
    rc_t rc = 0;
    KDirectory* wd;
    
    KLogLevelSet(klogInfo);
    LogMsg ( klogInfo, "KeyringServer: starting");

    rc = KDirectoryNativeDir (&wd);
    if (rc == 0)
    {
        KFile* lockedFile;
        const char* dataDir;
        
        char lockFileName[MAX_PATH];
        if (argc < 2 || argv[1] == NULL)
            dataDir = KeyRingDefaultDataDir;
        else
            dataDir = argv[1];
        rc = string_printf(lockFileName, sizeof(lockFileName)-1, NULL, "%s/keyring_lock", dataDir);
        if (rc == 0)
        {
            rc = KDirectoryCreateExclusiveAccessFile(wd, &lockedFile, true, 0600, kcmOpen, "%s", lockFileName);
            if (rc == 0)
            {
                KNSManager* mgr;
                rc = KNSManagerMake(&mgr);
                if (rc == 0)
                {
                    rc = string_printf(keyRingFileName, sizeof(keyRingFileName)-1, NULL, "%s/keyring", dataDir);
                    if (rc == 0)
                        rc = Server(mgr);
                    KNSManagerRelease(mgr);
                }
                else
                    LogErr(klogErr, rc, "KeyringServer: KNSManagerMake failed");
                KFileRelease(lockedFile); 
                LogMsg ( klogInfo, "KeyringServer: removing lock file.");
                KDirectoryRemove(wd, true, "%s", lockFileName);
            }
            else
            {   /*TODO: check for stale lock file*/
                LogMsg ( klogInfo, "KeyringServer: another instance appears to be running.");
                rc = 0;
            }
        }
        else
            LogErr ( klogErr, rc, "KeyringServer: failed to build the lock file name" );
        
        KDirectoryRelease(wd);
    }
    else
        LogErr(klogErr, rc, "KeyringServer: KDirectoryNativeDir failed");
    
    LogMsg ( klogInfo, "KeyringServer: finishing");
    
    return rc;
}
Пример #22
0
rc_t report_on_reference( Args * args, bool extended )
{
    uint32_t count;
    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        LOGERR( klogInt, rc, "ArgsParamCount() failed" );
    }
    else
    {
        KDirectory *dir; 
        rc = KDirectoryNativeDir( &dir );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
        }
        else
        {
            const VDBManager *vdb_mgr;
            rc = VDBManagerMakeRead ( &vdb_mgr, dir );
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
            }
            else
            {
                VFSManager * vfs_mgr;
                rc =  VFSManagerMake ( &vfs_mgr );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot make vfs-manager" );
                }
                else
                {
                    uint32_t idx;
                    for ( idx = 0; idx < count && rc == 0; ++idx )
                    {
                        const char *param = NULL;
                        rc = ArgsParamValue( args, idx, &param );
                        if ( rc != 0 )
                        {
                            LOGERR( klogInt, rc, "ArgsParamvalue() failed" );
                        }
                        else
                        {
                            /* rc value not used, because it can be something that has no references */
                            report_references( vdb_mgr, vfs_mgr, param, extended );
                        }
                    }
                    VFSManagerRelease ( vfs_mgr );
                }
                VDBManagerRelease( vdb_mgr );
            }
            KDirectoryRelease( dir );
        }
    }
    return rc;
}
Пример #23
0
static 
rc_t CC
_LoadKartScanPath ( struct XFSKartCollectionNode * Node )
{
    rc_t RCt;
    struct KDirectory * Directory;
    KNamelist * List;
    const char * Name;
    uint32_t Idx;
    uint32_t ListCount;

    RCt = 0;
    Directory = NULL;
    List = NULL;
    Name = NULL;
    Idx = 0;
    ListCount = 0;

    if ( Node == NULL ) {
        return XFS_RC ( rcNull );
    }

    if ( Node -> path == NULL ) {
        return XFS_RC ( rcInvalid );
    }

    RCt = KDirectoryNativeDir ( & Directory );
    if ( RCt == 0 ) {
        RCt = KDirectoryList (
                            Directory,
                            & List,
                            NULL,
                            NULL,
                            Node -> path
                            );
        if ( RCt == 0 ) {
            RCt = KNamelistCount ( List, & ListCount );
            if ( RCt == 0 ) {
                for ( Idx = 0; Idx < ListCount; Idx ++ ) {
                    RCt = KNamelistGet ( List, Idx, & Name );
                    if ( RCt == 0 ) {
                        RCt = _LoadKartItem ( Directory, Node, Name );
                    }
                    if ( RCt != 0 ) {
                        break;
                    }
                }
            }

            KNamelistRelease ( List );
        }

        KDirectoryRelease ( Directory );
    }

    return RCt;
}   /* _LoadKartScanPath () */
Пример #24
0
rc_t KeyRingWhack(KKeyRing* self)
{
    KeyRingDataWhack( self->data );
    free(self->data);
    free(self->path);
    KDirectoryRelease(self->wd);
    free(self);
    return 0;
}
Пример #25
0
static rc_t ref_seq_load_main( const p_context ctx )
{
    KDirectory *dir;
    rc_t rc = KDirectoryNativeDir( &dir );
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryNativeDir() failed" );
    }
    else
    {
        VDBManager *mgr;
        rc = VDBManagerMakeUpdate ( &mgr, dir );
        if ( rc != 0 )
        {
            LOGERR( klogErr, rc, "ref_seq_load_main:VDBManagerMakeRead() failed" );
        }
        else
        {
            rc = prepare_load( dir, ctx );
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "ref_seq_load_main:prepare_load() failed" );
            }
            else
            {
                char tblpath[ 4096 ];
                rc = KDirectoryResolvePath( dir, true, tblpath, sizeof tblpath, ctx->dst_path );
                if ( rc != 0 )
                {
                    LOGERR( klogErr, rc, "ref_seq_load_main:KDirectoryResolvePath() failed" );
                }
                else
                {
                    KPathType type = VDBManagerPathType( mgr, tblpath );
                    if ( type != kptNotFound )
                    {
                        rc = RC( rcExe, rcDatabase, rcCreating, rcFile, rcExists );
                        PLOGERR( klogErr, ( klogErr, rc, "$(path)", "path=%s", tblpath ) );
                    }
                }
            }

            if ( rc == 0 )
            {
                rc = perform_load( ctx, dir, mgr ); /* <====================== */
                if ( rc != 0 )
                {
                    remove_path( dir, ctx->dst_path, ctx->quiet );
                }
            }

            VDBManagerRelease( mgr );
        }
        KDirectoryRelease( dir );
    }
    return rc;
}
Пример #26
0
rc_t report_deletes( Args * args, uint32_t min_len )
{
    uint32_t count;
    rc_t rc = ArgsParamCount( args, &count );
    if ( rc != 0 )
    {
        LOGERR( klogInt, rc, "ArgsParamCount() failed" );
    }
    else
    {
        KDirectory *dir; 
        rc = KDirectoryNativeDir( &dir );
        if ( rc != 0 )
        {
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
        }
        else
        {
            const VDBManager *vdb_mgr;
            rc = VDBManagerMakeRead ( &vdb_mgr, dir );
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
            }
            else
            {
                VFSManager * vfs_mgr;
                rc =  VFSManagerMake ( &vfs_mgr );
                if ( rc != 0 )
                {
                    (void)LOGERR( klogErr, rc, "cannot make vfs-manager" );
                }
                else
                {
                    uint32_t idx;
                    for ( idx = 0; idx < count && rc == 0; ++idx )
                    {
                        const char *param = NULL;
                        rc = ArgsParamValue( args, idx, (const void **)&param );
                        if ( rc != 0 )
                        {
                            LOGERR( klogInt, rc, "ArgsParamvalue() failed" );
                        }
                        else
                        {
                            rc = report_deletes_spec( vdb_mgr, vfs_mgr, param, min_len );
                        }
                    }
                    VFSManagerRelease ( vfs_mgr );
                }
                VDBManagerRelease( vdb_mgr );
            }
            KDirectoryRelease( dir );
        }
    }
    return rc;
}
Пример #27
0
static
rc_t	run_kar_extract (const char * archive, const char * directory)
{
    rc_t rc;
    const KDirectory * din;
    KDirectory * dout;

    STSMSG (1, ("run_kar_extract"));

    rc = open_file_as_dir (archive, &din);
    if (rc == 0 )
    {
        char * directorystr;
        rc = derive_directory_name (&directorystr, archive, directory);
        
        if (rc != 0)
        {
            ;
/*             PLOGERR (klogDebug1, (klogDebug1, rc, "failure to derive archive [$(A)/$(D)]", */
/*                      PLOG_2(PLOG_S(A),PLOG_S(D)), archive, directory)); */
        }
        else
        {
            rc = open_out_dir (directorystr, &dout);
            free (directorystr);
            if (rc != 0)
            {
                LOGERR (klogErr, rc, "failure to open output directory");
            }
            else
            {
                extract_adata adata;
                adata.dir = dout;
                adata.filter = pnamesFilter;
                adata.fdata = NULL;
                
                rc = step_through_dir (din, ".", pnamesFilter, NULL, extract_action, &adata);
                KDirectoryRelease (dout);
            }
        }
        KDirectoryRelease (din);
    }
    return rc;
}
Пример #28
0
/* IsAlias
 *  returns true if object name is an alias
 *  returns path to fundamental name if it was aliased
 *
 *  "type" [ IN ] - a KDBPathType
 *  valid values are kptIndex and kptColumn
 *
 *  "resolved" [ OUT ] and "rsize" [ IN ] - optional output buffer
 *  for fundamenta object name if "alias" is not a fundamental name, 
 *
 *  "name" [ IN ] - NUL terminated object name
 */
LIB_EXPORT bool CC KTableIsAlias ( const KTable *self, uint32_t type,
    char *resolved, size_t rsize, const char *name )
{
    if ( self != NULL && name != NULL && name [ 0 ] != 0 )
    {
        rc_t rc;
        const char *ns;
        char path [ 256 ];

        switch ( type )
        {
        case kptIndex:
            ns = "idx";
            break;

        case kptColumn:
            ns = "col";
            break;

        default:
            return false;
        }

        rc = KDBMakeSubPath ( self -> dir, path, sizeof path, ns, 3, name );
        if ( rc == 0 )
        {
            switch ( KDirectoryPathType ( self -> dir, "%s", path ) )
            {
            case kptFile | kptAlias:
            case kptDir | kptAlias:
                if ( resolved != NULL && rsize != 0 )
                {
                    const KDirectory *sub;
                    rc = KDirectoryOpenDirRead ( self -> dir, & sub, false, "%s", ns );
                    * resolved = 0;
                    if ( rc != 0 )
                        PLOGERR ( klogWarn, ( klogWarn, rc, "failed to open subdirectory '$(sub)'", "sub=%s", ns ) );
                    else
                    {
                        rc = KDirectoryResolveAlias ( sub, false, resolved, rsize, "%s", name );
                        KDirectoryRelease ( sub );
                        if ( rc != 0 )
                            PLOGERR ( klogWarn, ( klogWarn, rc, "failed to resolve alias '$(alias)'", "alias=%s", name ) );
                    }
                }
                return true;
            }
        }
    }

    if ( resolved != NULL && rsize != 0 )
        * resolved = 0;

    return false;
}
Пример #29
0
rc_t KeyRingOpen(KKeyRing** self, const char* path, const struct KFile* pwd_in, struct KFile* pwd_out)
{
    rc_t rc; 
    assert(self && path && pwd_in && pwd_out);

    *self = (KKeyRing*) malloc(sizeof(**self));
    if (*self)
    { 
        rc = KeyRingInit(*self, path);
        if (rc == 0)
        {
            rc = KeyRingAddRef(*self);
            if (rc == 0)
            {
                KDirectory* wd; 
                rc = KDirectoryNativeDir(&wd);
                if (rc == 0)
                {   /* open the database */
                    if (KDirectoryPathType(wd, "%s", (*self)->path) == kptFile)
                        rc = GetPassword(pwd_in, pwd_out, (*self)->passwd);
                    else /* does not exist; create first */
                    {   
                        rc = GetNewPassword(pwd_in, pwd_out, (*self)->passwd);
                        if (rc == 0)
                            rc = CreateDatabase(*self);
                    }
                    if (rc == 0)
                        rc = OpenDatabase(*self);
                        
                    {
                        rc_t rc2;
                        rc2 = KDirectoryRelease(wd);
                        if (rc == 0)
                            rc = rc2;
                    }
                }
            }
            
            if (rc != 0)
            {
                KeyRingWhack(*self);
                *self = NULL;
            }
        }
        else
        {
            free(*self);
            *self = NULL;
        }
    }
    else
        rc = RC ( rcApp, rcDatabase, rcOpening, rcMemory, rcExhausted );

    return rc;
}
Пример #30
0
static void ref_walker_release( struct ref_walker * self )
{
    KDirectoryRelease( self->dir );
    VDBManagerRelease( self->vmgr );
    VSchemaRelease( self->vschema );
    AlignMgrRelease ( self->amgr );
    VFSManagerRelease ( self->vfs_mgr );
    VNamelistRelease ( self->sources );
    free_ref_regions( &self->regions );
    free( ( void * )self->spot_group );
}