forked from lix-project/lix
* Fix a bug that caused Fix not to be deterministic (due to addToStore
returning different paths if the hash of the path to be added was already available in the store under a different name).
This commit is contained in:
parent
c834a5c597
commit
73b163c1a1
|
@ -131,7 +131,7 @@ static Expr evalExpr(Expr e)
|
||||||
string srcPath = searchPath(s1);
|
string srcPath = searchPath(s1);
|
||||||
string dstPath;
|
string dstPath;
|
||||||
Hash hash;
|
Hash hash;
|
||||||
addToStore(srcPath, dstPath, hash);
|
addToStore(srcPath, dstPath, hash, true);
|
||||||
return ATmake("Path(<str>, Hash(<str>), [])",
|
return ATmake("Path(<str>, Hash(<str>), [])",
|
||||||
dstPath.c_str(), ((string) hash).c_str());
|
dstPath.c_str(), ((string) hash).c_str());
|
||||||
}
|
}
|
||||||
|
|
19
src/store.cc
19
src/store.cc
|
@ -224,24 +224,23 @@ string expandHash(const Hash & hash, const string & target,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void addToStore(string srcPath, string & dstPath, Hash & hash)
|
void addToStore(string srcPath, string & dstPath, Hash & hash,
|
||||||
|
bool deterministicName)
|
||||||
{
|
{
|
||||||
srcPath = absPath(srcPath);
|
srcPath = absPath(srcPath);
|
||||||
|
|
||||||
hash = hashPath(srcPath);
|
hash = hashPath(srcPath);
|
||||||
|
|
||||||
try {
|
|
||||||
/* !!! should not use the substitutes! */
|
|
||||||
dstPath = expandHash(hash, "", nixStore);
|
|
||||||
return;
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
string baseName = baseNameOf(srcPath);
|
string baseName = baseNameOf(srcPath);
|
||||||
dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
|
dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
|
||||||
|
|
||||||
copyPath(srcPath, dstPath);
|
try {
|
||||||
|
/* !!! should not use the substitutes! */
|
||||||
|
dstPath = expandHash(hash, deterministicName ? dstPath : "", nixStore);
|
||||||
|
return;
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
|
||||||
|
copyPath(srcPath, dstPath);
|
||||||
registerPath(dstPath, hash);
|
registerPath(dstPath, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@ string expandHash(const Hash & hash, const string & target = "",
|
||||||
|
|
||||||
/* Copy a file to the nixStore directory and register it in dbRefs.
|
/* Copy a file to the nixStore directory and register it in dbRefs.
|
||||||
Return the hash code of the value. */
|
Return the hash code of the value. */
|
||||||
void addToStore(string srcPath, string & dstPath, Hash & hash);
|
void addToStore(string srcPath, string & dstPath, Hash & hash,
|
||||||
|
bool deterministicName = false);
|
||||||
|
|
||||||
/* Delete a value from the nixStore directory. */
|
/* Delete a value from the nixStore directory. */
|
||||||
void deleteFromStore(const string & path);
|
void deleteFromStore(const string & path);
|
||||||
|
|
Loading…
Reference in a new issue