1
0
Fork 0

Add some additional check to NavCache opening.

Hoping to capture why opening the DB read-write fails in some cases
on Windows.
This commit is contained in:
James Turner 2017-01-10 10:39:07 +00:00
parent 9441f0d656
commit ac8fb6fd24

View file

@ -78,6 +78,7 @@
#include <Airports/parking.hxx>
#include <Airports/gnnode.hxx>
#include "CacheSchema.h"
#include <GUI/MessageBox.hxx>
using std::string;
@ -263,10 +264,17 @@ public:
int openFlags = readOnly ? SQLITE_OPEN_READONLY :
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
// see http://code.google.com/p/flightgear-bugs/issues/detail?id=1055
// for the UTF8 / path logic here
std::string pathUtf8 = path.utf8Str();
sqlite3_open_v2(pathUtf8.c_str(), &db, openFlags, NULL);
int result = sqlite3_open_v2(pathUtf8.c_str(), &db, openFlags, NULL);
if (result == SQLITE_MISUSE) {
// docs state sqlite3_errmsg may not work in this case
SG_LOG(SG_NAVCACHE, SG_WARN, "Failed to open DB at " << path << ": misuse of Sqlite API");
throw sg_exception("Navcache failed to open: Sqlite API misuse");
} else if (result != SQLITE_OK) {
std::string errMsg = sqlite3_errmsg(db);
SG_LOG(SG_NAVCACHE, SG_WARN, "Failed to open DB at " << path << " with error:\n\t" << errMsg);
throw sg_exception("Navcache failed to open:" + errMsg);
}
sqlite3_stmt_ptr checkTables =
prepare("SELECT count(*) FROM sqlite_master WHERE name='properties'");
@ -1207,11 +1215,25 @@ NavDataCache::NavDataCache()
} catch (sg_exception& e) {
SG_LOG(SG_NAVCACHE, t == 0 ? SG_WARN : SG_ALERT, "NavCache: init failed:" << e.what()
<< " (attempt " << t << ")");
if (t == (MAX_TRIES - 1)) {
// final attempt still failed, we are busted
flightgear::fatalMessageBox("Unable to open navigation cache",
std::string("The navigation data cache could not be opened:") + e.getMessage(),
e.getOrigin());
}
d.reset();
// only wipe the existing if not readonly
if (!fgGetBool("/sim/fghome-readonly", false)) {
homePath.remove();
bool ok = homePath.remove();
if (!ok) {
SG_LOG(SG_NAVCACHE, SG_ALERT, "NavCache: failed to remove previous cache file");
flightgear::fatalMessageBox("Unable to re-create navigation cache",
"Attempting to remove the old cache failed.",
"Location: " + homePath.utf8Str());
}
}
}
} // of retry loop