mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
This commit is contained in:
parent
91313011f9
commit
22c225a899
2 changed files with 46 additions and 19 deletions
|
|
@ -111,10 +111,6 @@ LocalStore::LocalStore(bool reserveSpace)
|
||||||
readOnlyMode = true;
|
readOnlyMode = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dbValidPaths = nixDB.openTable("validpaths");
|
|
||||||
dbReferences = nixDB.openTable("references");
|
|
||||||
dbReferrers = nixDB.openTable("referrers", true); /* must be sorted */
|
|
||||||
dbDerivers = nixDB.openTable("derivers");
|
|
||||||
|
|
||||||
int curSchema = 0;
|
int curSchema = 0;
|
||||||
Path schemaFN = nixDBPath + "/schema";
|
Path schemaFN = nixDBPath + "/schema";
|
||||||
|
|
@ -128,6 +124,13 @@ LocalStore::LocalStore(bool reserveSpace)
|
||||||
throw Error(format("current Nix store schema is version %1%, but I only support %2%")
|
throw Error(format("current Nix store schema is version %1%, but I only support %2%")
|
||||||
% curSchema % nixSchemaVersion);
|
% curSchema % nixSchemaVersion);
|
||||||
|
|
||||||
|
if (curSchema < nixSchemaVersion) { // !!! temporary
|
||||||
|
dbValidPaths = nixDB.openTable("validpaths");
|
||||||
|
dbReferences = nixDB.openTable("references");
|
||||||
|
dbReferrers = nixDB.openTable("referrers", true); /* must be sorted */
|
||||||
|
dbDerivers = nixDB.openTable("derivers");
|
||||||
|
}
|
||||||
|
|
||||||
if (curSchema < nixSchemaVersion) {
|
if (curSchema < nixSchemaVersion) {
|
||||||
if (curSchema == 0) /* new store */
|
if (curSchema == 0) /* new store */
|
||||||
curSchema = nixSchemaVersion;
|
curSchema = nixSchemaVersion;
|
||||||
|
|
@ -250,6 +253,32 @@ void canonicalisePathMetaData(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Path metaPathFor(const Path & path)
|
||||||
|
{
|
||||||
|
string baseName = baseNameOf(path);
|
||||||
|
return (format("%1%/meta/%2%") % nixDBPath % baseName).str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Path infoFileFor(const Path & path)
|
||||||
|
{
|
||||||
|
return metaPathFor(path) + ".info";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ValidPathInfo queryPathInfo(const Path & path)
|
||||||
|
{
|
||||||
|
ValidPathInfo res;
|
||||||
|
|
||||||
|
Path infoFile = infoFileFor(path);
|
||||||
|
if (!pathExists(infoFile))
|
||||||
|
throw Error(format("path `%1%' is not valid") % path);
|
||||||
|
string info = readFile(infoFile);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isValidPathTxn(const Transaction & txn, const Path & path)
|
bool isValidPathTxn(const Transaction & txn, const Path & path)
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
|
|
@ -259,7 +288,7 @@ bool isValidPathTxn(const Transaction & txn, const Path & path)
|
||||||
|
|
||||||
bool LocalStore::isValidPath(const Path & path)
|
bool LocalStore::isValidPath(const Path & path)
|
||||||
{
|
{
|
||||||
return isValidPathTxn(noTxn, path);
|
return pathExists(infoFileFor(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -342,10 +371,11 @@ void oldQueryReferences(const Transaction & txn,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::queryReferences(const Path & storePath,
|
void LocalStore::queryReferences(const Path & path,
|
||||||
PathSet & references)
|
PathSet & references)
|
||||||
{
|
{
|
||||||
oldQueryReferences(noTxn, storePath, references);
|
ValidPathInfo info = queryPathInfo(path);
|
||||||
|
references.insert(info.references.begin(), info.references.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1147,13 +1177,6 @@ static void upgradeStore11()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path metaFileFor(const Path & path)
|
|
||||||
{
|
|
||||||
string baseName = baseNameOf(path);
|
|
||||||
return (format("%1%/meta/%2%") % nixDBPath % baseName).str();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* !!! move to util.cc */
|
/* !!! move to util.cc */
|
||||||
void appendFile(const Path & path, const string & s)
|
void appendFile(const Path & path, const string & s)
|
||||||
{
|
{
|
||||||
|
|
@ -1168,7 +1191,10 @@ void newRegisterValidPath(const Path & path,
|
||||||
const Hash & hash, const PathSet & references,
|
const Hash & hash, const PathSet & references,
|
||||||
const Path & deriver)
|
const Path & deriver)
|
||||||
{
|
{
|
||||||
Path infoFile = metaFileFor(path) + ".info";
|
Path infoFile = infoFileFor(path);
|
||||||
|
if (pathExists(infoFile)) return;
|
||||||
|
|
||||||
|
// !!! acquire PathLock on infoFile here
|
||||||
|
|
||||||
string refs;
|
string refs;
|
||||||
for (PathSet::const_iterator i = references.begin(); i != references.end(); ++i) {
|
for (PathSet::const_iterator i = references.begin(); i != references.end(); ++i) {
|
||||||
|
|
@ -1181,7 +1207,7 @@ void newRegisterValidPath(const Path & path,
|
||||||
have referrer mappings back to `path'. A " " is prefixed
|
have referrer mappings back to `path'. A " " is prefixed
|
||||||
to separate it from the previous entry. It's not suffixed
|
to separate it from the previous entry. It's not suffixed
|
||||||
to deal with interrupted partial writes to this file. */
|
to deal with interrupted partial writes to this file. */
|
||||||
Path referrersFile = metaFileFor(*i) + ".referrers";
|
Path referrersFile = metaPathFor(*i) + ".referrers";
|
||||||
/* !!! locking */
|
/* !!! locking */
|
||||||
appendFile(referrersFile, " " + path);
|
appendFile(referrersFile, " " + path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -352,9 +352,10 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix)
|
||||||
|
|
||||||
Paths createDirs(const Path & path)
|
Paths createDirs(const Path & path)
|
||||||
{
|
{
|
||||||
if (path == "/") return Paths();
|
Paths created;
|
||||||
Paths created = createDirs(dirOf(path));
|
if (path == "/") return created;
|
||||||
if (!pathExists(path)) {
|
if (!pathExists(path)) {
|
||||||
|
created = createDirs(dirOf(path));
|
||||||
if (mkdir(path.c_str(), 0777) == -1)
|
if (mkdir(path.c_str(), 0777) == -1)
|
||||||
throw SysError(format("creating directory `%1%'") % path);
|
throw SysError(format("creating directory `%1%'") % path);
|
||||||
created.push_back(path);
|
created.push_back(path);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue