aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libstore/derivations.cc5
-rw-r--r--src/libstore/derivations.hh15
-rw-r--r--src/libstore/file-hash.cc27
-rw-r--r--src/libstore/file-hash.hh34
-rw-r--r--src/libstore/path.hh5
-rw-r--r--src/libstore/store-api.cc19
-rw-r--r--src/libstore/store-api.hh10
-rw-r--r--src/nix/hash.cc1
8 files changed, 64 insertions, 52 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index ad4d02c2c..f1569bf22 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -8,11 +8,6 @@
namespace nix {
-std::string FileSystemHash::printMethodAlgo() const {
- return makeFileIngestionPrefix(method) + printHashType(hash.type);
-}
-
-
BasicDerivation::BasicDerivation(const BasicDerivation & other)
: platform(other.platform)
, builder(other.builder)
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 5fc3b37da..e314beac1 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -3,6 +3,7 @@
#include "path.hh"
#include "types.hh"
#include "hash.hh"
+#include "file-hash.hh"
#include <map>
@@ -12,20 +13,6 @@ namespace nix {
/* Abstract syntax of derivations. */
-/// Pair of a hash, and how the file system was ingested
-struct FileSystemHash {
- FileIngestionMethod method;
- Hash hash;
- FileSystemHash(FileIngestionMethod method, Hash hash)
- : method(std::move(method))
- , hash(std::move(hash))
- { }
- FileSystemHash(const FileSystemHash &) = default;
- FileSystemHash(FileSystemHash &&) = default;
- FileSystemHash & operator = (const FileSystemHash &) = default;
- std::string printMethodAlgo() const;
-};
-
struct DerivationOutput
{
StorePath path;
diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc
new file mode 100644
index 000000000..549540db2
--- /dev/null
+++ b/src/libstore/file-hash.cc
@@ -0,0 +1,27 @@
+#include "file-hash.hh"
+
+namespace nix {
+
+std::string FileSystemHash::printMethodAlgo() const {
+ return makeFileIngestionPrefix(method) + printHashType(hash.type);
+}
+
+std::string makeFileIngestionPrefix(const FileIngestionMethod m) {
+ switch (m) {
+ case FileIngestionMethod::Flat:
+ return "";
+ case FileIngestionMethod::Recursive:
+ return "r:";
+ default:
+ throw Error("impossible, caught both cases");
+ }
+}
+
+std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
+{
+ return "fixed:"
+ + makeFileIngestionPrefix(method)
+ + hash.to_string();
+}
+
+}
diff --git a/src/libstore/file-hash.hh b/src/libstore/file-hash.hh
new file mode 100644
index 000000000..94122db07
--- /dev/null
+++ b/src/libstore/file-hash.hh
@@ -0,0 +1,34 @@
+#pragma once
+
+#include "hash.hh"
+
+namespace nix {
+
+enum struct FileIngestionMethod : uint8_t {
+ Flat = false,
+ Recursive = true
+};
+
+/// Pair of a hash, and how the file system was ingested
+struct FileSystemHash {
+ FileIngestionMethod method;
+ Hash hash;
+ FileSystemHash(FileIngestionMethod method, Hash hash)
+ : method(std::move(method))
+ , hash(std::move(hash))
+ { }
+ FileSystemHash(const FileSystemHash &) = default;
+ FileSystemHash(FileSystemHash &&) = default;
+ FileSystemHash & operator = (const FileSystemHash &) = default;
+ std::string printMethodAlgo() const;
+};
+
+/* Compute the prefix to the hash algorithm which indicates how the files were
+ ingested. */
+std::string makeFileIngestionPrefix(const FileIngestionMethod m);
+
+/* Compute the content-addressability assertion (ValidPathInfo::ca)
+ for paths created by makeFixedOutputPath() / addToStore(). */
+std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash);
+
+}
diff --git a/src/libstore/path.hh b/src/libstore/path.hh
index f3ed6ca39..186976855 100644
--- a/src/libstore/path.hh
+++ b/src/libstore/path.hh
@@ -87,11 +87,6 @@ const size_t storePathHashLen = 32; // i.e. 160 bits
/* Extension of derivations in the Nix store. */
const std::string drvExtension = ".drv";
-enum struct FileIngestionMethod : uint8_t {
- Flat = false,
- Recursive = true
-};
-
struct StorePathWithOutputs
{
StorePath path;
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index b7ba9e4f2..3c72dc56f 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -814,25 +814,6 @@ Strings ValidPathInfo::shortRefs() const
}
-std::string makeFileIngestionPrefix(const FileIngestionMethod m) {
- switch (m) {
- case FileIngestionMethod::Flat:
- return "";
- case FileIngestionMethod::Recursive:
- return "r:";
- default:
- throw Error("impossible, caught both cases");
- }
-}
-
-std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash)
-{
- return "fixed:"
- + makeFileIngestionPrefix(method)
- + hash.to_string();
-}
-
-
void Store::addToStore(const ValidPathInfo & info, Source & narSource,
RepairFlag repair, CheckSigsFlag checkSigs,
std::shared_ptr<FSAccessor> accessor)
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 598798570..d89e10c94 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -2,6 +2,7 @@
#include "path.hh"
#include "hash.hh"
+#include "file-hash.hh"
#include "serialise.hh"
#include "crypto.hh"
#include "lru-cache.hh"
@@ -846,15 +847,6 @@ std::optional<ValidPathInfo> decodeValidPathInfo(
std::istream & str,
bool hashGiven = false);
-/* Compute the prefix to the hash algorithm which indicates how the files were
- ingested. */
-std::string makeFileIngestionPrefix(const FileIngestionMethod m);
-
-/* Compute the content-addressability assertion (ValidPathInfo::ca)
- for paths created by makeFixedOutputPath() / addToStore(). */
-std::string makeFixedOutputCA(FileIngestionMethod method, const Hash & hash);
-
-
/* Split URI into protocol+hierarchy part and its parameter set. */
std::pair<std::string, Store::Params> splitUriAndParams(const std::string & uri);
diff --git a/src/nix/hash.cc b/src/nix/hash.cc
index 3362ffd0d..ec23b77bc 100644
--- a/src/nix/hash.cc
+++ b/src/nix/hash.cc
@@ -1,5 +1,6 @@
#include "command.hh"
#include "hash.hh"
+#include "file-hash.hh"
#include "legacy.hh"
#include "shared.hh"
#include "references.hh"