From 8572c918c26062dceb3d11d4ccee10014ac98b16 Mon Sep 17 00:00:00 2001 From: Rick L Bird Date: Fri, 22 Apr 2011 16:53:50 -0400 Subject: [PATCH] Fixed minimal db loading IssueID #94 --- src/game.c | 70 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/game.c b/src/game.c index 7a2c0a1..80f6644 100644 --- a/src/game.c +++ b/src/game.c @@ -909,41 +909,40 @@ init_game_dbs(void) fcache_init(); /* Read flagfile before main database */ - f = db_open(flag_file); - - if(f) { - if(setjmp(db_err) == 0){ - use_flagfile = 1; - do_rawlog(LT_ERR, "LOADING: %s", flag_file); - if(load_flag_db(f) != 0) - use_flagfile = 0; - do_rawlog(LT_ERR, "LOADING: %s(done)", flag_file); - penn_fclose(f); - } - } else use_flagfile = 0; + + if(setjmp(db_err) == 1){ + do_rawlog(LT_ERR, "DB: Could not process flag file. Will Attempt reading from main database."); + use_flagfile = 0; + } else { + f = db_open(flag_file); + use_flagfile = 1; + do_rawlog(LT_ERR, "LOADING: %s", flag_file); + if(load_flag_db(f) != 0) + use_flagfile = 0; + do_rawlog(LT_ERR, "LOADING: %s(done)", flag_file); + penn_fclose(f); + } if(ps_tab._Read_Powers_ == 0) init_powers(); - f = db_open(infile); - - if (!f) { - do_rawlog(LT_ERR, "Couldn't open %s! Creating minimal world.", infile); - init_compress(NULL); - create_minimal_db(); - return 0; - } - - c = penn_fgetc(f); - if (c == EOF) { - do_rawlog(LT_ERR, "Couldn't read %s! Creating minimal world.", infile); - init_compress(NULL); - create_minimal_db(); - return 0; + if (setjmp(db_err) == 1) { + do_rawlog(LT_ERR, "Couldn't open %s! Creating minimal world.", infile); + init_compress(NULL); + create_minimal_db(); + return 0; + } else { + f = db_open(infile); + c = penn_fgetc(f); + if (c == EOF) { + do_rawlog(LT_ERR, "Couldn't read %s! Creating minimal world.", infile); + init_compress(NULL); + create_minimal_db(); + return 0; + } + c = penn_fgetc(f); } - penn_ungetc(c, f); - if (setjmp(db_err) == 0) { /* ok, read it in */ do_rawlog(LT_ERR, "ANALYZING: %s", infile); @@ -1006,8 +1005,7 @@ init_game_dbs(void) penn_fclose(f); panicdb = 0; } - } else /* Close the panicdb file handle */ - penn_fclose(f); + } if (!panicdb) { f = db_open(mailfile); @@ -1047,7 +1045,8 @@ init_game_dbs(void) } penn_fclose(f); } - } + } else /* Close the panicdb file handle */ + penn_fclose(f); #endif /* CHAT_SYSTEM */ } else { do_rawlog(LT_ERR, "ERROR READING DATABASE!"); @@ -2321,6 +2320,7 @@ db_open(const char *fname) pf->type = PFT_GZFILE; pf->handle.g = gzopen(filename, "rb"); if (!pf->handle.g) { + do_rawlog(LT_ERR, "Unable to open %s with libz: %s\n", filename, strerror(errno)); mush_free(pf, "pennfile"); longjmp(db_err, 1); } @@ -2356,8 +2356,10 @@ db_open(const char *fname) { pf->type = PFT_FILE; pf->handle.f = fopen(filename, FOPEN_READ); + if(!pf->handle.f) + do_rawlog(LT_ERR, "Unable to open %s: %s\n", filename, strerror(errno)); #ifdef HAVE_POSIX_FADVISE - if (pf->handle.f) + else if (pf->handle.f) posix_fadvise(fileno(pf->handle.f), 0, 0, POSIX_FADV_SEQUENTIAL); #endif @@ -2433,6 +2435,8 @@ db_open_write(const char *fname) { pf->type = PFT_FILE; pf->handle.f = fopen(filename, "wb"); + if (!pf->handle.f) + do_rawlog(LT_ERR, "Unable to open %s: %s\n", filename, strerror(errno)); } if (!pf->handle.f) { mush_free(pf, "pennfile"); -- 2.30.2