* 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:
Eelco Dolstra 2003-07-11 08:41:03 +00:00
parent c834a5c597
commit 73b163c1a1
3 changed files with 9 additions and 9 deletions

View File

@ -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());
} }

View File

@ -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);
string baseName = baseNameOf(srcPath);
dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
try { try {
/* !!! should not use the substitutes! */ /* !!! should not use the substitutes! */
dstPath = expandHash(hash, "", nixStore); dstPath = expandHash(hash, deterministicName ? dstPath : "", nixStore);
return; return;
} catch (...) { } catch (...) {
} }
string baseName = baseNameOf(srcPath);
dstPath = canonPath(nixStore + "/" + (string) hash + "-" + baseName);
copyPath(srcPath, dstPath); copyPath(srcPath, dstPath);
registerPath(dstPath, hash); registerPath(dstPath, hash);
} }

View File

@ -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);