make loading a null or invalid storage area not be fatal, but use the default path

This commit is contained in:
Isaac Connor 2015-12-15 09:39:29 -05:00
parent a196906345
commit 6aadd7330a
1 changed files with 19 additions and 12 deletions

View File

@ -39,21 +39,28 @@ Storage::Storage( MYSQL_ROW &dbrow ) {
strncpy( path, dbrow[index++], sizeof(path) ); strncpy( path, dbrow[index++], sizeof(path) );
} }
/* If a zero or invalid p_id is passed, then the old default path will be assumed. */
Storage::Storage( unsigned int p_id ) { Storage::Storage( unsigned int p_id ) {
char sql[ZM_SQL_SML_BUFSIZ]; if ( p_id ) {
snprintf( sql, sizeof(sql), "SELECT Id, Name, Path from Storage WHERE Id=%d", p_id ); char sql[ZM_SQL_SML_BUFSIZ];
MYSQL_ROW dbrow = zmDbFetchOne( sql ); snprintf( sql, sizeof(sql), "SELECT Id, Name, Path from Storage WHERE Id=%d", p_id );
if ( ! dbrow ) { MYSQL_ROW dbrow = zmDbFetchOne( sql );
Error( "Can't use query result: %s", mysql_error( &dbconn ) ); if ( ! dbrow ) {
exit( mysql_errno( &dbconn ) ); Error( "Unable to load storage area for id %d: %s", p_id, mysql_error( &dbconn ) );
} } else {
unsigned int index = 0;
id = atoi( dbrow[index++] );
strncpy( name, dbrow[index++], sizeof(name) );
strncpy( path, dbrow[index++], sizeof(path) );
Info( "Loaded Storage area '%s'", this->getName() );
}
}
if ( ! id ) {
strcpy(name, "Default");
strncpy(path, config.dir_events, sizeof(path) );
}
unsigned int index = 0;
id = atoi( dbrow[index++] );
strncpy( name, dbrow[index++], sizeof(name) );
strncpy( path, dbrow[index++], sizeof(path) );
Info( "Loaded Storage area '%s'", this->getName() );
} }
Storage::~Storage() { Storage::~Storage() {