aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/derived-path.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-14 20:45:11 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-14 20:45:11 -0400
commitee420ac64e7d1f51f5abcb069dbe84cd6ff707ce (patch)
tree98668c4cdac6640aee90a86acd644aaad862bb71 /src/libstore/derived-path.cc
parent9e8f2090365a509656dead69bc91fb6615cf9d05 (diff)
Legacy vs non-legacy `to_string`/`parse` for `DerivedPath`
As requested by @roberth, it is good to call out the specific instances we care about, which is `!` for the RPC protocols, and `^` for humans. This doesn't take advantage of parametricity as much, but since the human and computer interfaces are good to decouple anyways (we don't care if they drift further apart over time in the slightest) some separation and slight duplication is fine. Also, unit test both round trips.
Diffstat (limited to 'src/libstore/derived-path.cc')
-rw-r--r--src/libstore/derived-path.cc37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/libstore/derived-path.cc b/src/libstore/derived-path.cc
index 6baca70a3..9a2ffda39 100644
--- a/src/libstore/derived-path.cc
+++ b/src/libstore/derived-path.cc
@@ -59,17 +59,32 @@ std::string DerivedPath::Opaque::to_string(const Store & store) const
return store.printStorePath(path);
}
-std::string DerivedPath::Built::to_string(const Store & store, char separator) const
+std::string DerivedPath::Built::to_string(const Store & store) const
{
return store.printStorePath(drvPath)
- + separator
+ + '^'
+ outputs.to_string();
}
-std::string DerivedPath::to_string(const Store & store, char separator) const
+std::string DerivedPath::Built::to_string_legacy(const Store & store) const
+{
+ return store.printStorePath(drvPath)
+ + '!'
+ + outputs.to_string();
+}
+
+std::string DerivedPath::to_string(const Store & store) const
{
return std::visit(overloaded {
- [&](const DerivedPath::Built & req) { return req.to_string(store, separator); },
+ [&](const DerivedPath::Built & req) { return req.to_string(store); },
+ [&](const DerivedPath::Opaque & req) { return req.to_string(store); },
+ }, this->raw());
+}
+
+std::string DerivedPath::to_string_legacy(const Store & store) const
+{
+ return std::visit(overloaded {
+ [&](const DerivedPath::Built & req) { return req.to_string_legacy(store); },
[&](const DerivedPath::Opaque & req) { return req.to_string(store); },
}, this->raw());
}
@@ -88,14 +103,24 @@ DerivedPath::Built DerivedPath::Built::parse(const Store & store, std::string_vi
};
}
-DerivedPath DerivedPath::parse(const Store & store, std::string_view s)
+static inline DerivedPath parseWith(const Store & store, std::string_view s, std::string_view separator)
{
- size_t n = s.find("!");
+ size_t n = s.find(separator);
return n == s.npos
? (DerivedPath) DerivedPath::Opaque::parse(store, s)
: (DerivedPath) DerivedPath::Built::parse(store, s.substr(0, n), s.substr(n + 1));
}
+DerivedPath DerivedPath::parse(const Store & store, std::string_view s)
+{
+ return parseWith(store, s, "^");
+}
+
+DerivedPath DerivedPath::parseLegacy(const Store & store, std::string_view s)
+{
+ return parseWith(store, s, "!");
+}
+
RealisedPath::Set BuiltPath::toRealisedPaths(Store & store) const
{
RealisedPath::Set res;