diff options
| author | Congcong Kuo <congcong.kuo@gmail.com> | 2025-05-26 00:49:26 +0800 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2025-06-03 15:09:55 +0200 |
| commit | 4b9d14378fcc3d8dd4eea36b541fe87e198fd7b8 (patch) | |
| tree | 530ea4ad44c0c1bdd9d4c655627f7f60a8cf5c74 | |
| parent | 8a6cf4fad6d6568940286adc4197f37a344d4e5a (diff) | |
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>
| -rw-r--r-- | nix/libstore/build.cc | 11 | ||||
| -rw-r--r-- | nix/libstore/local-store.cc | 6 | ||||
| -rw-r--r-- | nix/libutil/types.hh | 14 | ||||
| -rw-r--r-- | nix/libutil/util.hh | 9 | ||||
| -rw-r--r-- | nix/nix-daemon/nix-daemon.cc | 4 |
5 files changed, 17 insertions, 27 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 993876c6d10..47e93d1a211 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -2041,8 +2041,7 @@ void DerivationGoal::startBuilder() | |||
| 2041 | /* parent */ | 2041 | /* parent */ |
| 2042 | pid.setSeparatePG(true); | 2042 | pid.setSeparatePG(true); |
| 2043 | builderOut.writeSide.close(); | 2043 | builderOut.writeSide.close(); |
| 2044 | worker.childStarted(shared_from_this(), pid, | 2044 | worker.childStarted(shared_from_this(), pid, std::set<int>{builderOut.readSide}, true, true); |
| 2045 | singleton<set<int> >(builderOut.readSide), true, true); | ||
| 2046 | 2045 | ||
| 2047 | /* Check if setting up the build environment failed. */ | 2046 | /* Check if setting up the build environment failed. */ |
| 2048 | string msg = readLine(builderOut.readSide); | 2047 | string msg = readLine(builderOut.readSide); |
| @@ -3168,7 +3167,7 @@ void SubstitutionGoal::tryNext() | |||
| 3168 | trace("trying substituter"); | 3167 | trace("trying substituter"); |
| 3169 | 3168 | ||
| 3170 | SubstitutablePathInfos infos; | 3169 | SubstitutablePathInfos infos; |
| 3171 | PathSet dummy(singleton<PathSet>(storePath)); | 3170 | PathSet dummy{storePath}; |
| 3172 | worker.store.querySubstitutablePathInfos(dummy, infos); | 3171 | worker.store.querySubstitutablePathInfos(dummy, infos); |
| 3173 | SubstitutablePathInfos::iterator k = infos.find(storePath); | 3172 | SubstitutablePathInfos::iterator k = infos.find(storePath); |
| 3174 | if (k == infos.end()) { | 3173 | if (k == infos.end()) { |
| @@ -3243,7 +3242,7 @@ void SubstitutionGoal::tryToRun() | |||
| 3243 | 3242 | ||
| 3244 | /* Acquire a lock on the output path. */ | 3243 | /* Acquire a lock on the output path. */ |
| 3245 | outputLock = std::shared_ptr<PathLocks>(new PathLocks); | 3244 | outputLock = std::shared_ptr<PathLocks>(new PathLocks); |
| 3246 | if (!outputLock->lockPaths(singleton<PathSet>(storePath), "", false)) { | 3245 | if (!outputLock->lockPaths(PathSet{storePath}, "", false)) { |
| 3247 | worker.waitForAWhile(shared_from_this()); | 3246 | worker.waitForAWhile(shared_from_this()); |
| 3248 | return; | 3247 | return; |
| 3249 | } | 3248 | } |
| @@ -3842,7 +3841,7 @@ void LocalStore::ensurePath(const Path & path) | |||
| 3842 | 3841 | ||
| 3843 | Worker worker(*this); | 3842 | Worker worker(*this); |
| 3844 | GoalPtr goal = worker.makeSubstitutionGoal(path); | 3843 | GoalPtr goal = worker.makeSubstitutionGoal(path); |
| 3845 | Goals goals = singleton<Goals>(goal); | 3844 | Goals goals{goal}; |
| 3846 | 3845 | ||
| 3847 | worker.run(goals); | 3846 | worker.run(goals); |
| 3848 | 3847 | ||
| @@ -3855,7 +3854,7 @@ void LocalStore::repairPath(const Path & path) | |||
| 3855 | { | 3854 | { |
| 3856 | Worker worker(*this); | 3855 | Worker worker(*this); |
| 3857 | GoalPtr goal = worker.makeSubstitutionGoal(path, true); | 3856 | GoalPtr goal = worker.makeSubstitutionGoal(path, true); |
| 3858 | Goals goals = singleton<Goals>(goal); | 3857 | Goals goals{goal}; |
| 3859 | 3858 | ||
| 3860 | worker.run(goals); | 3859 | worker.run(goals); |
| 3861 | 3860 | ||
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc index f6540c2117d..d544253add8 100644 --- a/nix/libstore/local-store.cc +++ b/nix/libstore/local-store.cc | |||
| @@ -1015,7 +1015,7 @@ Path LocalStore::addToStoreFromDump(const string & dump, const string & name, | |||
| 1015 | /* The first check above is an optimisation to prevent | 1015 | /* The first check above is an optimisation to prevent |
| 1016 | unnecessary lock acquisition. */ | 1016 | unnecessary lock acquisition. */ |
| 1017 | 1017 | ||
| 1018 | PathLocks outputLock(singleton<PathSet, Path>(dstPath)); | 1018 | PathLocks outputLock{ PathSet{dstPath} }; |
| 1019 | 1019 | ||
| 1020 | if (repair || !isValidPath(dstPath)) { | 1020 | if (repair || !isValidPath(dstPath)) { |
| 1021 | 1021 | ||
| @@ -1084,7 +1084,7 @@ Path LocalStore::addTextToStore(const string & name, const string & s, | |||
| 1084 | 1084 | ||
| 1085 | if (repair || !isValidPath(dstPath)) { | 1085 | if (repair || !isValidPath(dstPath)) { |
| 1086 | 1086 | ||
| 1087 | PathLocks outputLock(singleton<PathSet, Path>(dstPath)); | 1087 | PathLocks outputLock{ PathSet{dstPath} }; |
| 1088 | 1088 | ||
| 1089 | if (repair || !isValidPath(dstPath)) { | 1089 | if (repair || !isValidPath(dstPath)) { |
| 1090 | 1090 | ||
| @@ -1380,7 +1380,7 @@ Path LocalStore::importPath(bool requireSignature, Source & source) | |||
| 1380 | lock on this path). */ | 1380 | lock on this path). */ |
| 1381 | Strings locksHeld = tokenizeString<Strings>(getEnv("NIX_HELD_LOCKS")); | 1381 | Strings locksHeld = tokenizeString<Strings>(getEnv("NIX_HELD_LOCKS")); |
| 1382 | if (find(locksHeld.begin(), locksHeld.end(), dstPath) == locksHeld.end()) | 1382 | if (find(locksHeld.begin(), locksHeld.end(), dstPath) == locksHeld.end()) |
| 1383 | outputLock.lockPaths(singleton<PathSet, Path>(dstPath)); | 1383 | outputLock.lockPaths(PathSet{dstPath}); |
| 1384 | 1384 | ||
| 1385 | if (!isValidPath(dstPath)) { | 1385 | if (!isValidPath(dstPath)) { |
| 1386 | 1386 | ||
diff --git a/nix/libutil/types.hh b/nix/libutil/types.hh index 160884ee1ad..62889e6fa99 100644 --- a/nix/libutil/types.hh +++ b/nix/libutil/types.hh | |||
| @@ -76,24 +76,24 @@ public: | |||
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | typedef list<string> Strings; | 79 | using Strings = std::list<std::string>; |
| 80 | typedef set<string> StringSet; | 80 | using StringSet = std::set<std::string>; |
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | /* Paths are just strings. */ | 83 | /* Paths are just strings. */ |
| 84 | typedef string Path; | 84 | using Path = std::string; |
| 85 | typedef list<Path> Paths; | 85 | using Paths = std::list<Path>; |
| 86 | typedef set<Path> PathSet; | 86 | using PathSet = std::set<Path>; |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | typedef enum { | 89 | enum Verbosity { |
| 90 | lvlError = 0, | 90 | lvlError = 0, |
| 91 | lvlInfo, | 91 | lvlInfo, |
| 92 | lvlTalkative, | 92 | lvlTalkative, |
| 93 | lvlChatty, | 93 | lvlChatty, |
| 94 | lvlDebug, | 94 | lvlDebug, |
| 95 | lvlVomit | 95 | lvlVomit |
| 96 | } Verbosity; | 96 | }; |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | } | 99 | } |
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 03234e3a5d2..176247e699d 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh | |||
| @@ -121,15 +121,6 @@ Paths createDirs(const Path & path); | |||
| 121 | void createSymlink(const Path & target, const Path & link); | 121 | void createSymlink(const Path & target, const Path & link); |
| 122 | 122 | ||
| 123 | 123 | ||
| 124 | template<class T, class A> | ||
| 125 | T singleton(const A & a) | ||
| 126 | { | ||
| 127 | T t; | ||
| 128 | t.insert(a); | ||
| 129 | return t; | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | /* Messages. */ | 124 | /* Messages. */ |
| 134 | 125 | ||
| 135 | 126 | ||
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index e29237e65dd..b43bcf7fc6e 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc | |||
| @@ -336,7 +336,7 @@ static void performOp(bool trusted, unsigned int clientVersion, | |||
| 336 | case wopHasSubstitutes: { | 336 | case wopHasSubstitutes: { |
| 337 | Path path = readStorePath(from); | 337 | Path path = readStorePath(from); |
| 338 | startWork(); | 338 | startWork(); |
| 339 | PathSet res = store->querySubstitutablePaths(singleton<PathSet>(path)); | 339 | PathSet res = store->querySubstitutablePaths(PathSet{path}); |
| 340 | stopWork(); | 340 | stopWork(); |
| 341 | writeInt(res.find(path) != res.end(), to); | 341 | writeInt(res.find(path) != res.end(), to); |
| 342 | break; | 342 | break; |
| @@ -656,7 +656,7 @@ static void performOp(bool trusted, unsigned int clientVersion, | |||
| 656 | Path path = absPath(readString(from)); | 656 | Path path = absPath(readString(from)); |
| 657 | startWork(); | 657 | startWork(); |
| 658 | SubstitutablePathInfos infos; | 658 | SubstitutablePathInfos infos; |
| 659 | store->querySubstitutablePathInfos(singleton<PathSet>(path), infos); | 659 | store->querySubstitutablePathInfos(PathSet{path}, infos); |
| 660 | stopWork(); | 660 | stopWork(); |
| 661 | SubstitutablePathInfos::iterator i = infos.find(path); | 661 | SubstitutablePathInfos::iterator i = infos.find(path); |
| 662 | if (i == infos.end()) | 662 | if (i == infos.end()) |
