daemon: Remove ‘singleton’ and replace ‘typedef’ with ‘using’ in ‘types.hh’

* nix/libutil/util.hh (singleton): Remove.
* nix/libstore/build.cc (DerivationGoal::startBuilder)
(SubstitutionGoal::tryNext, SubstitutionGoal::tryToRun)
(LocalStore::ensurePath, LocalStore::repairPath): Use normal
construction function instead of ‘singleton’.
* nix/libstore/local-store.cc (LocalStore::addToStoreFromDump)
(LocalStore::addTextToStore, LocalStore::importPath): Likewise.
* nix/nix-daemon/nix-daemon.cc (performOp): Likewise.

Change-Id: If0d929407c09482f3b506a1c51dfda70e29696dd
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Congcong Kuo 2025-05-26 00:49:26 +08:00 committed by Ludovic Courtès
parent 8a6cf4fad6
commit 4b9d14378f
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
5 changed files with 17 additions and 27 deletions

View file

@ -2041,8 +2041,7 @@ void DerivationGoal::startBuilder()
/* parent */
pid.setSeparatePG(true);
builderOut.writeSide.close();
worker.childStarted(shared_from_this(), pid,
singleton<set<int> >(builderOut.readSide), true, true);
worker.childStarted(shared_from_this(), pid, std::set<int>{builderOut.readSide}, true, true);
/* Check if setting up the build environment failed. */
string msg = readLine(builderOut.readSide);
@ -3168,7 +3167,7 @@ void SubstitutionGoal::tryNext()
trace("trying substituter");
SubstitutablePathInfos infos;
PathSet dummy(singleton<PathSet>(storePath));
PathSet dummy{storePath};
worker.store.querySubstitutablePathInfos(dummy, infos);
SubstitutablePathInfos::iterator k = infos.find(storePath);
if (k == infos.end()) {
@ -3243,7 +3242,7 @@ void SubstitutionGoal::tryToRun()
/* Acquire a lock on the output path. */
outputLock = std::shared_ptr<PathLocks>(new PathLocks);
if (!outputLock->lockPaths(singleton<PathSet>(storePath), "", false)) {
if (!outputLock->lockPaths(PathSet{storePath}, "", false)) {
worker.waitForAWhile(shared_from_this());
return;
}
@ -3842,7 +3841,7 @@ void LocalStore::ensurePath(const Path & path)
Worker worker(*this);
GoalPtr goal = worker.makeSubstitutionGoal(path);
Goals goals = singleton<Goals>(goal);
Goals goals{goal};
worker.run(goals);
@ -3855,7 +3854,7 @@ void LocalStore::repairPath(const Path & path)
{
Worker worker(*this);
GoalPtr goal = worker.makeSubstitutionGoal(path, true);
Goals goals = singleton<Goals>(goal);
Goals goals{goal};
worker.run(goals);

View file

@ -1015,7 +1015,7 @@ Path LocalStore::addToStoreFromDump(const string & dump, const string & name,
/* The first check above is an optimisation to prevent
unnecessary lock acquisition. */
PathLocks outputLock(singleton<PathSet, Path>(dstPath));
PathLocks outputLock{ PathSet{dstPath} };
if (repair || !isValidPath(dstPath)) {
@ -1084,7 +1084,7 @@ Path LocalStore::addTextToStore(const string & name, const string & s,
if (repair || !isValidPath(dstPath)) {
PathLocks outputLock(singleton<PathSet, Path>(dstPath));
PathLocks outputLock{ PathSet{dstPath} };
if (repair || !isValidPath(dstPath)) {
@ -1380,7 +1380,7 @@ Path LocalStore::importPath(bool requireSignature, Source & source)
lock on this path). */
Strings locksHeld = tokenizeString<Strings>(getEnv("NIX_HELD_LOCKS"));
if (find(locksHeld.begin(), locksHeld.end(), dstPath) == locksHeld.end())
outputLock.lockPaths(singleton<PathSet, Path>(dstPath));
outputLock.lockPaths(PathSet{dstPath});
if (!isValidPath(dstPath)) {

View file

@ -76,24 +76,24 @@ public:
};
typedef list<string> Strings;
typedef set<string> StringSet;
using Strings = std::list<std::string>;
using StringSet = std::set<std::string>;
/* Paths are just strings. */
typedef string Path;
typedef list<Path> Paths;
typedef set<Path> PathSet;
using Path = std::string;
using Paths = std::list<Path>;
using PathSet = std::set<Path>;
typedef enum {
enum Verbosity {
lvlError = 0,
lvlInfo,
lvlTalkative,
lvlChatty,
lvlDebug,
lvlVomit
} Verbosity;
};
}

View file

@ -121,15 +121,6 @@ Paths createDirs(const Path & path);
void createSymlink(const Path & target, const Path & link);
template<class T, class A>
T singleton(const A & a)
{
T t;
t.insert(a);
return t;
}
/* Messages. */

View file

@ -336,7 +336,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
case wopHasSubstitutes: {
Path path = readStorePath(from);
startWork();
PathSet res = store->querySubstitutablePaths(singleton<PathSet>(path));
PathSet res = store->querySubstitutablePaths(PathSet{path});
stopWork();
writeInt(res.find(path) != res.end(), to);
break;
@ -656,7 +656,7 @@ static void performOp(bool trusted, unsigned int clientVersion,
Path path = absPath(readString(from));
startWork();
SubstitutablePathInfos infos;
store->querySubstitutablePathInfos(singleton<PathSet>(path), infos);
store->querySubstitutablePathInfos(PathSet{path}, infos);
stopWork();
SubstitutablePathInfos::iterator i = infos.find(path);
if (i == infos.end())