1
0
Fork 0

Check nav-cache write-ability explicitly.

Check the file permissions before opening using the new SGPath APIs,
and validate the result using Sqlite APIs after opening.
This commit is contained in:
James Turner 2017-01-26 20:35:25 +00:00
parent 45c6ec216f
commit d343496084

View file

@ -261,6 +261,9 @@ public:
SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache at:" << path);
readOnly = fgGetBool("/sim/fghome-readonly", false);
if (!readOnly && !path.canWrite()) {
throw sg_exception("Nav-cache file is not writeable");
}
int openFlags = readOnly ? SQLITE_OPEN_READONLY :
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
@ -276,6 +279,10 @@ public:
throw sg_exception("Navcache failed to open:" + errMsg);
}
if (!readOnly && (sqlite3_db_readonly(db, nullptr) != 0)) {
throw sg_exception("Nav-cache file opened but is not writeable");
}
sqlite3_stmt_ptr checkTables =
prepare("SELECT count(*) FROM sqlite_master WHERE name='properties'");