Skip to content

Commit

Permalink
Move StorePathWithOutput utilities out of store class
Browse files Browse the repository at this point in the history
These are by no means part of the notion of a store, but rather are
things that happen to use stores. (Or put another way, there's no way
we'd make them virtual methods any time soon.) It's better to move them
out of that too-big class then.

Also, this helps us remove StorePathWithOutputs from the Store interface
altogether next commit.
  • Loading branch information
Ericson2314 committed Mar 2, 2021
1 parent 3070415 commit 3ea534d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/get-drvs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DrvInfo::DrvInfo(EvalState & state, const string & attrPath, Bindings * attrs)
DrvInfo::DrvInfo(EvalState & state, ref<Store> store, const std::string & drvPathWithOutputs)
: state(&state), attrs(nullptr), attrPath("")
{
auto [drvPath, selectedOutputs] = store->parsePathWithOutputs(drvPathWithOutputs);
auto [drvPath, selectedOutputs] = parsePathWithOutputs(*store, drvPathWithOutputs);

this->drvPath = store->printStorePath(drvPath);

Expand Down
4 changes: 2 additions & 2 deletions src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopBuildPaths: {
std::vector<StorePathWithOutputs> drvs;
for (auto & s : readStrings<Strings>(from))
drvs.push_back(store->parsePathWithOutputs(s));
drvs.push_back(parsePathWithOutputs(*store, s));
BuildMode mode = bmNormal;
if (GET_PROTOCOL_MINOR(clientVersion) >= 15) {
mode = (BuildMode) readInt(from);
Expand Down Expand Up @@ -858,7 +858,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
case wopQueryMissing: {
std::vector<StorePathWithOutputs> targets;
for (auto & s : readStrings<Strings>(from))
targets.push_back(store->parsePathWithOutputs(s));
targets.push_back(parsePathWithOutputs(*store, s));
logger->startWork();
StorePathSet willBuild, willSubstitute, unknown;
uint64_t downloadSize, narSize;
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/path-with-outputs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s)
}


StorePathWithOutputs Store::parsePathWithOutputs(const std::string & s)
StorePathWithOutputs parsePathWithOutputs(const Store & store, std::string_view pathWithOutputs)
{
auto [path, outputs] = nix::parsePathWithOutputs(s);
return {parseStorePath(path), std::move(outputs)};
auto [path, outputs] = parsePathWithOutputs(pathWithOutputs);
return StorePathWithOutputs { store.parseStorePath(path), std::move(outputs) };
}


StorePathWithOutputs Store::followLinksToStorePathWithOutputs(std::string_view path) const
StorePathWithOutputs followLinksToStorePathWithOutputs(const Store & store, std::string_view pathWithOutputs)
{
auto [path2, outputs] = nix::parsePathWithOutputs(path);
return StorePathWithOutputs { followLinksToStorePath(path2), std::move(outputs) };
auto [path, outputs] = parsePathWithOutputs(pathWithOutputs);
return StorePathWithOutputs { store.followLinksToStorePath(path), std::move(outputs) };
}

}
9 changes: 9 additions & 0 deletions src/libstore/path-with-outputs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ struct StorePathWithOutputs

std::pair<std::string_view, StringSet> parsePathWithOutputs(std::string_view s);

class Store;

/* Split a string specifying a derivation and a set of outputs
(/nix/store/hash-foo!out1,out2,...) into the derivation path
and the outputs. */
StorePathWithOutputs parsePathWithOutputs(const Store & store, std::string_view pathWithOutputs);

StorePathWithOutputs followLinksToStorePathWithOutputs(const Store & store, std::string_view pathWithOutputs);

}
7 changes: 0 additions & 7 deletions src/libstore/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ public:

PathSet printStorePathSet(const StorePathSet & path) const;

/* Split a string specifying a derivation and a set of outputs
(/nix/store/hash-foo!out1,out2,...) into the derivation path
and the outputs. */
StorePathWithOutputs parsePathWithOutputs(const string & s);

/* Display a set of paths in human-readable form (i.e., between quotes
and separated by commas). */
std::string showPaths(const StorePathSet & paths);
Expand All @@ -290,8 +285,6 @@ public:
result. */
StorePath followLinksToStorePath(std::string_view path) const;

StorePathWithOutputs followLinksToStorePathWithOutputs(std::string_view path) const;

/* Constructs a unique store path name. */
StorePath makeStorePath(std::string_view type,
std::string_view hash, std::string_view name) const;
Expand Down
4 changes: 2 additions & 2 deletions src/nix-store/nix-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static void opRealise(Strings opFlags, Strings opArgs)

std::vector<StorePathWithOutputs> paths;
for (auto & i : opArgs)
paths.push_back(store->followLinksToStorePathWithOutputs(i));
paths.push_back(followLinksToStorePathWithOutputs(*store, i));

uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown;
Expand Down Expand Up @@ -873,7 +873,7 @@ static void opServe(Strings opFlags, Strings opArgs)

std::vector<StorePathWithOutputs> paths;
for (auto & s : readStrings<Strings>(in))
paths.push_back(store->parsePathWithOutputs(s));
paths.push_back(parsePathWithOutputs(*store, s));

getBuildSettings();

Expand Down

0 comments on commit 3ea534d

Please sign in to comment.