From 00651aeaf50f8481a2c894f9462cd3b8eb6971d6 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 1 Oct 2024 11:21:13 -0700 Subject: More myriad fixes, it passes all existing unit tests. --- src/stable/myriad.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/stable/myriad.cpp') diff --git a/src/stable/myriad.cpp b/src/stable/myriad.cpp index 85daa0d..f9fcd3e 100644 --- a/src/stable/myriad.cpp +++ b/src/stable/myriad.cpp @@ -12,13 +12,13 @@ #define MyriadRead( target, size ) if( rBacking.read( target, size ) < size ) \ { \ throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ - "Insufficent data reading myriad data from backing stream."); \ + "Insufficient data reading myriad data from backing stream."); \ } (void)0 #define ReqRead( stream, target, size ) if( stream.read( target, size ) < size ) \ { \ throw Bu::MyriadException( Bu::MyriadException::invalidFormat, \ - "Insufficent data reading from myriad stream."); \ + "Insufficient data reading from myriad stream."); \ } (void)0 namespace Bu @@ -112,7 +112,7 @@ Bu::MyriadStream Bu::Myriad::open( Bu::Myriad::StreamId iStream, } { Bu::MutexLocker l2( mBacking ); - if( (eMode&Write) && rBacking.isWritable() ) + if( (eMode&Write) && !rBacking.isWritable() ) { throw Bu::MyriadException( MyriadException::badMode, "Backing stream does not support writing."); @@ -398,6 +398,8 @@ bool Bu::Myriad::loadMyriad() lFreeBlocks = hUnusedBlocks.getKeys(); //Bu::println("Free blocks: %1").arg( lFreeBlocks.getSize() ); + + bIsNewStream = false; return true; } @@ -434,14 +436,11 @@ void Bu::Myriad::createMyriad( int32_t iBlockSize, int32_t iPreallocateBlocks ) //Bu::println(" Adjustment: %1 bytes / %2 cur blocks, %3 computed blocks (%4 target bytes).").arg( iHeaderStreamBytes+(iHeaderStreamBlocks*4) ).arg( iHeaderStreamBlocks ).arg( blkDiv((iHeaderStreamBytes+(iHeaderStreamBlocks*4)), iBlockSize) ).arg( iHeaderStreamBlocks*iBlockSize ); } - if( iPreallocateBlocks > iHeaderStreamBlocks ) + if( iPreallocateBlocks < iHeaderStreamBlocks ) { - rBacking.setSize( iBlockSize*iPreallocateBlocks ); - } - else - { - rBacking.setSize( iBlockSize*iHeaderStreamBlocks ); + iPreallocateBlocks = iHeaderStreamBlocks; } + rBacking.setSize( iBlockSize*iPreallocateBlocks ); // // Write Myriad header @@ -540,14 +539,15 @@ void Bu::Myriad::writeHeader() uint32_t uStreamSize = pStream->getSize(); mbHeader.write( &uStreamId, 4 ); mbHeader.write( &uStreamSize, 4 ); + int32_t iBlocks = Bu::blkDiv( uStreamSize, (uint32_t)iBlockSize ); Bu::Array aBlocks = pStream->getBlockList(); //Bu::println(" Stream %1 is %2 bytes %3 blocks (%4 blocks computed)").arg( *i ).arg( uStreamSize ).arg( aBlocks.getSize() ).arg( Bu::blkDiv( (int)uStreamSize, (int)iBlockSize ) ); - for( Bu::Array::iterator i = aBlocks.begin(); i; i++ ) +// for( Bu::Array::iterator i = aBlocks.begin(); i; i++ ) + for( int j = 0; j < iBlocks; j++ ) { - int32_t iIdx = *i; - mbHeader.write( &iIdx, 4 ); + mbHeader.write( &aBlocks[j], 4 ); } } @@ -768,7 +768,7 @@ int32_t Bu::Myriad::Stream::read( int32_t iStart, void *pTarget, if( iStart+iSize >= this->iSize ) { - int32_t iDiff = this->iSize-(iStart+iSize); + int32_t iDiff = (iStart+iSize)-this->iSize; iSize -= iDiff; iStart += iDiff; } -- cgit v1.2.3