@@ -577,7 +577,7 @@ void LocalStore::checkDerivationOutputs(const StorePath & drvPath, const Derivat
577
577
uint64_t LocalStore::addValidPath (State & state,
578
578
const ValidPathInfo & info, bool checkOutputs)
579
579
{
580
- if (info.ca != " " && !info.isContentAddressed (*this ))
580
+ if (info.ca . has_value () && !info.isContentAddressed (*this ))
581
581
throw Error (" cannot add path '%s' to the Nix store because it claims to be content-addressed but isn't" ,
582
582
printStorePath (info.path ));
583
583
@@ -589,7 +589,7 @@ uint64_t LocalStore::addValidPath(State & state,
589
589
(info.narSize , info.narSize != 0 )
590
590
(info.ultimate ? 1 : 0 , info.ultimate )
591
591
(concatStringsSep (" " , info.sigs ), !info.sigs .empty ())
592
- (info.ca , ! info.ca . empty () )
592
+ (renderContentAddress ( info.ca ), ( bool ) info.ca )
593
593
.exec ();
594
594
uint64_t id = sqlite3_last_insert_rowid (state.db );
595
595
@@ -663,7 +663,7 @@ void LocalStore::queryPathInfoUncached(const StorePath & path,
663
663
if (s) info->sigs = tokenizeString<StringSet>(s, " " );
664
664
665
665
s = (const char *) sqlite3_column_text (state->stmtQueryPathInfo , 7 );
666
- if (s) info->ca = s ;
666
+ if (s) info->ca = parseContentAddressOpt (s) ;
667
667
668
668
/* Get the references. */
669
669
auto useQueryReferences (state->stmtQueryReferences .use ()(info->id ));
@@ -686,7 +686,7 @@ void LocalStore::updatePathInfo(State & state, const ValidPathInfo & info)
686
686
(info.narHash .to_string (Base::Base16))
687
687
(info.ultimate ? 1 : 0 , info.ultimate )
688
688
(concatStringsSep (" " , info.sigs ), !info.sigs .empty ())
689
- (info.ca , ! info.ca . empty () )
689
+ (renderContentAddress ( info.ca ), ( bool ) info.ca )
690
690
(printStorePath (info.path ))
691
691
.exec ();
692
692
}
@@ -1000,15 +1000,15 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
1000
1000
1001
1001
deletePath (realPath);
1002
1002
1003
- if (info. ca != " " &&
1004
- !(( hasPrefix ( info.ca , " text: " ) && !info. references .count (info.path ))
1005
- || info.references .empty ()))
1003
+ // text hashing has long been allowed to have non-self-references because it is used for drv files.
1004
+ bool refersToSelf = info.references .count (info.path ) > 0 ;
1005
+ if (info. ca . has_value () && ! info.references .empty () && !(std::holds_alternative<TextHash>(*info. ca ) && !refersToSelf ))
1006
1006
settings.requireExperimentalFeature (" ca-references" );
1007
1007
1008
1008
/* While restoring the path from the NAR, compute the hash
1009
1009
of the NAR. */
1010
1010
std::unique_ptr<AbstractHashSink> hashSink;
1011
- if (info.ca == " " || !info.references .count (info.path ))
1011
+ if (! info.ca . has_value () || !info.references .count (info.path ))
1012
1012
hashSink = std::make_unique<HashSink>(HashType::SHA256);
1013
1013
else
1014
1014
hashSink = std::make_unique<HashModuloSink>(HashType::SHA256, storePathToHash (printStorePath (info.path )));
@@ -1019,7 +1019,8 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
1019
1019
return n;
1020
1020
});
1021
1021
1022
- if (hasPrefix (info.ca , " fixed:git:" ))
1022
+ auto p = info.ca ? std::get_if<FileSystemHash>(&*info.ca ) : NULL ;
1023
+ if (p && p->method == FileIngestionMethod::Git)
1023
1024
restoreGit (realPath, wrapperSource, realStoreDir, storeDir);
1024
1025
else
1025
1026
restorePath (realPath, wrapperSource);
@@ -1110,7 +1111,7 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam
1110
1111
ValidPathInfo info (dstPath.clone ());
1111
1112
info.narHash = hash.first ;
1112
1113
info.narSize = hash.second ;
1113
- info.ca = makeFixedOutputCA ( method, h) ;
1114
+ info.ca = FileSystemHash { method, h } ;
1114
1115
registerValidPath (info);
1115
1116
}
1116
1117
@@ -1195,7 +1196,7 @@ StorePath LocalStore::addTextToStore(const string & name, const string & s,
1195
1196
info.narHash = narHash;
1196
1197
info.narSize = sink.s ->size ();
1197
1198
info.references = cloneStorePathSet (references);
1198
- info.ca = " text: " + hash. to_string () ;
1199
+ info.ca = TextHash { . hash = hash } ;
1199
1200
registerValidPath (info);
1200
1201
}
1201
1202
@@ -1303,7 +1304,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
1303
1304
printMsg (Verbosity::Talkative, " checking contents of '%s'" , printStorePath (i));
1304
1305
1305
1306
std::unique_ptr<AbstractHashSink> hashSink;
1306
- if (info->ca == " " || !info->references .count (info->path ))
1307
+ if (! info->ca || !info->references .count (info->path ))
1307
1308
hashSink = std::make_unique<HashSink>(*info->narHash .type );
1308
1309
else
1309
1310
hashSink = std::make_unique<HashModuloSink>(*info->narHash .type , storePathToHash (printStorePath (info->path )));
0 commit comments