* Pass HashType values instead of strings.
This commit is contained in:
parent
1307b22223
commit
ff762fb499
11 changed files with 36 additions and 23 deletions
|
|
@ -656,7 +656,7 @@ void LocalStore::invalidatePath(const Path & path)
|
|||
|
||||
|
||||
Path LocalStore::addToStore(const Path & _srcPath,
|
||||
bool recursive, string hashAlgo, PathFilter & filter)
|
||||
bool recursive, HashType hashAlgo, PathFilter & filter)
|
||||
{
|
||||
Path srcPath(absPath(_srcPath));
|
||||
debug(format("adding `%1%' to the store") % srcPath);
|
||||
|
|
@ -670,7 +670,7 @@ Path LocalStore::addToStore(const Path & _srcPath,
|
|||
else
|
||||
sink.s = readFile(srcPath);
|
||||
|
||||
Hash h = hashString(parseHashType(hashAlgo), sink.s);
|
||||
Hash h = hashString(hashAlgo, sink.s);
|
||||
|
||||
Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, baseNameOf(srcPath));
|
||||
|
||||
|
|
@ -700,7 +700,7 @@ Path LocalStore::addToStore(const Path & _srcPath,
|
|||
above (if called with recursive == true and hashAlgo ==
|
||||
sha256); otherwise, compute it here. */
|
||||
registerValidPath(dstPath,
|
||||
(recursive && hashAlgo == "sha256") ? h :
|
||||
(recursive && hashAlgo == htSHA256) ? h :
|
||||
(recursive ? hashString(htSHA256, sink.s) : hashPath(htSHA256, dstPath)),
|
||||
PathSet(), "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public:
|
|||
const Path & path, SubstitutablePathInfo & info);
|
||||
|
||||
Path addToStore(const Path & srcPath,
|
||||
bool recursive = true, string hashAlgo = "sha256",
|
||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
||||
PathFilter & filter = defaultPathFilter);
|
||||
|
||||
Path addTextToStore(const string & name, const string & s,
|
||||
|
|
|
|||
|
|
@ -279,16 +279,16 @@ Path RemoteStore::queryDeriver(const Path & path)
|
|||
|
||||
|
||||
Path RemoteStore::addToStore(const Path & _srcPath,
|
||||
bool recursive, string hashAlgo, PathFilter & filter)
|
||||
bool recursive, HashType hashAlgo, PathFilter & filter)
|
||||
{
|
||||
Path srcPath(absPath(_srcPath));
|
||||
|
||||
writeInt(wopAddToStore, to);
|
||||
writeString(baseNameOf(srcPath), to);
|
||||
/* backwards compatibility hack */
|
||||
writeInt((hashAlgo == "sha256" && recursive) ? 0 : 1, to);
|
||||
writeInt((hashAlgo == htSHA256 && recursive) ? 0 : 1, to);
|
||||
writeInt(recursive ? 1 : 0, to);
|
||||
writeString(hashAlgo, to);
|
||||
writeString(printHashType(hashAlgo), to);
|
||||
dumpPath(srcPath, to, filter);
|
||||
processStderr();
|
||||
return readStorePath(from);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public:
|
|||
SubstitutablePathInfo & info);
|
||||
|
||||
Path addToStore(const Path & srcPath,
|
||||
bool recursive = true, string hashAlgo = "sha256",
|
||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
||||
PathFilter & filter = defaultPathFilter);
|
||||
|
||||
Path addTextToStore(const string & name, const string & s,
|
||||
|
|
|
|||
|
|
@ -183,20 +183,21 @@ Path makeStorePath(const string & type,
|
|||
|
||||
|
||||
Path makeFixedOutputPath(bool recursive,
|
||||
string hashAlgo, Hash hash, string name)
|
||||
HashType hashAlgo, Hash hash, string name)
|
||||
{
|
||||
return hashAlgo == "sha256" && recursive
|
||||
return hashAlgo == htSHA256 && recursive
|
||||
? makeStorePath("source", hash, name)
|
||||
: makeStorePath("output:out", hashString(htSHA256,
|
||||
"fixed:out:" + (recursive ? (string) "r:" : "") + hashAlgo + ":" + printHash(hash) + ":"),
|
||||
"fixed:out:" + (recursive ? (string) "r:" : "") +
|
||||
printHashType(hashAlgo) + ":" + printHash(hash) + ":"),
|
||||
name);
|
||||
}
|
||||
|
||||
|
||||
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
||||
bool recursive, string hashAlgo, PathFilter & filter)
|
||||
bool recursive, HashType hashAlgo, PathFilter & filter)
|
||||
{
|
||||
HashType ht(parseHashType(hashAlgo));
|
||||
HashType ht(hashAlgo);
|
||||
Hash h = recursive ? hashPath(ht, srcPath, filter) : hashFile(ht, srcPath);
|
||||
string name = baseNameOf(srcPath);
|
||||
Path dstPath = makeFixedOutputPath(recursive, hashAlgo, h, name);
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ public:
|
|||
object `filter' can be used to exclude files (see
|
||||
libutil/archive.hh). */
|
||||
virtual Path addToStore(const Path & srcPath,
|
||||
bool recursive = true, string hashAlgo = "sha256",
|
||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
||||
PathFilter & filter = defaultPathFilter) = 0;
|
||||
|
||||
/* Like addToStore, but the contents written to the output path is
|
||||
|
|
@ -277,7 +277,7 @@ Path makeStorePath(const string & type,
|
|||
const Hash & hash, const string & name);
|
||||
|
||||
Path makeFixedOutputPath(bool recursive,
|
||||
string hashAlgo, Hash hash, string name);
|
||||
HashType hashAlgo, Hash hash, string name);
|
||||
|
||||
|
||||
/* This is the preparatory part of addToStore() and addToStoreFixed();
|
||||
|
|
@ -285,7 +285,7 @@ Path makeFixedOutputPath(bool recursive,
|
|||
Returns the store path and the cryptographic hash of the
|
||||
contents of srcPath. */
|
||||
std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath,
|
||||
bool recursive = true, string hashAlgo = "sha256",
|
||||
bool recursive = true, HashType hashAlgo = htSHA256,
|
||||
PathFilter & filter = defaultPathFilter);
|
||||
|
||||
/* Preparatory part of addTextToStore().
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue