From bcde5456cc3295061a0726881c3e441444dd6680 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 21 Mar 2020 11:07:16 -0400 Subject: Flip dependency so store-api.hh includes derivations.hh I think it makes more sense to define the data model (derivations), before the operations (store api). --- src/libstore/store-api.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..396709633 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -8,6 +8,7 @@ #include "sync.hh" #include "globals.hh" #include "config.hh" +#include "derivations.hh" #include #include @@ -30,15 +31,12 @@ MakeError(SubstituteGone, Error); MakeError(SubstituterDisabled, Error); -struct BasicDerivation; -struct Derivation; class FSAccessor; class NarInfoDiskCache; class Store; class JSONPlaceholder; -enum RepairFlag : bool { NoRepair = false, Repair = true }; enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true }; enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true }; enum AllowInvalidFlag : bool { DisallowInvalid = false, AllowInvalid = true }; -- cgit v1.2.3 From e433d4af4cf78c88dc0cb3e8139e835470b72fd3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 22 Mar 2020 23:43:07 -0400 Subject: Extend Rust FFI Do idiomatic C++ copy and move constructors for a few things, so wrapping structs' defaults can work. --- src/libstore/store-api.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..0237d0b04 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -189,8 +189,9 @@ struct ValidPathInfo Strings shortRefs() const; - ValidPathInfo(StorePath && path) : path(std::move(path)) { } - explicit ValidPathInfo(const ValidPathInfo & other); + ValidPathInfo(StorePath && path) : path(std::move(path)) { }; + ValidPathInfo(const StorePath & path) : path(path) { }; + ValidPathInfo(const ValidPathInfo & other) = default; virtual ~ValidPathInfo() { } }; -- cgit v1.2.3 From 87b32bab05ff91981c8847d66cd5502feb44f3b5 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Mar 2020 23:22:10 +0000 Subject: Use `enum struct` and drop prefixes This does a few enums; the rest will be gotten in subsequent commits. --- src/libstore/store-api.hh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0fa59be6a..4247367b5 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -359,7 +359,7 @@ public: path and the cryptographic hash of the contents of srcPath. */ std::pair computeStorePathForPath(std::string_view name, const Path & srcPath, bool recursive = true, - HashType hashAlgo = htSHA256, PathFilter & filter = defaultPathFilter) const; + HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter) const; /* Preparatory part of addTextToStore(). @@ -462,12 +462,12 @@ public: The function object `filter' can be used to exclude files (see libutil/archive.hh). */ virtual StorePath addToStore(const string & name, const Path & srcPath, - bool recursive = true, HashType hashAlgo = htSHA256, + bool recursive = true, HashType hashAlgo = HashType::SHA256, PathFilter & filter = defaultPathFilter, RepairFlag repair = NoRepair) = 0; // FIXME: remove? virtual StorePath addToStoreFromDump(const string & dump, const string & name, - bool recursive = true, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair) + bool recursive = true, HashType hashAlgo = HashType::SHA256, RepairFlag repair = NoRepair) { throw Error("addToStoreFromDump() is not supported by this store"); } @@ -561,7 +561,7 @@ public: each path is included. */ void pathInfoToJSON(JSONPlaceholder & jsonOut, const StorePathSet & storePaths, bool includeImpureInfo, bool showClosureSize, - Base hashBase = Base32, + Base hashBase = Base::Base32, AllowInvalidFlag allowInvalid = DisallowInvalid); /* Return the size of the closure of the specified path, that is, -- cgit v1.2.3 From 832bd534dc0ab36fd8267f62b67ab1db1498d2b4 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 22 Mar 2020 23:43:07 -0400 Subject: Store parsed hashes in `DerivationOutput` It's best to detect invalid data as soon as possible, with data types that make storing it impossible. --- src/libstore/store-api.hh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index a4fdad8c4..ef15e60ec 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -847,6 +847,9 @@ std::optional 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(). */ -- cgit v1.2.3 From 0e9438b6d381a87946ddda8d4bdd06707f9b0a48 Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Mon, 1 Jun 2020 17:32:27 -0400 Subject: Create new file-hash files --- src/libstore/store-api.hh | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'src/libstore/store-api.hh') 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 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 splitUriAndParams(const std::string & uri); -- cgit v1.2.3 From da39092a39bbcca80144041b5efc8428cc3b2e4a Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Mon, 1 Jun 2020 18:53:31 -0400 Subject: WIP --- src/libstore/store-api.hh | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index d89e10c94..1f1c1e0eb 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -19,6 +19,7 @@ #include #include #include +#include namespace nix { @@ -110,6 +111,19 @@ struct SubstitutablePathInfo typedef std::map SubstitutablePathInfos; +template struct overloaded : Ts... { using Ts::operator()...; }; +template overloaded(Ts...) -> overloaded; + +std::string renderContentAddress(ContentAddress ca) { + return std::visit(overloaded { + [](Hash hash) { + return "text:" + hash.to_string(); + }, + [](FileSystemHash fsh) { + return makeFixedOutputCA(fsh.method, fsh.hash); + } + }, ca); +} struct ValidPathInfo { @@ -139,21 +153,11 @@ struct ValidPathInfo that a particular output path was produced by a derivation; the path then implies the contents.) - Ideally, the content-addressability assertion would just be a - Boolean, and the store path would be computed from - the name component, ‘narHash’ and ‘references’. However, - 1) we've accumulated several types of content-addressed paths - over the years; and 2) fixed-output derivations support - multiple hash algorithms and serialisation methods (flat file - vs NAR). Thus, ‘ca’ has one of the following forms: - - * ‘text:sha256:’: For paths - computed by makeTextPath() / addTextToStore(). - - * ‘fixed:::’: For paths computed by - makeFixedOutputPath() / addToStore(). + Ideally, the content-addressability assertion would just be a Boolean, + and the store path would be computed from the name component, ‘narHash’ + and ‘references’. However, we support many types of content addresses. */ - std::string ca; + std::optional ca; bool operator == (const ValidPathInfo & i) const { -- cgit v1.2.3 From 754c910953901ced4fbd27a8b86d36d57cb72996 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 1 Jun 2020 19:26:40 -0400 Subject: WIP more progress --- src/libstore/store-api.hh | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 1f1c1e0eb..faf549fe1 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -111,20 +111,6 @@ struct SubstitutablePathInfo typedef std::map SubstitutablePathInfos; -template struct overloaded : Ts... { using Ts::operator()...; }; -template overloaded(Ts...) -> overloaded; - -std::string renderContentAddress(ContentAddress ca) { - return std::visit(overloaded { - [](Hash hash) { - return "text:" + hash.to_string(); - }, - [](FileSystemHash fsh) { - return makeFixedOutputCA(fsh.method, fsh.hash); - } - }, ca); -} - struct ValidPathInfo { StorePath path; -- cgit v1.2.3 From fd2eb41e6433e72516ae149949b8b0050305293d Mon Sep 17 00:00:00 2001 From: Carlo Nucera Date: Tue, 2 Jun 2020 15:44:58 -0400 Subject: Move file-hash to content-address --- src/libstore/store-api.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstore/store-api.hh') diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 7836c04dc..441e3efc5 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -2,7 +2,7 @@ #include "path.hh" #include "hash.hh" -#include "file-hash.hh" +#include "content-address.hh" #include "serialise.hh" #include "crypto.hh" #include "lru-cache.hh" -- cgit v1.2.3