Browse Source

Clean up compaction code.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
05ebbc073b
2 changed files with 11 additions and 17 deletions
  1. +8
    -15
      Timeline/Loggable.C
  2. +3
    -2
      Timeline/Loggable.H

+ 8
- 15
Timeline/Loggable.C View File

@@ -327,13 +327,13 @@ Loggable::undo ( void )
} }


/** write a snapshot of the state of all loggable objects, sufficient /** write a snapshot of the state of all loggable objects, sufficient
* for later reconstruction, to /file/ */
* for later reconstruction, to /fp/ */
bool bool
Loggable::snapshot( const char *file )
Loggable::snapshot( FILE *fp )
{ {
FILE *ofp = _fp; FILE *ofp = _fp;


if ( ! ( _fp = fopen( file, "w" ) ) )
if ( ! ( _fp = fp ) )
{ {
_fp = ofp; _fp = ofp;
return false; return false;
@@ -345,8 +345,6 @@ Loggable::snapshot( const char *file )
_loggables[ i ]->log_create(); _loggables[ i ]->log_create();
} }


fclose( _fp );

_fp = ofp; _fp = ofp;


return true; return true;
@@ -355,19 +353,14 @@ Loggable::snapshot( const char *file )
void void
Loggable::compact ( 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 void


+ 3
- 2
Timeline/Loggable.H View File

@@ -68,6 +68,7 @@ class Loggable
static queue <char *> _transaction; static queue <char *> _transaction;


private: private:

int _id; int _id;


char **_old_state; char **_old_state;
@@ -88,14 +89,14 @@ private:
log( "\t" ); log( "\t" );
} }


static bool snapshot( FILE * fp );


public: public:


static bool open ( const char *filename ); static bool open ( const char *filename );
static void undo ( void ); static void undo ( void );
static int undo_index ( void ) { return _undo_index; } static int undo_index ( void ) { return _undo_index; }
static bool snapshot( const char *file );
static void compact( void );
static void compact ( void );


static static
void void


Loading…
Cancel
Save