Clean up compaction code.

This commit is contained in:
Jonathan Moore Liles 2008-04-23 19:33:44 -05:00
parent 2e7fab494a
commit 05ebbc073b
2 changed files with 11 additions and 17 deletions

View File

@ -327,13 +327,13 @@ Loggable::undo ( void )
}
/** write a snapshot of the state of all loggable objects, sufficient
* for later reconstruction, to /file/ */
* for later reconstruction, to /fp/ */
bool
Loggable::snapshot( const char *file )
Loggable::snapshot( FILE *fp )
{
FILE *ofp = _fp;
if ( ! ( _fp = fopen( file, "w" ) ) )
if ( ! ( _fp = fp ) )
{
_fp = ofp;
return false;
@ -345,8 +345,6 @@ Loggable::snapshot( const char *file )
_loggables[ i ]->log_create();
}
fclose( _fp );
_fp = ofp;
return true;
@ -355,21 +353,16 @@ Loggable::snapshot( const char *file )
void
Loggable::compact ( void )
{
fclose( _fp );
_fp = NULL;
/* FIXME: don't use name here */
snapshot( "history" );
fseek( _fp, 0, SEEK_SET );
ftruncate( fileno( _fp ), 0 );
if ( ! ( _fp = fopen( "history", "a+" ) ) )
{
printf( "Could not open log file for writing!" );
// return false;
}
snapshot( _fp );
_undo_index = 0;
}
void
Loggable::log ( const char *fmt, ... )
{

View File

@ -68,6 +68,7 @@ class Loggable
static queue <char *> _transaction;
private:
int _id;
char **_old_state;
@ -88,14 +89,14 @@ private:
log( "\t" );
}
static bool snapshot( FILE * fp );
public:
static bool open ( const char *filename );
static void undo ( void );
static int undo_index ( void ) { return _undo_index; }
static bool snapshot( const char *file );
static void compact( void );
static void compact ( void );
static
void