1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-25 11:49:35 +01:00

SQLite: Use std::filesystem::path

This commit is contained in:
Eelco Dolstra 2025-07-22 11:47:52 +02:00
parent 47281531ec
commit efceb43ff7
4 changed files with 7 additions and 7 deletions

View file

@ -69,10 +69,10 @@ struct AttrDb
{ {
auto state(_state->lock()); auto state(_state->lock());
Path cacheDir = getCacheDir() + "/eval-cache-v5"; auto cacheDir = std::filesystem::path(getCacheDir()) / "eval-cache-v5";
createDirs(cacheDir); createDirs(cacheDir);
Path dbPath = cacheDir + "/" + fingerprint.to_string(HashFormat::Base16, false) + ".sqlite"; auto dbPath = cacheDir / (fingerprint.to_string(HashFormat::Base16, false) + ".sqlite");
state->db = SQLite(dbPath); state->db = SQLite(dbPath);
state->db.isCache(); state->db.isCache();

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
///@file ///@file
#include <filesystem>
#include <functional> #include <functional>
#include <string> #include <string>
@ -39,7 +40,7 @@ struct SQLite
{ {
sqlite3 * db = 0; sqlite3 * db = 0;
SQLite() { } SQLite() { }
SQLite(const Path & path, SQLiteOpenMode mode = SQLiteOpenMode::Normal); SQLite(const std::filesystem::path & path, SQLiteOpenMode mode = SQLiteOpenMode::Normal);
SQLite(const SQLite & from) = delete; SQLite(const SQLite & from) = delete;
SQLite& operator = (const SQLite & from) = delete; SQLite& operator = (const SQLite & from) = delete;
// NOTE: This is noexcept since we are only copying and assigning raw pointers. // NOTE: This is noexcept since we are only copying and assigning raw pointers.

View file

@ -466,12 +466,11 @@ void LocalStore::openDB(State & state, bool create)
throw SysError("Nix database directory '%1%' is not writable", dbDir); throw SysError("Nix database directory '%1%' is not writable", dbDir);
/* Open the Nix database. */ /* Open the Nix database. */
std::string dbPath = dbDir + "/db.sqlite";
auto & db(state.db); auto & db(state.db);
auto openMode = config->readOnly ? SQLiteOpenMode::Immutable auto openMode = config->readOnly ? SQLiteOpenMode::Immutable
: create ? SQLiteOpenMode::Normal : create ? SQLiteOpenMode::Normal
: SQLiteOpenMode::NoCreate; : SQLiteOpenMode::NoCreate;
state.db = SQLite(dbPath, openMode); state.db = SQLite(std::filesystem::path(dbDir) / "db.sqlite", openMode);
#ifdef __CYGWIN__ #ifdef __CYGWIN__
/* The cygwin version of sqlite3 has a patch which calls /* The cygwin version of sqlite3 has a patch which calls

View file

@ -53,7 +53,7 @@ static void traceSQL(void * x, const char * sql)
notice("SQL<[%1%]>", sql); notice("SQL<[%1%]>", sql);
}; };
SQLite::SQLite(const Path & path, SQLiteOpenMode mode) SQLite::SQLite(const std::filesystem::path & path, SQLiteOpenMode mode)
{ {
// 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
@ -62,7 +62,7 @@ SQLite::SQLite(const Path & path, SQLiteOpenMode mode)
bool immutable = mode == SQLiteOpenMode::Immutable; bool immutable = mode == SQLiteOpenMode::Immutable;
int flags = immutable ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE; 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=" + (immutable ? "1" : "0"); auto uri = "file:" + percentEncode(path.string()) + "?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);