mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Rename ReadOnly to Immutable and clarify its purpose.
This commit is contained in:
parent
aa376f4ab1
commit
b1a7b26eef
3 changed files with 9 additions and 7 deletions
|
@ -490,7 +490,7 @@ void LocalStore::openDB(State & state, bool create)
|
||||||
/* Open the Nix database. */
|
/* Open the Nix database. */
|
||||||
std::string dbPath = dbDir + "/db.sqlite";
|
std::string dbPath = dbDir + "/db.sqlite";
|
||||||
auto & db(state.db);
|
auto & db(state.db);
|
||||||
auto openMode = readOnly ? SQLiteOpenMode::ReadOnly
|
auto openMode = readOnly ? SQLiteOpenMode::Immutable
|
||||||
: create ? SQLiteOpenMode::Normal
|
: create ? SQLiteOpenMode::Normal
|
||||||
: SQLiteOpenMode::NoCreate;
|
: SQLiteOpenMode::NoCreate;
|
||||||
state.db = SQLite(dbPath, openMode);
|
state.db = SQLite(dbPath, openMode);
|
||||||
|
|
|
@ -53,15 +53,14 @@ static void traceSQL(void * x, const char * sql)
|
||||||
|
|
||||||
SQLite::SQLite(const Path & path, SQLiteOpenMode mode)
|
SQLite::SQLite(const Path & path, SQLiteOpenMode mode)
|
||||||
{
|
{
|
||||||
bool readOnly = mode == SQLiteOpenMode::ReadOnly;
|
|
||||||
|
|
||||||
// useSQLiteWAL also indicates what virtual file system we need. Using
|
// useSQLiteWAL also indicates what virtual file system we need. Using
|
||||||
// `unix-dotfile` is needed on NFS file systems and on Windows' Subsystem
|
// `unix-dotfile` is needed on NFS file systems and on Windows' Subsystem
|
||||||
// for Linux (WSL) where useSQLiteWAL should be false by default.
|
// for Linux (WSL) where useSQLiteWAL should be false by default.
|
||||||
const char *vfs = settings.useSQLiteWAL ? 0 : "unix-dotfile";
|
const char *vfs = settings.useSQLiteWAL ? 0 : "unix-dotfile";
|
||||||
int flags = readOnly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
|
bool immutable = mode == SQLiteOpenMode::Immutable;
|
||||||
|
int flags = immutable ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
|
||||||
if (mode == SQLiteOpenMode::Normal) flags |= SQLITE_OPEN_CREATE;
|
if (mode == SQLiteOpenMode::Normal) flags |= SQLITE_OPEN_CREATE;
|
||||||
auto uri = "file:" + percentEncode(path) + "?immutable=" + (readOnly ? "1" : "0");
|
auto uri = "file:" + percentEncode(path) + "?immutable=" + (immutable ? "1" : "0");
|
||||||
int ret = sqlite3_open_v2(uri.c_str(), &db, SQLITE_OPEN_URI | flags, vfs);
|
int ret = sqlite3_open_v2(uri.c_str(), &db, SQLITE_OPEN_URI | flags, vfs);
|
||||||
if (ret != SQLITE_OK) {
|
if (ret != SQLITE_OK) {
|
||||||
const char * err = sqlite3_errstr(ret);
|
const char * err = sqlite3_errstr(ret);
|
||||||
|
|
|
@ -23,10 +23,13 @@ enum class SQLiteOpenMode {
|
||||||
*/
|
*/
|
||||||
NoCreate,
|
NoCreate,
|
||||||
/**
|
/**
|
||||||
* Open the database in read-only mode.
|
* Open the database in immutable mode.
|
||||||
|
* In addition to the database being read-only,
|
||||||
|
* no wal or journal files will be created by sqlite.
|
||||||
|
* Use this mode if the database is on a read-only filesystem.
|
||||||
* Fails with an error if the database does not exist.
|
* Fails with an error if the database does not exist.
|
||||||
*/
|
*/
|
||||||
ReadOnly
|
Immutable
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue