mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
Check earlier whether schema migration is required.
This commit is contained in:
parent
fe174d72a2
commit
d55e38b98a
1 changed files with 10 additions and 3 deletions
|
@ -284,6 +284,14 @@ LocalStore::LocalStore(const Params & params)
|
|||
/* Check the current database schema and if necessary do an
|
||||
upgrade. */
|
||||
int curSchema = getSchema();
|
||||
if (readOnly && curSchema < nixSchemaVersion) {
|
||||
debug("current schema version: %d", curSchema);
|
||||
debug("supported schema version: %d", nixSchemaVersion);
|
||||
throw Error(curSchema == 0 ?
|
||||
"database does not exist, and cannot be created in read-only mode" :
|
||||
"database schema needs migrating, but this cannot be done in read-only mode");
|
||||
}
|
||||
|
||||
if (curSchema > nixSchemaVersion)
|
||||
throw Error("current Nix store schema is version %1%, but I only support %2%",
|
||||
curSchema, nixSchemaVersion);
|
||||
|
@ -307,7 +315,7 @@ LocalStore::LocalStore(const Params & params)
|
|||
"which is no longer supported. To convert to the new format,\n"
|
||||
"please upgrade Nix to version 1.11 first.");
|
||||
|
||||
if (!readOnly && !lockFile(globalLock.get(), ltWrite, false)) {
|
||||
if (!lockFile(globalLock.get(), ltWrite, false)) {
|
||||
printInfo("waiting for exclusive access to the Nix store...");
|
||||
lockFile(globalLock.get(), ltNone, false); // We have acquired a shared lock; release it to prevent deadlocks
|
||||
lockFile(globalLock.get(), ltWrite, true);
|
||||
|
@ -342,8 +350,7 @@ LocalStore::LocalStore(const Params & params)
|
|||
|
||||
writeFile(schemaPath, fmt("%1%", nixSchemaVersion), 0666, true);
|
||||
|
||||
if (!readOnly)
|
||||
lockFile(globalLock.get(), ltRead, true);
|
||||
lockFile(globalLock.get(), ltRead, true);
|
||||
}
|
||||
|
||||
else openDB(*state, false);
|
||||
|
|
Loading…
Reference in a new issue