aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-06-02 15:18:05 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-06-02 15:23:21 -0400
commit343c20a404055d266227b7562f775f7fad37103f (patch)
treebaed8604f051f20f7810b6c0f7720034d6274eb2 /src
parent390bf64858e03b948a9b65fe138b34dd2776f8ef (diff)
WIP Completed implementation
Diffstat (limited to 'src')
-rw-r--r--src/libstore/file-hash.cc48
1 files changed, 8 insertions, 40 deletions
diff --git a/src/libstore/file-hash.cc b/src/libstore/file-hash.cc
index 9cae8f80e..caf9a83e9 100644
--- a/src/libstore/file-hash.cc
+++ b/src/libstore/file-hash.cc
@@ -45,55 +45,23 @@ ContentAddress parseContentAddress(std::string_view rawCa) {
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";
- }
+ return TextHash { Hash(string(hashTypeAndHash)) };
} else if (prefix == "fixed") {
+ // This has to be an inverse to makeFixedOutputCA
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, }
+ return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
+ } else {
+ std::string_view hashRaw = methodAndHash;
+ return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
}
-
-
-
- // break;
- // } else {
- // throw "parseContentAddress: invalid prefix";
+ } else {
+ throw "parseContentAddress: format not recognized; has to be text or fixed";
}
-
} 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) {