Nonlib: Add (some) support for opening sessions readonly.

This commit is contained in:
Jonathan Moore Liles 2013-02-09 18:19:40 -08:00
parent 3756dea1d6
commit 4f4698a12c
2 changed files with 16 additions and 1 deletions

View File

@ -44,6 +44,7 @@ using std::max;
bool Loggable::_readonly = false;
FILE *Loggable::_fp; FILE *Loggable::_fp;
unsigned int Loggable::_log_id = 0; unsigned int Loggable::_log_id = 0;
int Loggable::_level = 0; int Loggable::_level = 0;
@ -116,9 +117,20 @@ Loggable::open ( const char *filename )
if ( ! ( fp = fopen( filename, "a+" ) ) ) if ( ! ( fp = fopen( filename, "a+" ) ) )
{ {
WARNING( "Could not open log file for writing!" ); WARNING( "Could not open log file for writing!" );
return false;
if ( ! ( fp = fopen( filename, "r" ) ) )
{
WARNING( "Could not open log file for reading!" );
return false;
}
else
{
_readonly = true;
}
} }
_readonly = false;
load_unjournaled_state(); load_unjournaled_state();
if ( newer( "snapshot", filename ) ) if ( newer( "snapshot", filename ) )

View File

@ -70,6 +70,7 @@ class Loggable
Log_Entry * unjournaled_state; Log_Entry * unjournaled_state;
}; };
static bool _readonly;
static FILE *_fp; static FILE *_fp;
static unsigned int _log_id; static unsigned int _log_id;
static int _level; static int _level;
@ -142,6 +143,8 @@ private:
public: public:
static bool readonly ( void ) { return _readonly; }
static bool replay ( const char *name ); static bool replay ( const char *name );
static bool snapshot( FILE * fp ); static bool snapshot( FILE * fp );