aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-12 15:26:30 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2020-07-12 15:40:14 +0000
commit18152406ce9db9491385f2e67da6f7f78e8d98d5 (patch)
treeab5d8caa50780fd47805aece9e92f00faea1dc3b /src/libstore
parent5d0b75e5b6a1c70203257fecc25743e5a1e009cb (diff)
String .drv suffix to create derivation name
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/daemon.cc2
-rw-r--r--src/libstore/derivations.cc11
-rw-r--r--src/libstore/derivations.hh2
3 files changed, 13 insertions, 2 deletions
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index 4cf67064a..2ff53c964 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -474,7 +474,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopBuildDerivation: {
auto drvPath = store->parseStorePath(readString(from));
BasicDerivation drv;
- readDerivation(from, *store, drv, std::string(drvPath.name()));
+ readDerivation(from, *store, drv, Derivation::nameFromPath(drvPath));
BuildMode buildMode = (BuildMode) readInt(from);
logger->startWork();
if (!trusted)
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 97fd21885..a85a70c0a 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -218,7 +218,7 @@ Derivation Store::readDerivation(const StorePath & drvPath)
{
auto accessor = getFSAccessor();
try {
- return parseDerivation(*this, accessor->readFile(printStorePath(drvPath)), std::string(drvPath.name()));
+ return parseDerivation(*this, accessor->readFile(printStorePath(drvPath)), Derivation::nameFromPath(drvPath));
} catch (FormatError & e) {
throw Error("error parsing derivation '%s': %s", printStorePath(drvPath), e.msg());
}
@@ -465,6 +465,15 @@ StringSet BasicDerivation::outputNames() const
}
+std::string_view BasicDerivation::nameFromPath(const StorePath & drvPath) {
+ auto nameWithSuffix = drvPath.name();
+ constexpr std::string_view extension = ".drv";
+ assert(hasSuffix(nameWithSuffix, extension));
+ nameWithSuffix.remove_suffix(extension.size());
+ return nameWithSuffix;
+}
+
+
Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv, std::string_view name)
{
drv.name = name;
diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh
index 81c196ff7..6d3b54d3f 100644
--- a/src/libstore/derivations.hh
+++ b/src/libstore/derivations.hh
@@ -64,6 +64,8 @@ struct BasicDerivation
/* Return the output names of a derivation. */
StringSet outputNames() const;
+
+ static std::string_view nameFromPath(const StorePath & storePath);
};
struct Derivation : BasicDerivation