Esempio n. 1
0
LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file,
    bool use_config, bool status)
{
    static const char *bin = NULL;
    static const char *key = NULL;
    rc_t rc = 0;
    KConfig *cfg = NULL;
    bool found = false;
    if (ascp_bin == NULL || private_file == NULL) {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    *ascp_bin = *private_file = NULL;
    rc = returnAscp(bin, key, ascp_bin, private_file, &found);
    if (rc != 0 || found) {
        return rc;
    }
    rc = KConfigMake(&cfg, NULL);
    if (rc != 0) {
        return rc;
    }
    if (_KConfigAscpDisabled(cfg, status)) {
        if (status) {
            STSMSG(STS_INFO, ("Use of Aspera transfer is disabled "
                "by the configuration, using HTTP transfer"));
        }
    }
    else {
        KDirectory *dir = NULL;
        rc = _KConfigGetAscp(cfg, &bin, &key);
        if (bin != NULL) {
            assert(key && !rc);
            RELEASE(KConfig, cfg);
            rc = returnAscp(bin, key, ascp_bin, private_file, &found);
            if (rc != 0 || found) {
                return rc;
            }
        }
        rc = KDirectoryNativeDir(&dir);
        if (rc != 0) {
            return rc;
        }
        while (ascp_path(&bin, &key)) {
            if (_SystemHelp(bin, status)) {
                if (_KDirectoryFileFound(dir, key, status)) {
                    break;
                }
            }
        }
        RELEASE(KDirectory, dir);
    }
    RELEASE(KConfig, cfg);

    rc = returnAscp(bin, key, ascp_bin, private_file, &found);
    if (rc != 0 || found) {
        return rc;
    }
    else {
        return RC(rcNS, rcFile, rcCopying, rcFile, rcNotFound);
    }
}
Esempio n. 2
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;
}
Esempio n. 3
0
static rc_t ref_walker_init( struct ref_walker * self )
{
    rc_t rc = KDirectoryNativeDir( &self->dir );
    if ( rc == 0 )
        rc = VDBManagerMakeRead ( &self->vmgr, self->dir );
    if ( rc == 0 )
        rc = VDBManagerMakeSRASchema( self->vmgr, &self->vschema );
    if ( rc == 0 )
        rc = AlignMgrMakeRead ( &self->amgr );
    if ( rc == 0 )
        rc =  VFSManagerMake ( &self->vfs_mgr );        
    if ( rc == 0 )
        rc = VNamelistMake ( &self->sources, 10 );

    self->cb_block.data = self;
    self->cb_block.destroy = NULL;
    self->cb_block.populate = populate_data;
    self->cb_block.alloc_size = alloc_size;
    self->cb_block.fixed_size = 0;

    BSTreeInit( &self->regions );
    self->primary_alignments = true;
    
    if ( rc != 0 )
        ref_walker_release( self );
    return rc;
}
Esempio n. 4
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;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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;

}
Esempio n. 8
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;
}
Esempio n. 9
0
static
rc_t XML_Open(const char* path, const FSNode** tree)
{
    rc_t rc = 0;
    char errmsg[4096] = "";
    KDirectory *dir = NULL;
    
    PLOGMSG(klogInfo, (klogInfo, "Reading XML file '$(x)'", PLOG_S(x), path));
    if( (rc = KDirectoryNativeDir(&dir)) == 0 ) {
        const KFile* file = NULL;
        if( (rc = KDirectoryOpenFileRead(dir, &file, "%s", path)) == 0 ) {
            if( (rc = FSNode_Make((FSNode**)tree, "ROOT", &RootNode_vtbl)) == 0 ) {
                const KXMLDoc* xmldoc = NULL;
                if( (rc = KXMLMgrMakeDocRead(g_xmlmgr, &xmldoc, file)) == 0 ) {
                    const KXMLNodeset* ns = NULL;
                    if( (rc = KXMLDocOpenNodesetRead(xmldoc, &ns, "/FUSE/*")) == 0 ) {
                        uint32_t count = 0;
                        if( (rc = KXMLNodesetCount(ns, &count)) == 0 ) {
                            if( count == 0 ) {
                                rc = RC(rcExe, rcDoc, rcValidating, rcData, rcEmpty);
                            } else {
                                uint32_t i = 0;
                                while(rc == 0 && i < count) {
                                    const KXMLNode* n = NULL;
                                    if( (rc = KXMLNodesetGetNodeRead(ns, &n, i++)) == 0 ) {
                                        SRAConfigFlags flags = ~0;
                                        errmsg[0] = '\0';
                                        rc = XML_ValidateNode((FSNode*)*tree, n, flags, errmsg);
                                        ReleaseComplain(KXMLNodeRelease, n);
                                    }
                                }
                                if( rc == 0 ) {
                                    rc = SRAList_NextVersion();
                                }
                            }
                        }
                        ReleaseComplain(KXMLNodesetRelease, ns);
                    }
                    ReleaseComplain(KXMLDocRelease, xmldoc);
                }
                if( rc != 0 ) {
                    FSNode_Release(*tree);
                    *tree = NULL;
                }
            }
            ReleaseComplain(KFileRelease, file);
        }
        ReleaseComplain(KDirectoryRelease, dir);
    }
    if( rc == 0 ) {
        PLOGMSG(klogInfo, (klogInfo, "XML file '$(x)' ok", PLOG_S(x), path));
    } else {
        if( strlen(errmsg) < 1 ) {
            strcpy(errmsg, path);
        }
        LOGERR(klogErr, rc, errmsg);
    }
    return rc;
}
Esempio n. 10
0
    DepFixture(const char *path)
        : mgr(NULL)
        , vmgr(NULL)
        , resolver(NULL)
        , siteless(false)
    {
        rc_t rc = 0;

        KDirectory *wd = NULL;
        if (KDirectoryNativeDir(&wd)) {
            FAIL("failed to KDirectoryNativeDir");
        }

        const KDirectory *dir = NULL;
        KConfig *cfg = NULL;

        if (KDirectoryOpenDirRead(wd, &dir, false, path)) {
            FAIL("failed to KDirectoryOpenDirRead()");
        }
        if (KConfigMake(&cfg, dir)) {
            FAIL("failed to KConfigMake()");
        }
        RELEASE(KDirectory, dir);
        if (VFSManagerMakeFromKfg(&vmgr, cfg)) {
            FAIL("failed to VFSManagerMakeFromKfg()");
        }
        if (VFSManagerGetResolver(vmgr, &resolver)) {
            FAIL("failed to VFSManagerGetResolver");
        }

        String *result = NULL;
        rc = KConfigReadString(cfg, "repository/site/main/tracearc/root",
            &result);
        if (rc != 0) {
            if (rc == SILENT_RC(rcKFG, rcNode, rcOpening, rcPath, rcNotFound)) {
                rc = 0;
                siteless = true;
            }
            else {
                FAIL(
              "failed to KConfigReadString(repository/site/main/tracearc/root)");
            }
        }
        else {
            assert(result);
            KPathType t = KDirectoryPathType(wd, result->addr);
            if (t != kptDir) {
                siteless = true;
            }
        }
        RELEASE(String, result);

        RELEASE(KConfig, cfg);
        if (VDBManagerMakeReadWithVFSManager(&mgr, NULL, vmgr)) {
            FAIL("failed to VDBManagerMakeReadWithVFSManager()");
        }

        RELEASE(KDirectory, wd);
    }
Esempio n. 11
0
rc_t CC KMain ( int argc, char *argv [] )
{
    Args * args;

    rc_t rc = ArgsMakeAndHandle ( &args, argc, argv, 2,
                                  MyOptions, sizeof MyOptions / sizeof ( OptDef ),
                                  XMLLogger_Args, XMLLogger_ArgsQty  );

    KLogHandlerSetStdErr();
    if ( rc != 0 )
    {
        LOGERR( klogErr, rc, "error creating internal structure" );
    }
    else
    {
        ld_context lctx;

        lctx_init( &lctx );
        rc = KDirectoryNativeDir ( &lctx.wd );
        if ( rc != 0 )
        {
            LOGERR( klogErr, rc, "error creating internal structure" );
        }
        else
        {
            rc = XMLLogger_Make( &lctx.xml_logger, lctx.wd, args );
            if ( rc != 0 )
            {
                LOGERR( klogErr, rc, "error creating internal structure" );
            }
            else
            {
                context ctx;
                rc = ctx_init( args, &ctx );
                if ( rc == 0 )
                {
                    rc = pacbio_check_sourcefile( &ctx, &lctx );
                    if ( rc == 0 )
                    {
                        lctx.with_progress = ctx.with_progress;
                        ctx_show( &ctx );
                        lctx.dst_path = ctx.dst_path;

                        rc = pacbio_load( &ctx, &lctx, false, false );
                        if ( rc == 0 )
                        {
                            rc = pacbio_meta_entry( &lctx, argv[ 0 ] );
                        }
                    }
                    ctx_free( &ctx );
                }
            }
        }
        lctx_free( &lctx );
        ArgsWhack ( args );
    }

    return rc;
}
Esempio n. 12
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;
}
Esempio n. 13
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;
}
Esempio n. 14
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;
}
Esempio n. 15
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 () */
Esempio n. 16
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;
}
Esempio n. 17
0
/** Init the static directory object */
static rc_t SpotIteratorInitDirectory(void) {
    if (__SpotIteratorDirectory) {
        return 0;
    }
    else {
        rc_t rc = KDirectoryNativeDir(&__SpotIteratorDirectory);
        DISP_RC(rc, "while calling KDirectoryNativeDir");
        return rc;
    }
}
Esempio n. 18
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;
}
Esempio n. 19
0
rc_t make_stdout_redir ( stdout_redir ** writer, const char * filename, size_t bufsize )
{
    KDirectory *dir;
    rc_t rc = 0;
    stdout_redir * wr = NULL;

    if ( writer == NULL )
    {
        *writer = NULL;
        rc = RC ( rcApp, rcNoTarg, rcAllocating, rcSelf, rcNull );
    }
    else
    {
        wr = calloc( 1, sizeof *wr );
        if ( wr == NULL )
            rc = RC ( rcApp, rcNoTarg, rcAllocating, rcMemory, rcExhausted );
    }

    if ( rc == 0 )
    {
        rc = KDirectoryNativeDir( &dir );
        if ( rc == 0 )
        {
            KFile *of;
            rc = KDirectoryCreateFile ( dir, &of, false, 0664, kcmInit | kcmCreate, "%s", filename );
            if ( rc == 0 )
            {
                KFile* buf;
                rc = KBufFileMakeWrite( &buf, of, false, bufsize );
                if ( rc == 0 )
                {
                    wr->kfile = buf;
                    wr->org_writer = KOutWriterGet();
                    wr->org_data = KOutDataGet();
                    rc = KOutHandlerSet( stdout_redir_callback, wr );
                    if ( rc != 0 )
                        LOGERR( klogInt, rc, "KOutHandlerSet() failed" );
                }
                KFileRelease( of );
            }
            KDirectoryRelease( dir );
        }
    }

    if ( rc == 0 )
        *writer = wr;
    else
    {
        if ( wr != NULL )
            free( wr );
    }

    return rc;
}
Esempio n. 20
0
static
rc_t TarNode_Touch(const TarNode* cself)
{
    rc_t rc = 0;

    if( cself->xml_path != NULL ) {
        KDirectory* dir = NULL;
        if( (rc = KDirectoryNativeDir(&dir)) == 0 ) {
            KTime_t dt;
            if( (rc = KDirectoryDate(dir, &dt, "%s", cself->xml_path)) == 0 ) {
                if( dt != cself->mtime ) {
                    const KFile* kfile = NULL;
                    DEBUG_MSG(8, ("%s: updating tar %s\n", __func__, cself->xml_path));
                    if( (rc = KDirectoryOpenFileRead(dir, &kfile, "%s", cself->xml_path)) == 0 ) {
                        const KXMLMgr* xmlmgr;
                        if( (rc = XML_MgrGet(&xmlmgr)) == 0 ) {
                            const KXMLDoc* xmldoc = NULL;
                            if( (rc = KXMLMgrMakeDocRead(xmlmgr, &xmldoc, kfile)) == 0 ) {
                                const KXMLNodeset* ns = NULL;
                                if( (rc = KXMLDocOpenNodesetRead(xmldoc, &ns, "/TAR")) == 0 ) {
                                    uint32_t count = 0;
                                    if( (rc = KXMLNodesetCount(ns, &count)) == 0 ) {
                                        if( count != 1 ) {
                                            rc = RC(rcExe, rcDoc, rcValidating, rcData, rcInvalid);
                                        } else {
                                            const KXMLNode* n = NULL;
                                            if( (rc = KXMLNodesetGetNodeRead(ns, &n, 0)) == 0 ) {
                                                char errmsg[4096];
                                                const TarFileList* new_files;
                                                if( (rc = TarNode_MakeFileList(n, &new_files, errmsg, cself->rel_path, cself->node.name)) != 0 ) {
                                                    LOGERR(klogErr, rc, errmsg);
                                                } else {
                                                    TarFileList_Release(cself->files);
                                                    ((TarNode*)cself)->files = new_files;
                                                    ((TarNode*)cself)->mtime = dt;
                                                }
                                                ReleaseComplain(KXMLNodeRelease, n);
                                            }
                                        }
                                    }
                                    ReleaseComplain(KXMLNodesetRelease, ns);
                                }
                                ReleaseComplain(KXMLDocRelease, xmldoc);
                            }
                        }
                        ReleaseComplain(KFileRelease, kfile);
                    }
                }
            }
            ReleaseComplain(KDirectoryRelease, dir);
        }
    }
    return rc;
}
Esempio n. 21
0
LIB_EXPORT rc_t CC ascp_locate(const char **ascp_bin, const char **private_file,
    bool use_config, bool status)
{
    rc_t rc = 0;
    KConfig *cfg = NULL;
    if (ascp_bin == NULL || private_file == NULL) {
        return RC(rcNS, rcFile, rcCopying, rcParam, rcNull);
    }
    *ascp_bin = *private_file = NULL;
    rc = KConfigMake(&cfg, NULL);
    if (rc != 0) {
        return rc;
    }
    if (_KConfigAscpDisabled(cfg, status)) {
        if (status) {
            STSMSG(STS_INFO, ("Use of Aspera transfer is disabled "
                "by the configuration, using HTTP transfer"));
        }
    }
    else {
        KDirectory *dir = NULL;
        const char *bin = NULL;
        const char *key = NULL;
        rc = _KConfigGetAscp(cfg, ascp_bin, private_file);
        if (*ascp_bin != NULL) {
            assert(*private_file && !rc);
            RELEASE(KConfig, cfg);
            return 0;
        }
        rc = KDirectoryNativeDir(&dir);
        if (rc != 0) {
            return rc;
        }
        while (ascp_path(&bin, &key)) {
            if (_SystemHelp(bin, status)) {
                if (_KDirectoryFileFound(dir, key, status)) {
                    *ascp_bin = string_dup_measure(bin, NULL);
                    *private_file = string_dup_measure(key, NULL);
                    if (*ascp_bin == NULL || *private_file == NULL) {
                        free((void*)*ascp_bin);
                        free((void*)*private_file);
                        *ascp_bin = *private_file = NULL;
                        return RC(rcNS,
                            rcStorage, rcAllocating, rcMemory, rcExhausted);
                    }
                    break;
                }
            }
        }
        RELEASE(KDirectory, dir);
    }
    RELEASE(KConfig, cfg);
    return rc;
}
Esempio n. 22
0
static rc_t make_local_file( const KFile ** f, const char * path )
{
    KDirectory * dir;
    rc_t rc = KDirectoryNativeDir( &dir );
    *f = NULL;
    if ( rc == 0 )
    {
        rc = KDirectoryOpenFileRead( dir, f, "%s", path );
        KDirectoryRelease( dir );
    }
    return rc;
}
Esempio n. 23
0
rc_t make_trans_ctx( trans_ctx * ctx, trans_opt * opt, bool open_reference )
{
    rc_t rc = AlignMgrMakeRead ( &ctx->almgr );
    if ( rc != 0 )
        LOGERR( klogInt, rc, "AlignMgrMake() failed" );

    if ( rc == 0 )
    {
        rc = KDirectoryNativeDir( &ctx->dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" );
    }

    if ( rc == 0 )
    {
        rc = VDBManagerMakeRead ( &ctx->vdb_mgr, ctx->dir );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" );
    }

    if ( rc == 0 )
    {
        if ( opt->fname != NULL )
        {
            rc = VDBManagerOpenDBRead ( ctx->vdb_mgr, &ctx->db, NULL, "%s", opt->fname );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "VDBManagerOpenDBRead() failed" );
        }
        else
            rc = RC ( rcApp, rcArgv, rcAccessing, rcParam, rcNull );
    }

    if ( rc == 0 )
    {
        rc = ReferenceList_MakeDatabase( &ctx->ref_list, ctx->db,
                                         ereferencelist_4na |
                                         ereferencelist_usePrimaryIds,
                                         0, NULL, 0 );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ReferenceList_MakeDatabase() failed" );
    }

    if ( rc == 0 && open_reference )
    {
        OUTMSG(( "looking for reference '%s'\n", opt->ref_name ));
        rc = ReferenceList_Find( ctx->ref_list, &ctx->ref_obj, opt->ref_name, string_size( opt->ref_name ) );
        if ( rc != 0 )
            LOGERR( klogInt, rc, "ReferenceList_Find() failed" );
    }

    return rc;
}
Esempio n. 24
0
static rc_t get_environment( tool_ctx_t * tool_ctx )
{
    rc_t rc = KAppGetTotalRam ( &( tool_ctx -> total_ram ) );
    if ( rc != 0 )
        ErrMsg( "KAppGetTotalRam() -> %R", rc );
    if ( rc == 0 )
    {
        rc = KDirectoryNativeDir( &( tool_ctx -> dir ) );
        if ( rc != 0 )
            ErrMsg( "KDirectoryNativeDir() -> %R", rc );
    }
    return rc;
}
Esempio n. 25
0
rc_t CC ReportRedirect
( KWrtHandler* handler, const char* filename, bool* to_file, bool finalize )
{
    rc_t rc = 0;
    if (!finalize) {
        if (handler) {
            handler->writer = KOutWriterGet();
            handler->data = KOutDataGet();
        }
        if (filename) {
            KDirectory* dir = NULL;
            SFile* data = calloc(1, sizeof *data);
            if (data == NULL) {
                return RC(rcFS, rcMemory, rcAllocating, rcMemory, rcExhausted);
            }
            data->magic = MAGIC;
            rc = KDirectoryNativeDir(&dir);
            if (rc == 0) {
                rc = KDirectoryCreateFile
                    (dir, &data->f, false, 0664, kcmInit, "%s", filename);
            }
            if (rc == 0) {
                rc = KOutHandlerSet(fileWriter, data);
            }
            RELEASE(KDirectory, dir);
        }
        if (rc != 0 || filename == NULL) {
            KOutHandlerSetStdErr();
            if (to_file)
            {   *to_file = false; }
        }
        else if (to_file)
        {   *to_file = true; }

    }
    else {
        void* data = KOutDataGet();
        SFile* self = (SFile*)data;
        if (self) {
            if (self->magic == MAGIC) {
                RELEASE(KFile, self->f);;
            }
            memset(self, 0, sizeof *self);
            free(self);
        }
        if (handler) {
            KOutHandlerSet(handler->writer, handler->data);
        }
    }
    return rc;
}
Esempio n. 26
0
/* Make
 *  create path manager
 *
 *  the path manager should already be configured with
 *  standard search paths, but can be augmented by using
 *  the Add*Path messages.
 *
 *  "dir" [ IN, NULL OKAY ] - optional root directory to use
 *  attaches a new reference
 */
MOD_EXPORT
rc_t CC SRAPathMakeImpl ( SRAPath **pm, const KDirectory *dir )
{
    rc_t rc;

    if ( pm == NULL )
        rc = RC ( rcSRA, rcMgr, rcConstructing, rcParam, rcNull );
    else
    {
        NCBISRAPath *p = (NCBISRAPath *) malloc ( sizeof * p );
        if ( p == NULL )
            rc = RC ( rcSRA, rcMgr, rcConstructing, rcMemory, rcExhausted );
        else
        {
            p -> dad . vt = ( SRAPath_vt* ) & vtSRAPath;
            p -> dir = dir;
            if ( dir != NULL )
                rc = KDirectoryAddRef ( dir );
            else
            {
                KDirectory *wd;
                rc = KDirectoryNativeDir ( & wd );
                p -> dir = wd;
            }

            if ( rc != 0 )
                free ( p );
            else
            {
                DLListInit ( & p -> repos );
                p -> dflt_repo = NULL;
                atomic32_set ( & p -> refcount, 1 );

                /* the object is now complete */
                rc = SRAPathConfig ( p );
                if ( rc == 0 )
                {
                    * pm = & p -> dad;
                    return 0;
                }

                SRAPathWhack ( p );
            }
        }

        * pm = NULL;
    }

    return rc;
}
Esempio n. 27
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;
}
Esempio n. 28
0
static rc_t OpenFile(KFile const **kf, char const path[], char const base[])
{
    char fname[4096];
    rc_t rc = PathWithBasePath(fname, sizeof(fname), path, base);
    
    if (rc == 0) {
        KDirectory *dir;
        
        rc = KDirectoryNativeDir(&dir);
        if (rc == 0) {
            rc = KDirectoryOpenFileRead(dir, kf, fname);
            KDirectoryRelease(dir);
        }
    }
    return rc;
}
Esempio n. 29
0
/** Init the static directory object */
static rc_t SpotIteratorInitDirectory   (void)
{
    if (__SpotIteratorDirectory)
    {
        return 0;
    }
    else
    {
        rc_t rc = KDirectoryNativeDir(&__SpotIteratorDirectory);
        if (rc != 0)
        {
            logerr(klogErr, rc, "while calling KDirectoryNativeDir");
        }
        return rc;
    }
}
Esempio n. 30
0
static uint64_t get_file_size( const char * path )
{
    uint64_t res = 0;
    KDirectory * dir;
    rc_t rc = KDirectoryNativeDir( &dir );
    if ( rc == 0 )
    {
        const KFile * f;
        rc = KDirectoryOpenFileRead( dir, &f, "%s", path );
        if ( rc == 0 )
        {
            KFileSize ( f, &res );
            KFileRelease( f );
        }
        KDirectoryRelease( dir );
    }
    return res;
}