* Start move towards SHA-256 hashes instead of MD5.
* Start cleaning up unique store path generation (they weren't always
unique; in particular the suffix ("-aterm-2.2", "-builder.sh") was
not part of the hash, therefore changes to the suffix would cause
multiple store objects with the same hash).
This commit is contained in:
parent
a7b94e87d7
commit
9530cc3170
9 changed files with 63 additions and 34 deletions
|
|
@ -1137,7 +1137,7 @@ void NormalisationGoal::createClosure()
|
|||
/* Write the normal form. This does not have to occur in the
|
||||
transaction below because writing terms is idem-potent. */
|
||||
ATerm nfTerm = unparseStoreExpr(nf);
|
||||
Path nfPath = writeTerm(nfTerm, "-s");
|
||||
Path nfPath = writeTerm(nfTerm, "s");
|
||||
|
||||
/* Register each output path, and register the normal form. This
|
||||
is wrapped in one database transaction to ensure that if we
|
||||
|
|
|
|||
|
|
@ -411,19 +411,34 @@ static void invalidatePath(const Path & path, Transaction & txn)
|
|||
}
|
||||
|
||||
|
||||
Path makeStorePath(const string & type,
|
||||
Hash & hash, const string & suffix)
|
||||
{
|
||||
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
||||
string s = type + ":sha256:" + (string) hash + ":"
|
||||
+ nixStore + ":" + suffix;
|
||||
|
||||
Hash nameHash = hashString(s, htSHA256);
|
||||
|
||||
printMsg(lvlError, format("name input: %1% -> %2%") % s % (string) nameHash);
|
||||
|
||||
return nixStore + "/" + (string) nameHash + "-" + suffix;
|
||||
}
|
||||
|
||||
|
||||
Path addToStore(const Path & _srcPath)
|
||||
{
|
||||
Path srcPath(absPath(_srcPath));
|
||||
debug(format("adding `%1%' to the store") % srcPath);
|
||||
|
||||
Hash h(htMD5);
|
||||
Hash h(htSHA256);
|
||||
{
|
||||
SwitchToOriginalUser sw;
|
||||
h = hashPath(srcPath, htMD5);
|
||||
h = hashPath(srcPath, htSHA256);
|
||||
}
|
||||
|
||||
string baseName = baseNameOf(srcPath);
|
||||
Path dstPath = canonPath(nixStore + "/" + (string) h + "-" + baseName);
|
||||
Path dstPath = makeStorePath("source", h, baseName);
|
||||
|
||||
if (!readOnlyMode && !isValidPath(dstPath)) {
|
||||
|
||||
|
|
@ -443,6 +458,11 @@ Path addToStore(const Path & _srcPath)
|
|||
|
||||
copyPath(srcPath, dstPath);
|
||||
|
||||
Hash h2 = hashPath(dstPath, htSHA256);
|
||||
if (h != h2)
|
||||
throw Error(format("contents of `%1%' changed while copying it to `%2%' (%3% -> %4%)")
|
||||
% srcPath % dstPath % (string) h % (string) h2);
|
||||
|
||||
makePathReadOnly(dstPath);
|
||||
|
||||
Transaction txn(nixDB);
|
||||
|
|
@ -457,11 +477,13 @@ Path addToStore(const Path & _srcPath)
|
|||
}
|
||||
|
||||
|
||||
void addTextToStore(const Path & dstPath, const string & s)
|
||||
Path addTextToStore(const string & suffix, const string & s)
|
||||
{
|
||||
assertStorePath(dstPath);
|
||||
Hash hash = hashString(s, htSHA256);
|
||||
|
||||
Path dstPath = makeStorePath("text", hash, suffix);
|
||||
|
||||
if (!isValidPath(dstPath)) {
|
||||
if (!readOnlyMode && !isValidPath(dstPath)) {
|
||||
|
||||
PathSet lockPaths;
|
||||
lockPaths.insert(dstPath);
|
||||
|
|
@ -482,6 +504,8 @@ void addTextToStore(const Path & dstPath, const string & s)
|
|||
|
||||
outputLock.setDeletion(true);
|
||||
}
|
||||
|
||||
return dstPath;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -81,14 +81,17 @@ void assertStorePath(const Path & path);
|
|||
/* Checks whether a path is valid. */
|
||||
bool isValidPath(const Path & path);
|
||||
|
||||
/* Constructs a unique store path name. */
|
||||
Path makeStorePath(const string & type,
|
||||
Hash & hash, const string & suffix);
|
||||
|
||||
/* Copy the contents of a path to the store and register the validity
|
||||
the resulting path. The resulting path is returned. */
|
||||
Path addToStore(const Path & srcPath);
|
||||
|
||||
/* Like addToStore, but the path of the output is given, and the
|
||||
contents written to the output path is a regular file containing
|
||||
the given string. */
|
||||
void addTextToStore(const Path & dstPath, const string & s);
|
||||
/* Like addToStore, but the contents written to the output path is a
|
||||
regular file containing the given string. */
|
||||
Path addTextToStore(const string & suffix, const string & s);
|
||||
|
||||
/* Delete a value from the nixStore directory. */
|
||||
void deleteFromStore(const Path & path);
|
||||
|
|
|
|||
|
|
@ -14,19 +14,9 @@ Hash hashTerm(ATerm t)
|
|||
|
||||
Path writeTerm(ATerm t, const string & suffix)
|
||||
{
|
||||
/* The id of a term is its hash. */
|
||||
Hash h = hashTerm(t);
|
||||
|
||||
Path path = canonPath(nixStore + "/" +
|
||||
(string) h + suffix + ".store");
|
||||
|
||||
if (!readOnlyMode && !isValidPath(path)) {
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error(format("cannot write aterm to `%1%'") % path);
|
||||
addTextToStore(path, string(s));
|
||||
}
|
||||
|
||||
return path;
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error("cannot print aterm");
|
||||
return addTextToStore(suffix + ".store", string(s));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue