diff options
author | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-06-02 14:15:38 -0400 |
---|---|---|
committer | Carlo Nucera <carlo.nucera@protonmail.com> | 2020-06-02 14:15:58 -0400 |
commit | 390bf64858e03b948a9b65fe138b34dd2776f8ef (patch) | |
tree | 0144a30c916ddd255a3cd566153bccb0f74cda27 | |
parent | a33270ce1d815069d3fec43225a10e33c8e94287 (diff) |
WIP
-rw-r--r-- | src/libstore/derivations.hh | 1 | ||||
-rw-r--r-- | src/libstore/file-hash.cc | 55 |
2 files changed, 54 insertions, 2 deletions
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index e314beac1..dba9318d9 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -24,7 +24,6 @@ struct DerivationOutput DerivationOutput(const DerivationOutput &) = default; DerivationOutput(DerivationOutput &&) = default; DerivationOutput & operator = (const DerivationOutput &) = default; - void parseHashInfo(FileIngestionMethod & recursive, Hash & hash) const; }; typedef std::map<string, DerivationOutput> DerivationOutputs; diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc index 4a3280653..9cae8f80e 100644 --- a/src/libstore/file-hash.cc +++ b/src/libstore/file-hash.cc @@ -40,7 +40,60 @@ std::string renderContentAddress(ContentAddress ca) { } ContentAddress parseContentAddress(std::string_view rawCa) { - throw Error("TODO"); + auto prefixSeparator = rawCa.find(':'); + if (prefixSeparator != string::npos) { + auto prefix = string(rawCa, 0, prefixSeparator); + if (prefix == "text") { + auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos); + auto hashSeparator = hashTypeAndHash.find(':'); + if (hashSeparator != string::npos) { + std::string_view hashTypeRaw = hashTypeAndHash.substr(0, hashSeparator); + std::string_view hashRaw = hashTypeAndHash.substr(hashSeparator+1, string::npos); + auto hashType = parseHashType(string(hashTypeRaw)); + return TextHash { Hash(string(hashRaw), hashType) }; + } else { + throw "parseContentAddress: hash type not found"; + } + } else if (prefix == "fixed") { + auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos); + if (methodAndHash.substr(0,2) == "r:") { + std::string_view hashRaw = methodAndHash.substr(2,string::npos); + return FileSystemHash { FileIngestionMethod::Recursive, } + } + + + + // break; + // } else { + // throw "parseContentAddress: invalid prefix"; + } + + } else { + throw "Not a content address because it lacks an appropriate prefix"; + } + + + + // if (getString(rawCa, 5) == "text:") { + // auto hashTypeAndHash = string::substr(5, string::npos); + // auto sep = hashTypeAndHash.find(':'); + // if (sep != string::npos) { + // string hashTypeRaw = string(hashTypeAndHash, 0, sep); + // auto hashType = parseHashType(hashTypeRaw); + // } + // break; + + // // } else if (getString (rawCa, 6) = "fixed:") { + // } else if (true) { + // break; + // } + + // auto sep = rawCa.find(':'); + // if (sep == string::npos) + // if(string(rawCa, 5) == "text:") { + // break; + // } else if {} + // throw Error("TODO"); }; std::optional<ContentAddress> parseContentAddressOpt(std::string_view rawCaOpt) { |