aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/add-to-store.cc10
-rw-r--r--src/nix/hash.cc30
-rw-r--r--src/nix/make-content-addressable.cc4
-rw-r--r--src/nix/profile.cc7
4 files changed, 31 insertions, 20 deletions
diff --git a/src/nix/add-to-store.cc b/src/nix/add-to-store.cc
index 1d298903b..f43f774c1 100644
--- a/src/nix/add-to-store.cc
+++ b/src/nix/add-to-store.cc
@@ -45,13 +45,15 @@ struct CmdAddToStore : MixDryRun, StoreCommand
auto narHash = hashString(htSHA256, *sink.s);
- ValidPathInfo info(store->makeFixedOutputPath(true, narHash, *namePart));
+ ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, *namePart));
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(true, info.narHash);
+ info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
- if (!dryRun)
- store->addToStore(info, sink.s);
+ if (!dryRun) {
+ auto source = StringSource { *sink.s };
+ store->addToStore(info, source);
+ }
logger->stdout("%s", store->printStorePath(info.path));
}
diff --git a/src/nix/hash.cc b/src/nix/hash.cc
index d5636eb47..9e1d27f4c 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -9,15 +9,14 @@ using namespace nix;
struct CmdHash : Command
{
- enum Mode { mFile, mPath };
- Mode mode;
+ FileIngestionMethod mode;
Base base = SRI;
bool truncate = false;
HashType ht = htSHA256;
std::vector<std::string> paths;
std::optional<std::string> modulus;
- CmdHash(Mode mode) : mode(mode)
+ CmdHash(FileIngestionMethod mode) : mode(mode)
{
mkFlag(0, "sri", "print hash in SRI format", &base, SRI);
mkFlag(0, "base64", "print hash in base-64", &base, Base64);
@@ -40,9 +39,14 @@ struct CmdHash : Command
std::string description() override
{
- return mode == mFile
- ? "print cryptographic hash of a regular file"
- : "print cryptographic hash of the NAR serialisation of a path";
+ const char* d;
+ switch (mode) {
+ case FileIngestionMethod::Flat:
+ d = "print cryptographic hash of a regular file";
+ case FileIngestionMethod::Recursive:
+ d = "print cryptographic hash of the NAR serialisation of a path";
+ };
+ return d;
}
Category category() override { return catUtility; }
@@ -57,10 +61,14 @@ struct CmdHash : Command
else
hashSink = std::make_unique<HashSink>(ht);
- if (mode == mFile)
+ switch (mode) {
+ case FileIngestionMethod::Flat:
readFile(path, *hashSink);
- else
+ break;
+ case FileIngestionMethod::Recursive:
dumpPath(path, *hashSink);
+ break;
+ }
Hash h = hashSink->finish().first;
if (truncate && h.hashSize > 20) h = compressHash(h, 20);
@@ -69,8 +77,8 @@ struct CmdHash : Command
}
};
-static RegisterCommand r1("hash-file", [](){ return make_ref<CmdHash>(CmdHash::mFile); });
-static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(CmdHash::mPath); });
+static RegisterCommand r1("hash-file", [](){ return make_ref<CmdHash>(FileIngestionMethod::Flat); });
+static RegisterCommand r2("hash-path", [](){ return make_ref<CmdHash>(FileIngestionMethod::Recursive); });
struct CmdToBase : Command
{
@@ -141,7 +149,7 @@ static int compatNixHash(int argc, char * * argv)
});
if (op == opHash) {
- CmdHash cmd(flat ? CmdHash::mFile : CmdHash::mPath);
+ CmdHash cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
cmd.ht = ht;
cmd.base = base32 ? Base32 : Base16;
cmd.truncate = truncate;
diff --git a/src/nix/make-content-addressable.cc b/src/nix/make-content-addressable.cc
index 8803461f4..3e7ff544d 100644
--- a/src/nix/make-content-addressable.cc
+++ b/src/nix/make-content-addressable.cc
@@ -77,12 +77,12 @@ struct CmdMakeContentAddressable : StorePathsCommand, MixJSON
auto narHash = hashModuloSink.finish().first;
- ValidPathInfo info(store->makeFixedOutputPath(true, narHash, path.name(), references, hasSelfReference));
+ ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, path.name(), references, hasSelfReference));
info.references = std::move(references);
if (hasSelfReference) info.references.insert(info.path.clone());
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(true, info.narHash);
+ info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
if (!json)
printError("rewrote '%s' to '%s'", pathS, store->printStorePath(info.path));
diff --git a/src/nix/profile.cc b/src/nix/profile.cc
index f39213b8f..59cc745e2 100644
--- a/src/nix/profile.cc
+++ b/src/nix/profile.cc
@@ -128,13 +128,14 @@ struct ProfileManifest
auto narHash = hashString(htSHA256, *sink.s);
- ValidPathInfo info(store->makeFixedOutputPath(true, narHash, "profile", references));
+ ValidPathInfo info(store->makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, "profile", references));
info.references = std::move(references);
info.narHash = narHash;
info.narSize = sink.s->size();
- info.ca = makeFixedOutputCA(true, info.narHash);
+ info.ca = makeFixedOutputCA(FileIngestionMethod::Recursive, info.narHash);
- store->addToStore(info, sink.s);
+ auto source = StringSource { *sink.s };
+ store->addToStore(info, source);
return std::move(info.path);
}