diff options
Diffstat (limited to 'nix')
| -rw-r--r-- | nix/libstore/build.cc | 332 | ||||
| -rw-r--r-- | nix/libstore/derivations.cc | 38 | ||||
| -rw-r--r-- | nix/libstore/gc.cc | 42 | ||||
| -rw-r--r-- | nix/libstore/globals.cc | 10 | ||||
| -rw-r--r-- | nix/libstore/local-store.cc | 78 | ||||
| -rw-r--r-- | nix/libstore/misc.cc | 28 | ||||
| -rw-r--r-- | nix/libstore/optimise-store.cc | 14 | ||||
| -rw-r--r-- | nix/libstore/pathlocks.cc | 26 | ||||
| -rw-r--r-- | nix/libstore/references.cc | 20 | ||||
| -rw-r--r-- | nix/libstore/store-api.cc | 42 | ||||
| -rw-r--r-- | nix/libutil/serialise.cc | 4 | ||||
| -rw-r--r-- | nix/libutil/util.cc | 8 | ||||
| -rw-r--r-- | nix/libutil/util.hh | 7 | ||||
| -rw-r--r-- | nix/nix-daemon/nix-daemon.cc | 12 |
14 files changed, 327 insertions, 334 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 47e93d1a211..afdcd9518b3 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc | |||
| @@ -336,9 +336,9 @@ void addToWeakGoals(WeakGoals & goals, GoalPtr p) | |||
| 336 | { | 336 | { |
| 337 | // FIXME: necessary? | 337 | // FIXME: necessary? |
| 338 | // FIXME: O(n) | 338 | // FIXME: O(n) |
| 339 | foreach (WeakGoals::iterator, i, goals) | 339 | bool b = std::none_of(goals.begin(), goals.end(), |
| 340 | if (i->lock() == p) return; | 340 | [p](WeakGoalPtr i) { return i.lock() == p; }); |
| 341 | goals.push_back(p); | 341 | if (b) goals.push_back(p); else return; |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | 344 | ||
| @@ -367,11 +367,11 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result) | |||
| 367 | 367 | ||
| 368 | /* If we failed and keepGoing is not set, we remove all | 368 | /* If we failed and keepGoing is not set, we remove all |
| 369 | remaining waitees. */ | 369 | remaining waitees. */ |
| 370 | foreach (Goals::iterator, i, waitees) { | 370 | for (auto& i : waitees) { |
| 371 | GoalPtr goal = *i; | 371 | GoalPtr goal = i; |
| 372 | WeakGoals waiters2; | 372 | WeakGoals waiters2; |
| 373 | foreach (WeakGoals::iterator, j, goal->waiters) | 373 | for (auto& j : goal->waiters) |
| 374 | if (j->lock() != shared_from_this()) waiters2.push_back(*j); | 374 | if (j.lock() != shared_from_this()) waiters2.push_back(j); |
| 375 | goal->waiters = waiters2; | 375 | goal->waiters = waiters2; |
| 376 | } | 376 | } |
| 377 | waitees.clear(); | 377 | waitees.clear(); |
| @@ -387,8 +387,8 @@ void Goal::amDone(ExitCode result) | |||
| 387 | assert(exitCode == ecBusy); | 387 | assert(exitCode == ecBusy); |
| 388 | assert(result == ecSuccess || result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure); | 388 | assert(result == ecSuccess || result == ecFailed || result == ecNoSubstituters || result == ecIncompleteClosure); |
| 389 | exitCode = result; | 389 | exitCode = result; |
| 390 | foreach (WeakGoals::iterator, i, waiters) { | 390 | for (auto& i : waiters) { |
| 391 | GoalPtr goal = i->lock(); | 391 | GoalPtr goal = i.lock(); |
| 392 | if (goal) goal->waiteeDone(shared_from_this(), result); | 392 | if (goal) goal->waiteeDone(shared_from_this(), result); |
| 393 | } | 393 | } |
| 394 | waiters.clear(); | 394 | waiters.clear(); |
| @@ -498,13 +498,13 @@ void UserLock::acquire() | |||
| 498 | 498 | ||
| 499 | /* Find a user account that isn't currently in use for another | 499 | /* Find a user account that isn't currently in use for another |
| 500 | build. */ | 500 | build. */ |
| 501 | foreach (Strings::iterator, i, users) { | 501 | for (auto& i : users) { |
| 502 | debug(format("trying user `%1%'") % *i); | 502 | debug(format("trying user `%1%'") % i); |
| 503 | 503 | ||
| 504 | struct passwd * pw = getpwnam(i->c_str()); | 504 | struct passwd * pw = getpwnam(i.c_str()); |
| 505 | if (!pw) | 505 | if (!pw) |
| 506 | throw Error(format("the user `%1%' in the group `%2%' does not exist") | 506 | throw Error(format("the user `%1%' in the group `%2%' does not exist") |
| 507 | % *i % settings.buildUsersGroup); | 507 | % i % settings.buildUsersGroup); |
| 508 | 508 | ||
| 509 | createDirs(settings.nixStateDir + "/userpool"); | 509 | createDirs(settings.nixStateDir + "/userpool"); |
| 510 | 510 | ||
| @@ -522,7 +522,7 @@ void UserLock::acquire() | |||
| 522 | if (lockFile(fd, ltWrite, false)) { | 522 | if (lockFile(fd, ltWrite, false)) { |
| 523 | fdUserLock = fd.borrow(); | 523 | fdUserLock = fd.borrow(); |
| 524 | lockedPaths.insert(fnUserLock); | 524 | lockedPaths.insert(fnUserLock); |
| 525 | user = *i; | 525 | user = i; |
| 526 | uid = pw->pw_uid; | 526 | uid = pw->pw_uid; |
| 527 | 527 | ||
| 528 | /* Sanity check... */ | 528 | /* Sanity check... */ |
| @@ -576,12 +576,12 @@ typedef map<string, string> HashRewrites; | |||
| 576 | 576 | ||
| 577 | string rewriteHashes(string s, const HashRewrites & rewrites) | 577 | string rewriteHashes(string s, const HashRewrites & rewrites) |
| 578 | { | 578 | { |
| 579 | foreach (HashRewrites::const_iterator, i, rewrites) { | 579 | for (auto& i : rewrites) { |
| 580 | assert(i->first.size() == i->second.size()); | 580 | assert(i.first.size() == i.second.size()); |
| 581 | size_t j = 0; | 581 | size_t j = 0; |
| 582 | while ((j = s.find(i->first, j)) != string::npos) { | 582 | while ((j = s.find(i.first, j)) != string::npos) { |
| 583 | debug(format("rewriting @ %1%") % j); | 583 | debug(format("rewriting @ %1%") % j); |
| 584 | s.replace(j, i->second.size(), i->second); | 584 | s.replace(j, i.second.size(), i.second); |
| 585 | } | 585 | } |
| 586 | } | 586 | } |
| 587 | return s; | 587 | return s; |
| @@ -884,9 +884,9 @@ void DerivationGoal::addWantedOutputs(const StringSet & outputs) | |||
| 884 | wantedOutputs.clear(); | 884 | wantedOutputs.clear(); |
| 885 | needRestart = true; | 885 | needRestart = true; |
| 886 | } else | 886 | } else |
| 887 | foreach (StringSet::const_iterator, i, outputs) | 887 | for (const auto& i : outputs) |
| 888 | if (wantedOutputs.find(*i) == wantedOutputs.end()) { | 888 | if (wantedOutputs.find(i) == wantedOutputs.end()) { |
| 889 | wantedOutputs.insert(*i); | 889 | wantedOutputs.insert(i); |
| 890 | needRestart = true; | 890 | needRestart = true; |
| 891 | } | 891 | } |
| 892 | } | 892 | } |
| @@ -933,8 +933,8 @@ void DerivationGoal::haveDerivation() | |||
| 933 | /* Get the derivation. */ | 933 | /* Get the derivation. */ |
| 934 | drv = derivationFromPath(worker.store, drvPath); | 934 | drv = derivationFromPath(worker.store, drvPath); |
| 935 | 935 | ||
| 936 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 936 | for (auto& i : drv.outputs) |
| 937 | worker.store.addTempRoot(i->second.path); | 937 | worker.store.addTempRoot(i.second.path); |
| 938 | 938 | ||
| 939 | /* Check what outputs paths are not already valid. */ | 939 | /* Check what outputs paths are not already valid. */ |
| 940 | PathSet invalidOutputs = checkPathValidity(false, buildMode == bmRepair); | 940 | PathSet invalidOutputs = checkPathValidity(false, buildMode == bmRepair); |
| @@ -947,15 +947,15 @@ void DerivationGoal::haveDerivation() | |||
| 947 | 947 | ||
| 948 | /* Check whether any output previously failed to build. If so, | 948 | /* Check whether any output previously failed to build. If so, |
| 949 | don't bother. */ | 949 | don't bother. */ |
| 950 | foreach (PathSet::iterator, i, invalidOutputs) | 950 | for (auto& i : invalidOutputs) |
| 951 | if (pathFailed(*i)) return; | 951 | if (pathFailed(i)) return; |
| 952 | 952 | ||
| 953 | /* We are first going to try to create the invalid output paths | 953 | /* We are first going to try to create the invalid output paths |
| 954 | through substitutes. If that doesn't work, we'll build | 954 | through substitutes. If that doesn't work, we'll build |
| 955 | them. */ | 955 | them. */ |
| 956 | if (settings.useSubstitutes && substitutesAllowed(drv)) | 956 | if (settings.useSubstitutes && substitutesAllowed(drv)) |
| 957 | foreach (PathSet::iterator, i, invalidOutputs) | 957 | for (auto& i : invalidOutputs) |
| 958 | addWaitee(worker.makeSubstitutionGoal(*i, buildMode == bmRepair)); | 958 | addWaitee(worker.makeSubstitutionGoal(i, buildMode == bmRepair)); |
| 959 | 959 | ||
| 960 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ | 960 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ |
| 961 | outputsSubstituted(); | 961 | outputsSubstituted(); |
| @@ -1004,11 +1004,11 @@ void DerivationGoal::outputsSubstituted() | |||
| 1004 | wantedOutputs = PathSet(); | 1004 | wantedOutputs = PathSet(); |
| 1005 | 1005 | ||
| 1006 | /* The inputs must be built before we can build this goal. */ | 1006 | /* The inputs must be built before we can build this goal. */ |
| 1007 | foreach (DerivationInputs::iterator, i, drv.inputDrvs) | 1007 | for (auto& i : drv.inputDrvs) |
| 1008 | addWaitee(worker.makeDerivationGoal(i->first, i->second, buildMode == bmRepair ? bmRepair : bmNormal)); | 1008 | addWaitee(worker.makeDerivationGoal(i.first, i.second, buildMode == bmRepair ? bmRepair : bmNormal)); |
| 1009 | 1009 | ||
| 1010 | foreach (PathSet::iterator, i, drv.inputSrcs) | 1010 | for (auto& i : drv.inputSrcs) |
| 1011 | addWaitee(worker.makeSubstitutionGoal(*i)); | 1011 | addWaitee(worker.makeSubstitutionGoal(i)); |
| 1012 | 1012 | ||
| 1013 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ | 1013 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ |
| 1014 | inputsRealised(); | 1014 | inputsRealised(); |
| @@ -1026,14 +1026,14 @@ void DerivationGoal::repairClosure() | |||
| 1026 | 1026 | ||
| 1027 | /* Get the output closure. */ | 1027 | /* Get the output closure. */ |
| 1028 | PathSet outputClosure; | 1028 | PathSet outputClosure; |
| 1029 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 1029 | for (auto& i : drv.outputs) { |
| 1030 | if (!wantOutput(i->first, wantedOutputs)) continue; | 1030 | if (!wantOutput(i.first, wantedOutputs)) continue; |
| 1031 | computeFSClosure(worker.store, i->second.path, outputClosure); | 1031 | computeFSClosure(worker.store, i.second.path, outputClosure); |
| 1032 | } | 1032 | } |
| 1033 | 1033 | ||
| 1034 | /* Filter out our own outputs (which we have already checked). */ | 1034 | /* Filter out our own outputs (which we have already checked). */ |
| 1035 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 1035 | for (auto& i : drv.outputs) |
| 1036 | outputClosure.erase(i->second.path); | 1036 | outputClosure.erase(i.second.path); |
| 1037 | 1037 | ||
| 1038 | /* Get all dependencies of this derivation so that we know which | 1038 | /* Get all dependencies of this derivation so that we know which |
| 1039 | derivation is responsible for which path in the output | 1039 | derivation is responsible for which path in the output |
| @@ -1041,21 +1041,21 @@ void DerivationGoal::repairClosure() | |||
| 1041 | PathSet inputClosure; | 1041 | PathSet inputClosure; |
| 1042 | computeFSClosure(worker.store, drvPath, inputClosure); | 1042 | computeFSClosure(worker.store, drvPath, inputClosure); |
| 1043 | std::map<Path, Path> outputsToDrv; | 1043 | std::map<Path, Path> outputsToDrv; |
| 1044 | foreach (PathSet::iterator, i, inputClosure) | 1044 | for (auto& i : inputClosure) |
| 1045 | if (isDerivation(*i)) { | 1045 | if (isDerivation(i)) { |
| 1046 | Derivation drv = derivationFromPath(worker.store, *i); | 1046 | Derivation drv = derivationFromPath(worker.store, i); |
| 1047 | foreach (DerivationOutputs::iterator, j, drv.outputs) | 1047 | for (auto& j : drv.outputs) |
| 1048 | outputsToDrv[j->second.path] = *i; | 1048 | outputsToDrv[j.second.path] = i; |
| 1049 | } | 1049 | } |
| 1050 | 1050 | ||
| 1051 | /* Check each path (slow!). */ | 1051 | /* Check each path (slow!). */ |
| 1052 | PathSet broken; | 1052 | PathSet broken; |
| 1053 | foreach (PathSet::iterator, i, outputClosure) { | 1053 | for (auto& i : outputClosure) { |
| 1054 | if (worker.store.pathContentsGood(*i)) continue; | 1054 | if (worker.store.pathContentsGood(i)) continue; |
| 1055 | printMsg(lvlError, format("found corrupted or missing path `%1%' in the output closure of `%2%'") % *i % drvPath); | 1055 | printMsg(lvlError, format("found corrupted or missing path `%1%' in the output closure of `%2%'") % i % drvPath); |
| 1056 | Path drvPath2 = outputsToDrv[*i]; | 1056 | Path drvPath2 = outputsToDrv[i]; |
| 1057 | if (drvPath2 == "") | 1057 | if (drvPath2 == "") |
| 1058 | addWaitee(worker.makeSubstitutionGoal(*i, true)); | 1058 | addWaitee(worker.makeSubstitutionGoal(i, true)); |
| 1059 | else | 1059 | else |
| 1060 | addWaitee(worker.makeDerivationGoal(drvPath2, PathSet(), bmRepair)); | 1060 | addWaitee(worker.makeDerivationGoal(drvPath2, PathSet(), bmRepair)); |
| 1061 | } | 1061 | } |
| @@ -1099,32 +1099,32 @@ void DerivationGoal::inputsRealised() | |||
| 1099 | running the build hook. */ | 1099 | running the build hook. */ |
| 1100 | 1100 | ||
| 1101 | /* The outputs are referenceable paths. */ | 1101 | /* The outputs are referenceable paths. */ |
| 1102 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 1102 | for (auto& i : drv.outputs) { |
| 1103 | debug(format("building path `%1%'") % i->second.path); | 1103 | debug(format("building path `%1%'") % i.second.path); |
| 1104 | allPaths.insert(i->second.path); | 1104 | allPaths.insert(i.second.path); |
| 1105 | } | 1105 | } |
| 1106 | 1106 | ||
| 1107 | /* Determine the full set of input paths. */ | 1107 | /* Determine the full set of input paths. */ |
| 1108 | 1108 | ||
| 1109 | /* First, the input derivations. */ | 1109 | /* First, the input derivations. */ |
| 1110 | foreach (DerivationInputs::iterator, i, drv.inputDrvs) { | 1110 | for (auto& i : drv.inputDrvs) { |
| 1111 | /* Add the relevant output closures of the input derivation | 1111 | /* Add the relevant output closures of the input derivation |
| 1112 | `*i' as input paths. Only add the closures of output paths | 1112 | `*i' as input paths. Only add the closures of output paths |
| 1113 | that are specified as inputs. */ | 1113 | that are specified as inputs. */ |
| 1114 | assert(worker.store.isValidPath(i->first)); | 1114 | assert(worker.store.isValidPath(i.first)); |
| 1115 | Derivation inDrv = derivationFromPath(worker.store, i->first); | 1115 | Derivation inDrv = derivationFromPath(worker.store, i.first); |
| 1116 | foreach (StringSet::iterator, j, i->second) | 1116 | for (auto& j : i.second) |
| 1117 | if (inDrv.outputs.find(*j) != inDrv.outputs.end()) | 1117 | if (inDrv.outputs.find(j) != inDrv.outputs.end()) |
| 1118 | computeFSClosure(worker.store, inDrv.outputs[*j].path, inputPaths); | 1118 | computeFSClosure(worker.store, inDrv.outputs[j].path, inputPaths); |
| 1119 | else | 1119 | else |
| 1120 | throw Error( | 1120 | throw Error( |
| 1121 | format("derivation `%1%' requires non-existent output `%2%' from input derivation `%3%'") | 1121 | format("derivation `%1%' requires non-existent output `%2%' from input derivation `%3%'") |
| 1122 | % drvPath % *j % i->first); | 1122 | % drvPath % j % i.first); |
| 1123 | } | 1123 | } |
| 1124 | 1124 | ||
| 1125 | /* Second, the input sources. */ | 1125 | /* Second, the input sources. */ |
| 1126 | foreach (PathSet::iterator, i, drv.inputSrcs) | 1126 | for (auto& i : drv.inputSrcs) |
| 1127 | computeFSClosure(worker.store, *i, inputPaths); | 1127 | computeFSClosure(worker.store, i, inputPaths); |
| 1128 | 1128 | ||
| 1129 | debug(format("added input paths %1%") % showPaths(inputPaths)); | 1129 | debug(format("added input paths %1%") % showPaths(inputPaths)); |
| 1130 | 1130 | ||
| @@ -1186,10 +1186,10 @@ void DerivationGoal::tryToBuild() | |||
| 1186 | (It can't happen between here and the lockPaths() call below | 1186 | (It can't happen between here and the lockPaths() call below |
| 1187 | because we're not allowing multi-threading.) If so, put this | 1187 | because we're not allowing multi-threading.) If so, put this |
| 1188 | goal to sleep until another goal finishes, then try again. */ | 1188 | goal to sleep until another goal finishes, then try again. */ |
| 1189 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 1189 | for (auto& i : drv.outputs) |
| 1190 | if (pathIsLockedByMe(i->second.path)) { | 1190 | if (pathIsLockedByMe(i.second.path)) { |
| 1191 | debug(format("putting derivation `%1%' to sleep because `%2%' is locked by another goal") | 1191 | debug(format("putting derivation `%1%' to sleep because `%2%' is locked by another goal") |
| 1192 | % drvPath % i->second.path); | 1192 | % drvPath % i.second.path); |
| 1193 | worker.waitForAnyGoal(shared_from_this()); | 1193 | worker.waitForAnyGoal(shared_from_this()); |
| 1194 | return; | 1194 | return; |
| 1195 | } | 1195 | } |
| @@ -1222,12 +1222,12 @@ void DerivationGoal::tryToBuild() | |||
| 1222 | 1222 | ||
| 1223 | missingPaths = outputPaths(drv); | 1223 | missingPaths = outputPaths(drv); |
| 1224 | if (buildMode != bmCheck) | 1224 | if (buildMode != bmCheck) |
| 1225 | foreach (PathSet::iterator, i, validPaths) missingPaths.erase(*i); | 1225 | for (auto& i : validPaths) missingPaths.erase(i); |
| 1226 | 1226 | ||
| 1227 | /* If any of the outputs already exist but are not valid, delete | 1227 | /* If any of the outputs already exist but are not valid, delete |
| 1228 | them. */ | 1228 | them. */ |
| 1229 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 1229 | for (auto& i : drv.outputs) { |
| 1230 | Path path = i->second.path; | 1230 | Path path = i.second.path; |
| 1231 | if (worker.store.isValidPath(path)) continue; | 1231 | if (worker.store.isValidPath(path)) continue; |
| 1232 | if (!pathExists(path)) continue; | 1232 | if (!pathExists(path)) continue; |
| 1233 | debug(format("removing invalid path `%1%'") % path); | 1233 | debug(format("removing invalid path `%1%'") % path); |
| @@ -1237,8 +1237,8 @@ void DerivationGoal::tryToBuild() | |||
| 1237 | /* Check again whether any output previously failed to build, | 1237 | /* Check again whether any output previously failed to build, |
| 1238 | because some other process may have tried and failed before we | 1238 | because some other process may have tried and failed before we |
| 1239 | acquired the lock. */ | 1239 | acquired the lock. */ |
| 1240 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 1240 | for (auto& i : drv.outputs) |
| 1241 | if (pathFailed(i->second.path)) return; | 1241 | if (pathFailed(i.second.path)) return; |
| 1242 | 1242 | ||
| 1243 | /* Don't do a remote build if the derivation has the attribute | 1243 | /* Don't do a remote build if the derivation has the attribute |
| 1244 | `preferLocalBuild' set. Also, check and repair modes are only | 1244 | `preferLocalBuild' set. Also, check and repair modes are only |
| @@ -1415,11 +1415,11 @@ void DerivationGoal::buildDone() | |||
| 1415 | /* Move paths out of the chroot for easier debugging of | 1415 | /* Move paths out of the chroot for easier debugging of |
| 1416 | build failures. */ | 1416 | build failures. */ |
| 1417 | if (useChroot && buildMode == bmNormal) | 1417 | if (useChroot && buildMode == bmNormal) |
| 1418 | foreach (PathSet::iterator, i, missingPaths) | 1418 | for (auto& i : missingPaths) |
| 1419 | if (pathExists(chrootRootDir + *i)) { | 1419 | if (pathExists(chrootRootDir + i)) { |
| 1420 | try { | 1420 | try { |
| 1421 | secureFilePerms(chrootRootDir + *i); | 1421 | secureFilePerms(chrootRootDir + i); |
| 1422 | rename((chrootRootDir + *i).c_str(), i->c_str()); | 1422 | rename((chrootRootDir + i).c_str(), i.c_str()); |
| 1423 | } catch(Error & e) { | 1423 | } catch(Error & e) { |
| 1424 | printMsg(lvlError, e.msg()); | 1424 | printMsg(lvlError, e.msg()); |
| 1425 | } | 1425 | } |
| @@ -1436,8 +1436,8 @@ void DerivationGoal::buildDone() | |||
| 1436 | /* Replace the output, if it exists, by a fresh copy of itself to | 1436 | /* Replace the output, if it exists, by a fresh copy of itself to |
| 1437 | make sure that there's no stale file descriptor pointing to it | 1437 | make sure that there's no stale file descriptor pointing to it |
| 1438 | (CVE-2024-27297). */ | 1438 | (CVE-2024-27297). */ |
| 1439 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 1439 | for (auto& i : drv.outputs) { |
| 1440 | Path output = chrootRootDir + i->second.path; | 1440 | Path output = chrootRootDir + i.second.path; |
| 1441 | if (pathExists(output)) { | 1441 | if (pathExists(output)) { |
| 1442 | Path pivot = output + ".tmp"; | 1442 | Path pivot = output + ".tmp"; |
| 1443 | copyFileRecursively(output, pivot, true); | 1443 | copyFileRecursively(output, pivot, true); |
| @@ -1454,8 +1454,8 @@ void DerivationGoal::buildDone() | |||
| 1454 | registerOutputs(); | 1454 | registerOutputs(); |
| 1455 | 1455 | ||
| 1456 | /* Delete unused redirected outputs (when doing hash rewriting). */ | 1456 | /* Delete unused redirected outputs (when doing hash rewriting). */ |
| 1457 | foreach (RedirectedOutputs::iterator, i, redirectedOutputs) | 1457 | for (auto& i : redirectedOutputs) |
| 1458 | if (pathExists(i->second)) deletePath(i->second); | 1458 | if (pathExists(i.second)) deletePath(i.second); |
| 1459 | 1459 | ||
| 1460 | /* Delete the chroot (if we were using one). */ | 1460 | /* Delete the chroot (if we were using one). */ |
| 1461 | autoDelChroot.reset(); /* this runs the destructor */ | 1461 | autoDelChroot.reset(); /* this runs the destructor */ |
| @@ -1516,8 +1516,8 @@ void DerivationGoal::buildDone() | |||
| 1516 | Hook errors (like communication problems with the | 1516 | Hook errors (like communication problems with the |
| 1517 | remote machine) shouldn't be cached either. */ | 1517 | remote machine) shouldn't be cached either. */ |
| 1518 | if (settings.cacheFailure && !fixedOutput && !diskFull) | 1518 | if (settings.cacheFailure && !fixedOutput && !diskFull) |
| 1519 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 1519 | for (auto& i : drv.outputs) |
| 1520 | worker.store.registerFailedPath(i->second.path); | 1520 | worker.store.registerFailedPath(i.second.path); |
| 1521 | } | 1521 | } |
| 1522 | 1522 | ||
| 1523 | done(st, e.msg()); | 1523 | done(st, e.msg()); |
| @@ -1554,7 +1554,7 @@ HookReply DerivationGoal::tryBuildHook() | |||
| 1554 | required from the build machine. (The hook could parse the | 1554 | required from the build machine. (The hook could parse the |
| 1555 | drv file itself, but this is easier.) */ | 1555 | drv file itself, but this is easier.) */ |
| 1556 | Strings features = tokenizeString<Strings>(get(drv.env, "requiredSystemFeatures")); | 1556 | Strings features = tokenizeString<Strings>(get(drv.env, "requiredSystemFeatures")); |
| 1557 | foreach (Strings::iterator, i, features) checkStoreName(*i); /* !!! abuse */ | 1557 | for (auto& i : features) checkStoreName(i); /* !!! abuse */ |
| 1558 | 1558 | ||
| 1559 | /* Send the request to the hook. */ | 1559 | /* Send the request to the hook. */ |
| 1560 | writeLine(worker.hook->toAgent.writeSide, (format("%1% %2% %3% %4%") | 1560 | writeLine(worker.hook->toAgent.writeSide, (format("%1% %2% %3% %4%") |
| @@ -1596,13 +1596,13 @@ HookReply DerivationGoal::tryBuildHook() | |||
| 1596 | computeFSClosure(worker.store, drvPath, allInputs); | 1596 | computeFSClosure(worker.store, drvPath, allInputs); |
| 1597 | 1597 | ||
| 1598 | string s; | 1598 | string s; |
| 1599 | foreach (PathSet::iterator, i, allInputs) { s += *i; s += ' '; } | 1599 | for (auto& i : allInputs) { s += i; s += ' '; } |
| 1600 | writeLine(hook->toAgent.writeSide, s); | 1600 | writeLine(hook->toAgent.writeSide, s); |
| 1601 | 1601 | ||
| 1602 | /* Tell the hooks the missing outputs that have to be copied back | 1602 | /* Tell the hooks the missing outputs that have to be copied back |
| 1603 | from the remote system. */ | 1603 | from the remote system. */ |
| 1604 | s = ""; | 1604 | s = ""; |
| 1605 | foreach (PathSet::iterator, i, missingPaths) { s += *i; s += ' '; } | 1605 | for (auto& i : missingPaths) { s += i; s += ' '; } |
| 1606 | writeLine(hook->toAgent.writeSide, s); | 1606 | writeLine(hook->toAgent.writeSide, s); |
| 1607 | 1607 | ||
| 1608 | hook->toAgent.writeSide.close(); | 1608 | hook->toAgent.writeSide.close(); |
| @@ -1698,8 +1698,8 @@ void DerivationGoal::startBuilder() | |||
| 1698 | env["NIX_BUILD_CORES"] = (format("%d") % settings.buildCores).str(); | 1698 | env["NIX_BUILD_CORES"] = (format("%d") % settings.buildCores).str(); |
| 1699 | 1699 | ||
| 1700 | /* Add all bindings specified in the derivation. */ | 1700 | /* Add all bindings specified in the derivation. */ |
| 1701 | foreach (StringPairs::iterator, i, drv.env) | 1701 | for (auto& i : drv.env) |
| 1702 | env[i->first] = i->second; | 1702 | env[i.first] = i.second; |
| 1703 | 1703 | ||
| 1704 | /* Create a temporary directory where the build will take | 1704 | /* Create a temporary directory where the build will take |
| 1705 | place. */ | 1705 | place. */ |
| @@ -1752,7 +1752,7 @@ void DerivationGoal::startBuilder() | |||
| 1752 | already know the cryptographic hash of the output). */ | 1752 | already know the cryptographic hash of the output). */ |
| 1753 | if (fixedOutput) { | 1753 | if (fixedOutput) { |
| 1754 | Strings varNames = tokenizeString<Strings>(get(drv.env, "impureEnvVars")); | 1754 | Strings varNames = tokenizeString<Strings>(get(drv.env, "impureEnvVars")); |
| 1755 | foreach (Strings::iterator, i, varNames) env[*i] = getEnv(*i); | 1755 | for (auto& i : varNames) env[i] = getEnv(i); |
| 1756 | } | 1756 | } |
| 1757 | 1757 | ||
| 1758 | /* The `exportReferencesGraph' feature allows the references graph | 1758 | /* The `exportReferencesGraph' feature allows the references graph |
| @@ -1788,11 +1788,11 @@ void DerivationGoal::startBuilder() | |||
| 1788 | computeFSClosure(worker.store, storePath, paths); | 1788 | computeFSClosure(worker.store, storePath, paths); |
| 1789 | paths2 = paths; | 1789 | paths2 = paths; |
| 1790 | 1790 | ||
| 1791 | foreach (PathSet::iterator, j, paths2) { | 1791 | for (auto& j : paths2) { |
| 1792 | if (isDerivation(*j)) { | 1792 | if (isDerivation(j)) { |
| 1793 | Derivation drv = derivationFromPath(worker.store, *j); | 1793 | Derivation drv = derivationFromPath(worker.store, j); |
| 1794 | foreach (DerivationOutputs::iterator, k, drv.outputs) | 1794 | for (auto& k : drv.outputs) |
| 1795 | computeFSClosure(worker.store, k->second.path, paths); | 1795 | computeFSClosure(worker.store, k.second.path, paths); |
| 1796 | } | 1796 | } |
| 1797 | } | 1797 | } |
| 1798 | 1798 | ||
| @@ -1896,10 +1896,10 @@ void DerivationGoal::startBuilder() | |||
| 1896 | /* Make the closure of the inputs available in the chroot, rather than | 1896 | /* Make the closure of the inputs available in the chroot, rather than |
| 1897 | the whole store. This prevents any access to undeclared | 1897 | the whole store. This prevents any access to undeclared |
| 1898 | dependencies. */ | 1898 | dependencies. */ |
| 1899 | foreach (PathSet::iterator, i, inputPaths) { | 1899 | for (auto& i : inputPaths) { |
| 1900 | struct stat st; | 1900 | struct stat st; |
| 1901 | if (lstat(i->c_str(), &st)) | 1901 | if (lstat(i.c_str(), &st)) |
| 1902 | throw SysError(format("getting attributes of path `%1%'") % *i); | 1902 | throw SysError(format("getting attributes of path `%1%'") % i); |
| 1903 | 1903 | ||
| 1904 | if (S_ISLNK(st.st_mode)) { | 1904 | if (S_ISLNK(st.st_mode)) { |
| 1905 | /* Since bind-mounts follow symlinks, thus representing their | 1905 | /* Since bind-mounts follow symlinks, thus representing their |
| @@ -1907,12 +1907,12 @@ void DerivationGoal::startBuilder() | |||
| 1907 | symlinks. XXX: When running unprivileged, TARGET can be | 1907 | symlinks. XXX: When running unprivileged, TARGET can be |
| 1908 | deleted by the build process. Use 'open_tree' & co. when | 1908 | deleted by the build process. Use 'open_tree' & co. when |
| 1909 | it's more widely available. */ | 1909 | it's more widely available. */ |
| 1910 | Path target = chrootRootDir + *i; | 1910 | Path target = chrootRootDir + i; |
| 1911 | if (symlink(readLink(*i).c_str(), target.c_str()) == -1) | 1911 | if (symlink(readLink(i).c_str(), target.c_str()) == -1) |
| 1912 | throw SysError(format("failed to create symlink '%1%' to '%2%'") % target % readLink(*i)); | 1912 | throw SysError(format("failed to create symlink '%1%' to '%2%'") % target % readLink(i)); |
| 1913 | } | 1913 | } |
| 1914 | else | 1914 | else |
| 1915 | dirsInChroot[*i] = *i; | 1915 | dirsInChroot[i] = i; |
| 1916 | } | 1916 | } |
| 1917 | 1917 | ||
| 1918 | /* If we're repairing, checking or rebuilding part of a | 1918 | /* If we're repairing, checking or rebuilding part of a |
| @@ -1943,16 +1943,16 @@ void DerivationGoal::startBuilder() | |||
| 1943 | contents of the new outputs to replace the dummy strings | 1943 | contents of the new outputs to replace the dummy strings |
| 1944 | with the actual hashes. */ | 1944 | with the actual hashes. */ |
| 1945 | if (validPaths.size() > 0) | 1945 | if (validPaths.size() > 0) |
| 1946 | foreach (PathSet::iterator, i, validPaths) | 1946 | for (auto i : validPaths) |
| 1947 | addHashRewrite(*i); | 1947 | addHashRewrite(i); |
| 1948 | 1948 | ||
| 1949 | /* If we're repairing, then we don't want to delete the | 1949 | /* If we're repairing, then we don't want to delete the |
| 1950 | corrupt outputs in advance. So rewrite them as well. */ | 1950 | corrupt outputs in advance. So rewrite them as well. */ |
| 1951 | if (buildMode == bmRepair) | 1951 | if (buildMode == bmRepair) |
| 1952 | foreach (PathSet::iterator, i, missingPaths) | 1952 | for (auto& i : missingPaths) |
| 1953 | if (worker.store.isValidPath(*i) && pathExists(*i)) { | 1953 | if (worker.store.isValidPath(i) && pathExists(i)) { |
| 1954 | addHashRewrite(*i); | 1954 | addHashRewrite(i); |
| 1955 | redirectedBadOutputs.insert(*i); | 1955 | redirectedBadOutputs.insert(i); |
| 1956 | } | 1956 | } |
| 1957 | } | 1957 | } |
| 1958 | 1958 | ||
| @@ -2186,10 +2186,10 @@ void DerivationGoal::runChild() | |||
| 2186 | /* Bind-mount all the directories from the "host" | 2186 | /* Bind-mount all the directories from the "host" |
| 2187 | filesystem that we want in the chroot | 2187 | filesystem that we want in the chroot |
| 2188 | environment. */ | 2188 | environment. */ |
| 2189 | foreach (DirsInChroot::iterator, i, dirsInChroot) { | 2189 | for (auto& i : dirsInChroot) { |
| 2190 | struct stat st; | 2190 | struct stat st; |
| 2191 | Path source = i->second; | 2191 | Path source = i.second; |
| 2192 | Path target = chrootRootDir + i->first; | 2192 | Path target = chrootRootDir + i.first; |
| 2193 | if (source == "/proc") continue; // backwards compatibility | 2193 | if (source == "/proc") continue; // backwards compatibility |
| 2194 | if (stat(source.c_str(), &st) == -1) | 2194 | if (stat(source.c_str(), &st) == -1) |
| 2195 | throw SysError(format("getting attributes of path `%1%'") % source); | 2195 | throw SysError(format("getting attributes of path `%1%'") % source); |
| @@ -2340,8 +2340,8 @@ void DerivationGoal::runChild() | |||
| 2340 | 2340 | ||
| 2341 | /* Fill in the environment. */ | 2341 | /* Fill in the environment. */ |
| 2342 | Strings envStrs; | 2342 | Strings envStrs; |
| 2343 | foreach (Environment::const_iterator, i, env) | 2343 | for (const auto& i : env) |
| 2344 | envStrs.push_back(rewriteHashes(i->first + "=" + i->second, rewritesToTmp)); | 2344 | envStrs.push_back(rewriteHashes(i.first + "=" + i.second, rewritesToTmp)); |
| 2345 | 2345 | ||
| 2346 | /* If we are running in `build-users' mode, then switch to the | 2346 | /* If we are running in `build-users' mode, then switch to the |
| 2347 | user we allocated above. Make sure that we drop all root | 2347 | user we allocated above. Make sure that we drop all root |
| @@ -2420,8 +2420,8 @@ void DerivationGoal::runChild() | |||
| 2420 | /* Fill in the arguments. */ | 2420 | /* Fill in the arguments. */ |
| 2421 | Strings args; | 2421 | Strings args; |
| 2422 | args.push_back(builderBasename); | 2422 | args.push_back(builderBasename); |
| 2423 | foreach (Strings::iterator, i, drv.args) | 2423 | for (auto& i : drv.args) |
| 2424 | args.push_back(rewriteHashes(*i, rewritesToTmp)); | 2424 | args.push_back(rewriteHashes(i, rewritesToTmp)); |
| 2425 | 2425 | ||
| 2426 | /* If DRV targets the same operating system kernel, try to execute it: | 2426 | /* If DRV targets the same operating system kernel, try to execute it: |
| 2427 | there might be binfmt_misc set up for user-land emulation of other | 2427 | there might be binfmt_misc set up for user-land emulation of other |
| @@ -2468,14 +2468,14 @@ PathSet parseReferenceSpecifiers(const Derivation & drv, string attr) | |||
| 2468 | { | 2468 | { |
| 2469 | PathSet result; | 2469 | PathSet result; |
| 2470 | Paths paths = tokenizeString<Paths>(attr); | 2470 | Paths paths = tokenizeString<Paths>(attr); |
| 2471 | foreach (Strings::iterator, i, paths) { | 2471 | for (auto& i : paths) { |
| 2472 | if (isStorePath(*i)) | 2472 | if (isStorePath(i)) |
| 2473 | result.insert(*i); | 2473 | result.insert(i); |
| 2474 | else if (drv.outputs.find(*i) != drv.outputs.end()) | 2474 | else if (drv.outputs.find(i) != drv.outputs.end()) |
| 2475 | result.insert(drv.outputs.find(*i)->second.path); | 2475 | result.insert(drv.outputs.find(i)->second.path); |
| 2476 | else throw BuildError( | 2476 | else throw BuildError( |
| 2477 | format("derivation contains an invalid reference specifier `%1%'") | 2477 | format("derivation contains an invalid reference specifier `%1%'") |
| 2478 | % *i); | 2478 | % i); |
| 2479 | } | 2479 | } |
| 2480 | return result; | 2480 | return result; |
| 2481 | } | 2481 | } |
| @@ -2488,8 +2488,8 @@ void DerivationGoal::registerOutputs() | |||
| 2488 | to do anything here. */ | 2488 | to do anything here. */ |
| 2489 | if (hook) { | 2489 | if (hook) { |
| 2490 | bool allValid = true; | 2490 | bool allValid = true; |
| 2491 | foreach (DerivationOutputs::iterator, i, drv.outputs) | 2491 | for (auto& i : drv.outputs) |
| 2492 | if (!worker.store.isValidPath(i->second.path)) allValid = false; | 2492 | if (!worker.store.isValidPath(i.second.path)) allValid = false; |
| 2493 | if (allValid) return; | 2493 | if (allValid) return; |
| 2494 | } | 2494 | } |
| 2495 | 2495 | ||
| @@ -2505,8 +2505,8 @@ void DerivationGoal::registerOutputs() | |||
| 2505 | /* Check whether the output paths were created, and grep each | 2505 | /* Check whether the output paths were created, and grep each |
| 2506 | output path to determine what other paths it references. Also make all | 2506 | output path to determine what other paths it references. Also make all |
| 2507 | output paths read-only. */ | 2507 | output paths read-only. */ |
| 2508 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 2508 | for (auto& i : drv.outputs) { |
| 2509 | Path path = i->second.path; | 2509 | Path path = i.second.path; |
| 2510 | if (missingPaths.find(path) == missingPaths.end()) continue; | 2510 | if (missingPaths.find(path) == missingPaths.end()) continue; |
| 2511 | 2511 | ||
| 2512 | Path actualPath = path; | 2512 | Path actualPath = path; |
| @@ -2568,10 +2568,10 @@ void DerivationGoal::registerOutputs() | |||
| 2568 | /* Check that fixed-output derivations produced the right | 2568 | /* Check that fixed-output derivations produced the right |
| 2569 | outputs (i.e., the content hash should match the specified | 2569 | outputs (i.e., the content hash should match the specified |
| 2570 | hash). */ | 2570 | hash). */ |
| 2571 | if (i->second.hash != "") { | 2571 | if (i.second.hash != "") { |
| 2572 | 2572 | ||
| 2573 | bool recursive; HashType ht; Hash h; | 2573 | bool recursive; HashType ht; Hash h; |
| 2574 | i->second.parseHashInfo(recursive, ht, h); | 2574 | i.second.parseHashInfo(recursive, ht, h); |
| 2575 | 2575 | ||
| 2576 | if (!recursive) { | 2576 | if (!recursive) { |
| 2577 | /* The output path should be a regular file without | 2577 | /* The output path should be a regular file without |
| @@ -2586,7 +2586,7 @@ void DerivationGoal::registerOutputs() | |||
| 2586 | if (h != h2) { | 2586 | if (h != h2) { |
| 2587 | if (settings.printBuildTrace) | 2587 | if (settings.printBuildTrace) |
| 2588 | printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%") | 2588 | printMsg(lvlError, format("@ hash-mismatch %1% %2% %3% %4%") |
| 2589 | % path % i->second.hashAlgo | 2589 | % path % i.second.hashAlgo |
| 2590 | % printHash16or32(h) % printHash16or32(h2)); | 2590 | % printHash16or32(h) % printHash16or32(h2)); |
| 2591 | throw BuildError(format("hash mismatch for store item '%1%'") % path); | 2591 | throw BuildError(format("hash mismatch for store item '%1%'") % path); |
| 2592 | } | 2592 | } |
| @@ -2650,12 +2650,12 @@ void DerivationGoal::registerOutputs() | |||
| 2650 | 2650 | ||
| 2651 | /* For debugging, print out the referenced and unreferenced | 2651 | /* For debugging, print out the referenced and unreferenced |
| 2652 | paths. */ | 2652 | paths. */ |
| 2653 | foreach (PathSet::iterator, i, inputPaths) { | 2653 | for (auto& i : inputPaths) { |
| 2654 | PathSet::iterator j = references.find(*i); | 2654 | PathSet::iterator j = references.find(i); |
| 2655 | if (j == references.end()) | 2655 | if (j == references.end()) |
| 2656 | debug(format("unreferenced input: `%1%'") % *i); | 2656 | debug(format("unreferenced input: `%1%'") % i); |
| 2657 | else | 2657 | else |
| 2658 | debug(format("referenced input: `%1%'") % *i); | 2658 | debug(format("referenced input: `%1%'") % i); |
| 2659 | } | 2659 | } |
| 2660 | 2660 | ||
| 2661 | /* Enforce `allowedReferences' and friends. */ | 2661 | /* Enforce `allowedReferences' and friends. */ |
| @@ -2985,12 +2985,12 @@ void DerivationGoal::handleEOF(int fd) | |||
| 2985 | PathSet DerivationGoal::checkPathValidity(bool returnValid, bool checkHash) | 2985 | PathSet DerivationGoal::checkPathValidity(bool returnValid, bool checkHash) |
| 2986 | { | 2986 | { |
| 2987 | PathSet result; | 2987 | PathSet result; |
| 2988 | foreach (DerivationOutputs::iterator, i, drv.outputs) { | 2988 | for (auto& i : drv.outputs) { |
| 2989 | if (!wantOutput(i->first, wantedOutputs)) continue; | 2989 | if (!wantOutput(i.first, wantedOutputs)) continue; |
| 2990 | bool good = | 2990 | bool good = |
| 2991 | worker.store.isValidPath(i->second.path) && | 2991 | worker.store.isValidPath(i.second.path) && |
| 2992 | (!checkHash || worker.store.pathContentsGood(i->second.path)); | 2992 | (!checkHash || worker.store.pathContentsGood(i.second.path)); |
| 2993 | if (good == returnValid) result.insert(i->second.path); | 2993 | if (good == returnValid) result.insert(i.second.path); |
| 2994 | } | 2994 | } |
| 2995 | return result; | 2995 | return result; |
| 2996 | } | 2996 | } |
| @@ -3186,9 +3186,9 @@ void SubstitutionGoal::tryNext() | |||
| 3186 | 3186 | ||
| 3187 | /* To maintain the closure invariant, we first have to realise the | 3187 | /* To maintain the closure invariant, we first have to realise the |
| 3188 | paths referenced by this one. */ | 3188 | paths referenced by this one. */ |
| 3189 | foreach (PathSet::iterator, i, info.references) | 3189 | for (auto& i : info.references) |
| 3190 | if (*i != storePath) /* ignore self-references */ | 3190 | if (i != storePath) /* ignore self-references */ |
| 3191 | addWaitee(worker.makeSubstitutionGoal(*i)); | 3191 | addWaitee(worker.makeSubstitutionGoal(i)); |
| 3192 | 3192 | ||
| 3193 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ | 3193 | if (waitees.empty()) /* to prevent hang (no wake-up event) */ |
| 3194 | referencesValid(); | 3194 | referencesValid(); |
| @@ -3207,9 +3207,9 @@ void SubstitutionGoal::referencesValid() | |||
| 3207 | return; | 3207 | return; |
| 3208 | } | 3208 | } |
| 3209 | 3209 | ||
| 3210 | foreach (PathSet::iterator, i, info.references) | 3210 | for (auto& i : info.references) |
| 3211 | if (*i != storePath) /* ignore self-references */ | 3211 | if (i != storePath) /* ignore self-references */ |
| 3212 | assert(worker.store.isValidPath(*i)); | 3212 | assert(worker.store.isValidPath(i)); |
| 3213 | 3213 | ||
| 3214 | state = &SubstitutionGoal::tryToRun; | 3214 | state = &SubstitutionGoal::tryToRun; |
| 3215 | worker.wakeUp(shared_from_this()); | 3215 | worker.wakeUp(shared_from_this()); |
| @@ -3521,8 +3521,8 @@ void Worker::removeGoal(GoalPtr goal) | |||
| 3521 | } | 3521 | } |
| 3522 | 3522 | ||
| 3523 | /* Wake up goals waiting for any goal to finish. */ | 3523 | /* Wake up goals waiting for any goal to finish. */ |
| 3524 | foreach (WeakGoals::iterator, i, waitingForAnyGoal) { | 3524 | for (auto& i : waitingForAnyGoal) { |
| 3525 | GoalPtr goal = i->lock(); | 3525 | GoalPtr goal = i.lock(); |
| 3526 | if (goal) wakeUp(goal); | 3526 | if (goal) wakeUp(goal); |
| 3527 | } | 3527 | } |
| 3528 | 3528 | ||
| @@ -3575,8 +3575,8 @@ void Worker::childTerminated(pid_t pid, bool wakeSleepers) | |||
| 3575 | if (wakeSleepers) { | 3575 | if (wakeSleepers) { |
| 3576 | 3576 | ||
| 3577 | /* Wake up goals waiting for a build slot. */ | 3577 | /* Wake up goals waiting for a build slot. */ |
| 3578 | foreach (WeakGoals::iterator, i, wantingToBuild) { | 3578 | for (auto& i : wantingToBuild) { |
| 3579 | GoalPtr goal = i->lock(); | 3579 | GoalPtr goal = i.lock(); |
| 3580 | if (goal) wakeUp(goal); | 3580 | if (goal) wakeUp(goal); |
| 3581 | } | 3581 | } |
| 3582 | 3582 | ||
| @@ -3611,7 +3611,7 @@ void Worker::waitForAWhile(GoalPtr goal) | |||
| 3611 | 3611 | ||
| 3612 | void Worker::run(const Goals & _topGoals) | 3612 | void Worker::run(const Goals & _topGoals) |
| 3613 | { | 3613 | { |
| 3614 | foreach (Goals::iterator, i, _topGoals) topGoals.insert(*i); | 3614 | for (auto& i : _topGoals) topGoals.insert(i); |
| 3615 | 3615 | ||
| 3616 | startNest(nest, lvlDebug, format("entered goal loop")); | 3616 | startNest(nest, lvlDebug, format("entered goal loop")); |
| 3617 | 3617 | ||
| @@ -3677,12 +3677,12 @@ void Worker::waitForInput() | |||
| 3677 | deadline for any child. */ | 3677 | deadline for any child. */ |
| 3678 | assert(sizeof(time_t) >= sizeof(long)); | 3678 | assert(sizeof(time_t) >= sizeof(long)); |
| 3679 | time_t nearest = LONG_MAX; // nearest deadline | 3679 | time_t nearest = LONG_MAX; // nearest deadline |
| 3680 | foreach (Children::iterator, i, children) { | 3680 | for (auto& i : children) { |
| 3681 | if (!i->second.respectTimeouts) continue; | 3681 | if (!i.second.respectTimeouts) continue; |
| 3682 | if (settings.maxSilentTime != 0) | 3682 | if (settings.maxSilentTime != 0) |
| 3683 | nearest = std::min(nearest, i->second.lastOutput + settings.maxSilentTime); | 3683 | nearest = std::min(nearest, i.second.lastOutput + settings.maxSilentTime); |
| 3684 | if (settings.buildTimeout != 0) | 3684 | if (settings.buildTimeout != 0) |
| 3685 | nearest = std::min(nearest, i->second.timeStarted + settings.buildTimeout); | 3685 | nearest = std::min(nearest, i.second.timeStarted + settings.buildTimeout); |
| 3686 | } | 3686 | } |
| 3687 | if (nearest != LONG_MAX) { | 3687 | if (nearest != LONG_MAX) { |
| 3688 | timeout.tv_sec = std::max((time_t) 1, nearest - before); | 3688 | timeout.tv_sec = std::max((time_t) 1, nearest - before); |
| @@ -3707,10 +3707,10 @@ void Worker::waitForInput() | |||
| 3707 | fd_set fds; | 3707 | fd_set fds; |
| 3708 | FD_ZERO(&fds); | 3708 | FD_ZERO(&fds); |
| 3709 | int fdMax = 0; | 3709 | int fdMax = 0; |
| 3710 | foreach (Children::iterator, i, children) { | 3710 | for (auto& i : children) { |
| 3711 | foreach (set<int>::iterator, j, i->second.fds) { | 3711 | for (auto& j : i.second.fds) { |
| 3712 | FD_SET(*j, &fds); | 3712 | FD_SET(j, &fds); |
| 3713 | if (*j >= fdMax) fdMax = *j + 1; | 3713 | if (j >= fdMax) fdMax = j + 1; |
| 3714 | } | 3714 | } |
| 3715 | } | 3715 | } |
| 3716 | 3716 | ||
| @@ -3728,34 +3728,34 @@ void Worker::waitForInput() | |||
| 3728 | careful that we don't keep iterators alive across calls to | 3728 | careful that we don't keep iterators alive across calls to |
| 3729 | timedOut(). */ | 3729 | timedOut(). */ |
| 3730 | set<pid_t> pids; | 3730 | set<pid_t> pids; |
| 3731 | foreach (Children::iterator, i, children) pids.insert(i->first); | 3731 | for (auto& i : children) pids.insert(i.first); |
| 3732 | 3732 | ||
| 3733 | foreach (set<pid_t>::iterator, i, pids) { | 3733 | for (auto& i : pids) { |
| 3734 | checkInterrupt(); | 3734 | checkInterrupt(); |
| 3735 | Children::iterator j = children.find(*i); | 3735 | Children::iterator j = children.find(i); |
| 3736 | if (j == children.end()) continue; // child destroyed | 3736 | if (j == children.end()) continue; // child destroyed |
| 3737 | GoalPtr goal = j->second.goal.lock(); | 3737 | GoalPtr goal = j->second.goal.lock(); |
| 3738 | assert(goal); | 3738 | assert(goal); |
| 3739 | 3739 | ||
| 3740 | set<int> fds2(j->second.fds); | 3740 | set<int> fds2(j->second.fds); |
| 3741 | foreach (set<int>::iterator, k, fds2) { | 3741 | for (auto& k : fds2) { |
| 3742 | if (FD_ISSET(*k, &fds)) { | 3742 | if (FD_ISSET(k, &fds)) { |
| 3743 | unsigned char buffer[4096]; | 3743 | unsigned char buffer[4096]; |
| 3744 | ssize_t rd = read(*k, buffer, sizeof(buffer)); | 3744 | ssize_t rd = read(k, buffer, sizeof(buffer)); |
| 3745 | if (rd == -1) { | 3745 | if (rd == -1) { |
| 3746 | if (errno != EINTR) | 3746 | if (errno != EINTR) |
| 3747 | throw SysError(format("reading from %1%") | 3747 | throw SysError(format("reading from %1%") |
| 3748 | % goal->getName()); | 3748 | % goal->getName()); |
| 3749 | } else if (rd == 0) { | 3749 | } else if (rd == 0) { |
| 3750 | debug(format("%1%: got EOF") % goal->getName()); | 3750 | debug(format("%1%: got EOF") % goal->getName()); |
| 3751 | goal->handleEOF(*k); | 3751 | goal->handleEOF(k); |
| 3752 | j->second.fds.erase(*k); | 3752 | j->second.fds.erase(k); |
| 3753 | } else { | 3753 | } else { |
| 3754 | printMsg(lvlVomit, format("%1%: read %2% bytes") | 3754 | printMsg(lvlVomit, format("%1%: read %2% bytes") |
| 3755 | % goal->getName() % rd); | 3755 | % goal->getName() % rd); |
| 3756 | string data((char *) buffer, rd); | 3756 | string data((char *) buffer, rd); |
| 3757 | j->second.lastOutput = after; | 3757 | j->second.lastOutput = after; |
| 3758 | goal->handleChildOutput(*k, data); | 3758 | goal->handleChildOutput(k, data); |
| 3759 | } | 3759 | } |
| 3760 | } | 3760 | } |
| 3761 | } | 3761 | } |
| @@ -3785,8 +3785,8 @@ void Worker::waitForInput() | |||
| 3785 | 3785 | ||
| 3786 | if (!waitingForAWhile.empty() && lastWokenUp + settings.pollInterval <= after) { | 3786 | if (!waitingForAWhile.empty() && lastWokenUp + settings.pollInterval <= after) { |
| 3787 | lastWokenUp = after; | 3787 | lastWokenUp = after; |
| 3788 | foreach (WeakGoals::iterator, i, waitingForAWhile) { | 3788 | for (auto& i : waitingForAWhile) { |
| 3789 | GoalPtr goal = i->lock(); | 3789 | GoalPtr goal = i.lock(); |
| 3790 | if (goal) wakeUp(goal); | 3790 | if (goal) wakeUp(goal); |
| 3791 | } | 3791 | } |
| 3792 | waitingForAWhile.clear(); | 3792 | waitingForAWhile.clear(); |
| @@ -3811,22 +3811,22 @@ void LocalStore::buildPaths(const PathSet & drvPaths, BuildMode buildMode) | |||
| 3811 | Worker worker(*this); | 3811 | Worker worker(*this); |
| 3812 | 3812 | ||
| 3813 | Goals goals; | 3813 | Goals goals; |
| 3814 | foreach (PathSet::const_iterator, i, drvPaths) { | 3814 | for (auto& i : drvPaths) { |
| 3815 | DrvPathWithOutputs i2 = parseDrvPathWithOutputs(*i); | 3815 | DrvPathWithOutputs i2 = parseDrvPathWithOutputs(i); |
| 3816 | if (isDerivation(i2.first)) | 3816 | if (isDerivation(i2.first)) |
| 3817 | goals.insert(worker.makeDerivationGoal(i2.first, i2.second, buildMode)); | 3817 | goals.insert(worker.makeDerivationGoal(i2.first, i2.second, buildMode)); |
| 3818 | else | 3818 | else |
| 3819 | goals.insert(worker.makeSubstitutionGoal(*i, buildMode)); | 3819 | goals.insert(worker.makeSubstitutionGoal(i, buildMode)); |
| 3820 | } | 3820 | } |
| 3821 | 3821 | ||
| 3822 | worker.run(goals); | 3822 | worker.run(goals); |
| 3823 | 3823 | ||
| 3824 | PathSet failed; | 3824 | PathSet failed; |
| 3825 | foreach (Goals::iterator, i, goals) | 3825 | for (auto& i : goals) |
| 3826 | if ((*i)->getExitCode() == Goal::ecFailed) { | 3826 | if (i->getExitCode() == Goal::ecFailed) { |
| 3827 | DerivationGoal * i2 = dynamic_cast<DerivationGoal *>(i->get()); | 3827 | DerivationGoal * i2 = dynamic_cast<DerivationGoal *>(i.get()); |
| 3828 | if (i2) failed.insert(i2->getDrvPath()); | 3828 | if (i2) failed.insert(i2->getDrvPath()); |
| 3829 | else failed.insert(dynamic_cast<SubstitutionGoal *>(i->get())->getStorePath()); | 3829 | else failed.insert(dynamic_cast<SubstitutionGoal *>(i.get())->getStorePath()); |
| 3830 | } | 3830 | } |
| 3831 | 3831 | ||
| 3832 | if (!failed.empty()) | 3832 | if (!failed.empty()) |
diff --git a/nix/libstore/derivations.cc b/nix/libstore/derivations.cc index d316f6c7bf1..0c3a249228d 100644 --- a/nix/libstore/derivations.cc +++ b/nix/libstore/derivations.cc | |||
| @@ -31,8 +31,8 @@ Path writeDerivation(StoreAPI & store, | |||
| 31 | { | 31 | { |
| 32 | PathSet references; | 32 | PathSet references; |
| 33 | references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end()); | 33 | references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end()); |
| 34 | foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) | 34 | for (const auto& i : drv.inputDrvs) |
| 35 | references.insert(i->first); | 35 | references.insert(i.first); |
| 36 | /* Note that the outputs of a derivation are *not* references | 36 | /* Note that the outputs of a derivation are *not* references |
| 37 | (that can be missing (of course) and should not necessarily be | 37 | (that can be missing (of course) and should not necessarily be |
| 38 | held during a garbage collection). */ | 38 | held during a garbage collection). */ |
| @@ -155,21 +155,21 @@ string unparseDerivation(const Derivation & drv) | |||
| 155 | s += "Derive(["; | 155 | s += "Derive(["; |
| 156 | 156 | ||
| 157 | bool first = true; | 157 | bool first = true; |
| 158 | foreach (DerivationOutputs::const_iterator, i, drv.outputs) { | 158 | for (const auto& i : drv.outputs) { |
| 159 | if (first) first = false; else s += ','; | 159 | if (first) first = false; else s += ','; |
| 160 | s += '('; printString(s, i->first); | 160 | s += '('; printString(s, i.first); |
| 161 | s += ','; printString(s, i->second.path); | 161 | s += ','; printString(s, i.second.path); |
| 162 | s += ','; printString(s, i->second.hashAlgo); | 162 | s += ','; printString(s, i.second.hashAlgo); |
| 163 | s += ','; printString(s, i->second.hash); | 163 | s += ','; printString(s, i.second.hash); |
| 164 | s += ')'; | 164 | s += ')'; |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | s += "],["; | 167 | s += "],["; |
| 168 | first = true; | 168 | first = true; |
| 169 | foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) { | 169 | for (const auto& i : drv.inputDrvs) { |
| 170 | if (first) first = false; else s += ','; | 170 | if (first) first = false; else s += ','; |
| 171 | s += '('; printString(s, i->first); | 171 | s += '('; printString(s, i.first); |
| 172 | s += ','; printStrings(s, i->second.begin(), i->second.end()); | 172 | s += ','; printStrings(s, i.second.begin(), i.second.end()); |
| 173 | s += ')'; | 173 | s += ')'; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| @@ -182,10 +182,10 @@ string unparseDerivation(const Derivation & drv) | |||
| 182 | 182 | ||
| 183 | s += ",["; | 183 | s += ",["; |
| 184 | first = true; | 184 | first = true; |
| 185 | foreach (StringPairs::const_iterator, i, drv.env) { | 185 | for (const auto& i : drv.env) { |
| 186 | if (first) first = false; else s += ','; | 186 | if (first) first = false; else s += ','; |
| 187 | s += '('; printString(s, i->first); | 187 | s += '('; printString(s, i.first); |
| 188 | s += ','; printString(s, i->second); | 188 | s += ','; printString(s, i.second); |
| 189 | s += ')'; | 189 | s += ')'; |
| 190 | } | 190 | } |
| 191 | 191 | ||
| @@ -246,15 +246,15 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv) | |||
| 246 | /* For other derivations, replace the inputs paths with recursive | 246 | /* For other derivations, replace the inputs paths with recursive |
| 247 | calls to this function.*/ | 247 | calls to this function.*/ |
| 248 | DerivationInputs inputs2; | 248 | DerivationInputs inputs2; |
| 249 | foreach (DerivationInputs::const_iterator, i, drv.inputDrvs) { | 249 | for (const auto& i : drv.inputDrvs) { |
| 250 | Hash h = drvHashes[i->first]; | 250 | Hash h = drvHashes[i.first]; |
| 251 | if (h.type == htUnknown) { | 251 | if (h.type == htUnknown) { |
| 252 | assert(store.isValidPath(i->first)); | 252 | assert(store.isValidPath(i.first)); |
| 253 | Derivation drv2 = readDerivation(i->first); | 253 | Derivation drv2 = readDerivation(i.first); |
| 254 | h = hashDerivationModulo(store, drv2); | 254 | h = hashDerivationModulo(store, drv2); |
| 255 | drvHashes[i->first] = h; | 255 | drvHashes[i.first] = h; |
| 256 | } | 256 | } |
| 257 | inputs2[printHash(h)] = i->second; | 257 | inputs2[printHash(h)] = i.second; |
| 258 | } | 258 | } |
| 259 | drv.inputDrvs = inputs2; | 259 | drv.inputDrvs = inputs2; |
| 260 | 260 | ||
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc index 261ea79ab32..1766a684122 100644 --- a/nix/libstore/gc.cc +++ b/nix/libstore/gc.cc | |||
| @@ -349,9 +349,9 @@ static void addAdditionalRoots(StoreAPI & store, PathSet & roots) | |||
| 349 | 349 | ||
| 350 | StringSet paths = tokenizeString<StringSet>(result, "\n"); | 350 | StringSet paths = tokenizeString<StringSet>(result, "\n"); |
| 351 | 351 | ||
| 352 | foreach (StringSet::iterator, i, paths) { | 352 | for (auto i : paths) { |
| 353 | if (isInStore(*i)) { | 353 | if (isInStore(i)) { |
| 354 | Path path = toStorePath(*i); | 354 | Path path = toStorePath(i); |
| 355 | if (roots.find(path) == roots.end() && store.isValidPath(path)) { | 355 | if (roots.find(path) == roots.end() && store.isValidPath(path)) { |
| 356 | debug(format("got additional root `%1%'") % path); | 356 | debug(format("got additional root `%1%'") % path); |
| 357 | roots.insert(path); | 357 | roots.insert(path); |
| @@ -414,8 +414,8 @@ void LocalStore::deletePathRecursive(GCState & state, const Path & path) | |||
| 414 | if (isValidPath(path)) { | 414 | if (isValidPath(path)) { |
| 415 | PathSet referrers; | 415 | PathSet referrers; |
| 416 | queryReferrers(path, referrers); | 416 | queryReferrers(path, referrers); |
| 417 | foreach (PathSet::iterator, i, referrers) | 417 | for (auto& i : referrers) |
| 418 | if (*i != path) deletePathRecursive(state, *i); | 418 | if (i != path) deletePathRecursive(state, i); |
| 419 | size = queryPathInfo(path).narSize; | 419 | size = queryPathInfo(path).narSize; |
| 420 | invalidatePathChecked(path); | 420 | invalidatePathChecked(path); |
| 421 | } | 421 | } |
| @@ -505,22 +505,22 @@ bool LocalStore::canReachRoot(GCState & state, PathSet & visited, const Path & p | |||
| 505 | don't delete the derivation if any of the outputs are alive. */ | 505 | don't delete the derivation if any of the outputs are alive. */ |
| 506 | if (state.gcKeepDerivations && isDerivation(path)) { | 506 | if (state.gcKeepDerivations && isDerivation(path)) { |
| 507 | PathSet outputs = queryDerivationOutputs(path); | 507 | PathSet outputs = queryDerivationOutputs(path); |
| 508 | foreach (PathSet::iterator, i, outputs) | 508 | for (auto& i : outputs) |
| 509 | if (isValidPath(*i) && queryDeriver(*i) == path) | 509 | if (isValidPath(i) && queryDeriver(i) == path) |
| 510 | incoming.insert(*i); | 510 | incoming.insert(i); |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | /* If gc-keep-outputs is set, then don't delete this path if there | 513 | /* If gc-keep-outputs is set, then don't delete this path if there |
| 514 | are derivers of this path that are not garbage. */ | 514 | are derivers of this path that are not garbage. */ |
| 515 | if (state.gcKeepOutputs) { | 515 | if (state.gcKeepOutputs) { |
| 516 | PathSet derivers = queryValidDerivers(path); | 516 | PathSet derivers = queryValidDerivers(path); |
| 517 | foreach (PathSet::iterator, i, derivers) | 517 | for (auto& i : derivers) |
| 518 | incoming.insert(*i); | 518 | incoming.insert(i); |
| 519 | } | 519 | } |
| 520 | 520 | ||
| 521 | foreach (PathSet::iterator, i, incoming) | 521 | for (auto& i : incoming) |
| 522 | if (*i != path) | 522 | if (i != path) |
| 523 | if (canReachRoot(state, visited, *i)) { | 523 | if (canReachRoot(state, visited, i)) { |
| 524 | state.alive.insert(path); | 524 | state.alive.insert(path); |
| 525 | return true; | 525 | return true; |
| 526 | } | 526 | } |
| @@ -664,7 +664,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) | |||
| 664 | printMsg(lvlError, format("finding garbage collector roots...")); | 664 | printMsg(lvlError, format("finding garbage collector roots...")); |
| 665 | Roots rootMap = options.ignoreLiveness ? Roots() : findRoots(); | 665 | Roots rootMap = options.ignoreLiveness ? Roots() : findRoots(); |
| 666 | 666 | ||
| 667 | foreach (Roots::iterator, i, rootMap) state.roots.insert(i->second); | 667 | for (auto& i : rootMap) state.roots.insert(i.second); |
| 668 | 668 | ||
| 669 | /* Add additional roots returned by 'guix gc --list-busy'. This is | 669 | /* Add additional roots returned by 'guix gc --list-busy'. This is |
| 670 | typically used to add running programs to the set of roots (to prevent | 670 | typically used to add running programs to the set of roots (to prevent |
| @@ -700,11 +700,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) | |||
| 700 | 700 | ||
| 701 | if (options.action == GCOptions::gcDeleteSpecific) { | 701 | if (options.action == GCOptions::gcDeleteSpecific) { |
| 702 | 702 | ||
| 703 | foreach (PathSet::iterator, i, options.pathsToDelete) { | 703 | for (auto& i : options.pathsToDelete) { |
| 704 | assertStorePath(*i); | 704 | assertStorePath(i); |
| 705 | tryToDelete(state, *i); | 705 | tryToDelete(state, i); |
| 706 | if (state.dead.find(*i) == state.dead.end()) | 706 | if (state.dead.find(i) == state.dead.end()) |
| 707 | throw Error(format("cannot delete path `%1%' since it is still alive") % *i); | 707 | throw Error(format("cannot delete path `%1%' since it is still alive") % i); |
| 708 | } | 708 | } |
| 709 | 709 | ||
| 710 | } else if (options.maxFreed > 0) { | 710 | } else if (options.maxFreed > 0) { |
| @@ -750,8 +750,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) | |||
| 750 | std::default_random_engine generator(seeder()); | 750 | std::default_random_engine generator(seeder()); |
| 751 | std::shuffle(entries_.begin(), entries_.end(), generator); | 751 | std::shuffle(entries_.begin(), entries_.end(), generator); |
| 752 | 752 | ||
| 753 | foreach (vector<Path>::iterator, i, entries_) | 753 | for (auto& i : entries_) |
| 754 | tryToDelete(state, *i); | 754 | tryToDelete(state, i); |
| 755 | 755 | ||
| 756 | } catch (GCLimitReached & e) { | 756 | } catch (GCLimitReached & e) { |
| 757 | } | 757 | } |
diff --git a/nix/libstore/globals.cc b/nix/libstore/globals.cc index 89add1f107e..10c60f6106d 100644 --- a/nix/libstore/globals.cc +++ b/nix/libstore/globals.cc | |||
| @@ -188,12 +188,12 @@ template<class N> void Settings::_get(N & res, const string & name) | |||
| 188 | string Settings::pack() | 188 | string Settings::pack() |
| 189 | { | 189 | { |
| 190 | string s; | 190 | string s; |
| 191 | foreach (SettingsMap::iterator, i, settings) { | 191 | for (auto& i : settings) { |
| 192 | if (i->first.find('\n') != string::npos || | 192 | if (i.first.find('\n') != string::npos || |
| 193 | i->first.find('=') != string::npos || | 193 | i.first.find('=') != string::npos || |
| 194 | i->second.find('\n') != string::npos) | 194 | i.second.find('\n') != string::npos) |
| 195 | throw Error("invalid option name/value"); | 195 | throw Error("invalid option name/value"); |
| 196 | s += i->first; s += '='; s += i->second; s += '\n'; | 196 | s += i.first; s += '='; s += i.second; s += '\n'; |
| 197 | } | 197 | } |
| 198 | return s; | 198 | return s; |
| 199 | } | 199 | } |
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc index d544253add8..50ef707fdf3 100644 --- a/nix/libstore/local-store.cc +++ b/nix/libstore/local-store.cc | |||
| @@ -474,19 +474,19 @@ void LocalStore::checkDerivationOutputs(const Path & drvPath, const Derivation & | |||
| 474 | 474 | ||
| 475 | else { | 475 | else { |
| 476 | Derivation drvCopy(drv); | 476 | Derivation drvCopy(drv); |
| 477 | foreach (DerivationOutputs::iterator, i, drvCopy.outputs) { | 477 | for (auto& i : drvCopy.outputs) { |
| 478 | i->second.path = ""; | 478 | i.second.path = ""; |
| 479 | drvCopy.env[i->first] = ""; | 479 | drvCopy.env[i.first] = ""; |
| 480 | } | 480 | } |
| 481 | 481 | ||
| 482 | Hash h = hashDerivationModulo(*this, drvCopy); | 482 | Hash h = hashDerivationModulo(*this, drvCopy); |
| 483 | 483 | ||
| 484 | foreach (DerivationOutputs::const_iterator, i, drv.outputs) { | 484 | for (const auto& i : drv.outputs) { |
| 485 | Path outPath = makeOutputPath(i->first, h, drvName); | 485 | Path outPath = makeOutputPath(i.first, h, drvName); |
| 486 | StringPairs::const_iterator j = drv.env.find(i->first); | 486 | StringPairs::const_iterator j = drv.env.find(i.first); |
| 487 | if (i->second.path != outPath || j == drv.env.end() || j->second != outPath) | 487 | if (i.second.path != outPath || j == drv.env.end() || j->second != outPath) |
| 488 | throw Error(format("derivation `%1%' has incorrect output `%2%', should be `%3%'") | 488 | throw Error(format("derivation `%1%' has incorrect output `%2%', should be `%3%'") |
| 489 | % drvPath % i->second.path % outPath); | 489 | % drvPath % i.second.path % outPath); |
| 490 | } | 490 | } |
| 491 | } | 491 | } |
| 492 | } | 492 | } |
| @@ -670,8 +670,8 @@ PathSet LocalStore::queryValidPaths(const PathSet & paths) | |||
| 670 | { | 670 | { |
| 671 | return retrySQLite<PathSet>([&]() { | 671 | return retrySQLite<PathSet>([&]() { |
| 672 | PathSet res; | 672 | PathSet res; |
| 673 | foreach (PathSet::const_iterator, i, paths) | 673 | for (const auto& i : paths) |
| 674 | if (isValidPath_(*i)) res.insert(*i); | 674 | if (isValidPath_(i)) res.insert(i); |
| 675 | return res; | 675 | return res; |
| 676 | }); | 676 | }); |
| 677 | } | 677 | } |
| @@ -854,8 +854,8 @@ PathSet LocalStore::querySubstitutablePaths(const PathSet & paths) | |||
| 854 | Agent & run = *substituter(); | 854 | Agent & run = *substituter(); |
| 855 | 855 | ||
| 856 | string s = "have "; | 856 | string s = "have "; |
| 857 | foreach (PathSet::const_iterator, j, paths) | 857 | for (const auto& j : paths) |
| 858 | if (res.find(*j) == res.end()) { s += *j; s += " "; } | 858 | if (res.find(j) == res.end()) { s += j; s += " "; } |
| 859 | writeLine(run.toAgent.writeSide, s); | 859 | writeLine(run.toAgent.writeSide, s); |
| 860 | while (true) { | 860 | while (true) { |
| 861 | /* FIXME: we only read stderr when an error occurs, so | 861 | /* FIXME: we only read stderr when an error occurs, so |
| @@ -889,8 +889,8 @@ void LocalStore::querySubstitutablePathInfos(PathSet & paths, SubstitutablePathI | |||
| 889 | Agent & run = *substituter(); | 889 | Agent & run = *substituter(); |
| 890 | 890 | ||
| 891 | string s = "info "; | 891 | string s = "info "; |
| 892 | foreach (PathSet::const_iterator, i, paths) | 892 | for (const auto& i : paths) |
| 893 | if (infos.find(*i) == infos.end()) { s += *i; s += " "; } | 893 | if (infos.find(i) == infos.end()) { s += i; s += " "; } |
| 894 | writeLine(run.toAgent.writeSide, s); | 894 | writeLine(run.toAgent.writeSide, s); |
| 895 | 895 | ||
| 896 | while (true) { | 896 | while (true) { |
| @@ -949,13 +949,13 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) | |||
| 949 | SQLiteTxn txn(db); | 949 | SQLiteTxn txn(db); |
| 950 | PathSet paths; | 950 | PathSet paths; |
| 951 | 951 | ||
| 952 | foreach (ValidPathInfos::const_iterator, i, infos) { | 952 | for (const auto& i : infos) { |
| 953 | assert(i->hash.type == htSHA256); | 953 | assert(i.hash.type == htSHA256); |
| 954 | if (isValidPath_(i->path)) | 954 | if (isValidPath_(i.path)) |
| 955 | updatePathInfo(*i); | 955 | updatePathInfo(i); |
| 956 | else | 956 | else |
| 957 | addValidPath(*i, false); | 957 | addValidPath(i, false); |
| 958 | paths.insert(i->path); | 958 | paths.insert(i.path); |
| 959 | } | 959 | } |
| 960 | 960 | ||
| 961 | for (auto & i : infos) { | 961 | for (auto & i : infos) { |
| @@ -967,12 +967,12 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos) | |||
| 967 | /* Check that the derivation outputs are correct. We can't do | 967 | /* Check that the derivation outputs are correct. We can't do |
| 968 | this in addValidPath() above, because the references might | 968 | this in addValidPath() above, because the references might |
| 969 | not be valid yet. */ | 969 | not be valid yet. */ |
| 970 | foreach (ValidPathInfos::const_iterator, i, infos) | 970 | for (const auto& i : infos) |
| 971 | if (isDerivation(i->path)) { | 971 | if (isDerivation(i.path)) { |
| 972 | // FIXME: inefficient; we already loaded the | 972 | // FIXME: inefficient; we already loaded the |
| 973 | // derivation in addValidPath(). | 973 | // derivation in addValidPath(). |
| 974 | Derivation drv = readDerivation(i->path); | 974 | Derivation drv = readDerivation(i.path); |
| 975 | checkDerivationOutputs(i->path, drv); | 975 | checkDerivationOutputs(i.path, drv); |
| 976 | } | 976 | } |
| 977 | 977 | ||
| 978 | /* Do a topological sort of the paths. This will throw an | 978 | /* Do a topological sort of the paths. This will throw an |
| @@ -1465,8 +1465,8 @@ bool LocalStore::verifyStore(bool checkContents, bool repair) | |||
| 1465 | 1465 | ||
| 1466 | PathSet validPaths2 = queryAllValidPaths(), validPaths, done; | 1466 | PathSet validPaths2 = queryAllValidPaths(), validPaths, done; |
| 1467 | 1467 | ||
| 1468 | foreach (PathSet::iterator, i, validPaths2) | 1468 | for (auto& i : validPaths2) |
| 1469 | verifyPath(*i, store, done, validPaths, repair, errors); | 1469 | verifyPath(i, store, done, validPaths, repair, errors); |
| 1470 | 1470 | ||
| 1471 | /* Release the GC lock so that checking content hashes (which can | 1471 | /* Release the GC lock so that checking content hashes (which can |
| 1472 | take ages) doesn't block the GC or builds. */ | 1472 | take ages) doesn't block the GC or builds. */ |
| @@ -1478,33 +1478,33 @@ bool LocalStore::verifyStore(bool checkContents, bool repair) | |||
| 1478 | 1478 | ||
| 1479 | Hash nullHash(htSHA256); | 1479 | Hash nullHash(htSHA256); |
| 1480 | 1480 | ||
| 1481 | foreach (PathSet::iterator, i, validPaths) { | 1481 | for (auto& i : validPaths) { |
| 1482 | try { | 1482 | try { |
| 1483 | ValidPathInfo info = queryPathInfo(*i); | 1483 | ValidPathInfo info = queryPathInfo(i); |
| 1484 | 1484 | ||
| 1485 | /* Check the content hash (optionally - slow). */ | 1485 | /* Check the content hash (optionally - slow). */ |
| 1486 | printMsg(lvlTalkative, format("checking contents of `%1%'") % *i); | 1486 | printMsg(lvlTalkative, format("checking contents of `%1%'") % i); |
| 1487 | HashResult current = hashPath(info.hash.type, *i); | 1487 | HashResult current = hashPath(info.hash.type, i); |
| 1488 | 1488 | ||
| 1489 | if (info.hash != nullHash && info.hash != current.first) { | 1489 | if (info.hash != nullHash && info.hash != current.first) { |
| 1490 | printMsg(lvlError, format("path `%1%' was modified! " | 1490 | printMsg(lvlError, format("path `%1%' was modified! " |
| 1491 | "expected hash `%2%', got `%3%'") | 1491 | "expected hash `%2%', got `%3%'") |
| 1492 | % *i % printHash(info.hash) % printHash(current.first)); | 1492 | % i % printHash(info.hash) % printHash(current.first)); |
| 1493 | if (repair) repairPath(*i); else errors = true; | 1493 | if (repair) repairPath(i); else errors = true; |
| 1494 | } else { | 1494 | } else { |
| 1495 | 1495 | ||
| 1496 | bool update = false; | 1496 | bool update = false; |
| 1497 | 1497 | ||
| 1498 | /* Fill in missing hashes. */ | 1498 | /* Fill in missing hashes. */ |
| 1499 | if (info.hash == nullHash) { | 1499 | if (info.hash == nullHash) { |
| 1500 | printMsg(lvlError, format("fixing missing hash on `%1%'") % *i); | 1500 | printMsg(lvlError, format("fixing missing hash on `%1%'") % i); |
| 1501 | info.hash = current.first; | 1501 | info.hash = current.first; |
| 1502 | update = true; | 1502 | update = true; |
| 1503 | } | 1503 | } |
| 1504 | 1504 | ||
| 1505 | /* Fill in missing narSize fields (from old stores). */ | 1505 | /* Fill in missing narSize fields (from old stores). */ |
| 1506 | if (info.narSize == 0) { | 1506 | if (info.narSize == 0) { |
| 1507 | printMsg(lvlError, format("updating size field on `%1%' to %2%") % *i % current.second); | 1507 | printMsg(lvlError, format("updating size field on `%1%' to %2%") % i % current.second); |
| 1508 | info.narSize = current.second; | 1508 | info.narSize = current.second; |
| 1509 | update = true; | 1509 | update = true; |
| 1510 | } | 1510 | } |
| @@ -1516,7 +1516,7 @@ bool LocalStore::verifyStore(bool checkContents, bool repair) | |||
| 1516 | } catch (Error & e) { | 1516 | } catch (Error & e) { |
| 1517 | /* It's possible that the path got GC'ed, so ignore | 1517 | /* It's possible that the path got GC'ed, so ignore |
| 1518 | errors on invalid paths. */ | 1518 | errors on invalid paths. */ |
| 1519 | if (isValidPath(*i)) | 1519 | if (isValidPath(i)) |
| 1520 | printMsg(lvlError, format("error: %1%") % e.msg()); | 1520 | printMsg(lvlError, format("error: %1%") % e.msg()); |
| 1521 | else | 1521 | else |
| 1522 | printMsg(lvlError, format("warning: %1%") % e.msg()); | 1522 | printMsg(lvlError, format("warning: %1%") % e.msg()); |
| @@ -1548,10 +1548,10 @@ void LocalStore::verifyPath(const Path & path, const PathSet & store, | |||
| 1548 | first, then we can invalidate this path as well. */ | 1548 | first, then we can invalidate this path as well. */ |
| 1549 | bool canInvalidate = true; | 1549 | bool canInvalidate = true; |
| 1550 | PathSet referrers; queryReferrers(path, referrers); | 1550 | PathSet referrers; queryReferrers(path, referrers); |
| 1551 | foreach (PathSet::iterator, i, referrers) | 1551 | for (auto& i : referrers) |
| 1552 | if (*i != path) { | 1552 | if (i != path) { |
| 1553 | verifyPath(*i, store, done, validPaths, repair, errors); | 1553 | verifyPath(i, store, done, validPaths, repair, errors); |
| 1554 | if (validPaths.find(*i) != validPaths.end()) | 1554 | if (validPaths.find(i) != validPaths.end()) |
| 1555 | canInvalidate = false; | 1555 | canInvalidate = false; |
| 1556 | } | 1556 | } |
| 1557 | 1557 | ||
diff --git a/nix/libstore/misc.cc b/nix/libstore/misc.cc index d4e6d1b4afc..bc5dec88bf2 100644 --- a/nix/libstore/misc.cc +++ b/nix/libstore/misc.cc | |||
| @@ -28,15 +28,15 @@ void computeFSClosure(StoreAPI & store, const Path & path, | |||
| 28 | 28 | ||
| 29 | if (includeOutputs) { | 29 | if (includeOutputs) { |
| 30 | PathSet derivers = store.queryValidDerivers(path); | 30 | PathSet derivers = store.queryValidDerivers(path); |
| 31 | foreach (PathSet::iterator, i, derivers) | 31 | for (auto& i : derivers) |
| 32 | edges.insert(*i); | 32 | edges.insert(i); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | if (includeDerivers && isDerivation(path)) { | 35 | if (includeDerivers && isDerivation(path)) { |
| 36 | PathSet outputs = store.queryDerivationOutputs(path); | 36 | PathSet outputs = store.queryDerivationOutputs(path); |
| 37 | foreach (PathSet::iterator, i, outputs) | 37 | for (auto& i : outputs) |
| 38 | if (store.isValidPath(*i) && store.queryDeriver(*i) == path) | 38 | if (store.isValidPath(i) && store.queryDeriver(i) == path) |
| 39 | edges.insert(*i); | 39 | edges.insert(i); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | } else { | 42 | } else { |
| @@ -44,8 +44,8 @@ void computeFSClosure(StoreAPI & store, const Path & path, | |||
| 44 | 44 | ||
| 45 | if (includeOutputs && isDerivation(path)) { | 45 | if (includeOutputs && isDerivation(path)) { |
| 46 | PathSet outputs = store.queryDerivationOutputs(path); | 46 | PathSet outputs = store.queryDerivationOutputs(path); |
| 47 | foreach (PathSet::iterator, i, outputs) | 47 | for (auto& i : outputs) |
| 48 | if (store.isValidPath(*i)) edges.insert(*i); | 48 | if (store.isValidPath(i)) edges.insert(i); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | if (includeDerivers) { | 51 | if (includeDerivers) { |
| @@ -54,8 +54,8 @@ void computeFSClosure(StoreAPI & store, const Path & path, | |||
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | foreach (PathSet::iterator, i, edges) | 57 | for (auto& i : edges) |
| 58 | computeFSClosure(store, *i, paths, flipDirection, includeOutputs, includeDerivers); | 58 | computeFSClosure(store, i, paths, flipDirection, includeOutputs, includeDerivers); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | 61 | ||
| @@ -74,11 +74,11 @@ static void dfsVisit(StoreAPI & store, const PathSet & paths, | |||
| 74 | if (store.isValidPath(path)) | 74 | if (store.isValidPath(path)) |
| 75 | store.queryReferences(path, references); | 75 | store.queryReferences(path, references); |
| 76 | 76 | ||
| 77 | foreach (PathSet::iterator, i, references) | 77 | for (auto& i : references) |
| 78 | /* Don't traverse into paths that don't exist. That can | 78 | /* Don't traverse into paths that don't exist. That can |
| 79 | happen due to substitutes for non-existent paths. */ | 79 | happen due to substitutes for non-existent paths. */ |
| 80 | if (*i != path && paths.find(*i) != paths.end()) | 80 | if (i != path && paths.find(i) != paths.end()) |
| 81 | dfsVisit(store, paths, *i, visited, sorted, parents); | 81 | dfsVisit(store, paths, i, visited, sorted, parents); |
| 82 | 82 | ||
| 83 | sorted.push_front(path); | 83 | sorted.push_front(path); |
| 84 | parents.erase(path); | 84 | parents.erase(path); |
| @@ -89,8 +89,8 @@ Paths topoSortPaths(StoreAPI & store, const PathSet & paths) | |||
| 89 | { | 89 | { |
| 90 | Paths sorted; | 90 | Paths sorted; |
| 91 | PathSet visited, parents; | 91 | PathSet visited, parents; |
| 92 | foreach (PathSet::const_iterator, i, paths) | 92 | for (const auto& i : paths) |
| 93 | dfsVisit(store, paths, *i, visited, sorted, parents); | 93 | dfsVisit(store, paths, i, visited, sorted, parents); |
| 94 | return sorted; | 94 | return sorted; |
| 95 | } | 95 | } |
| 96 | 96 | ||
diff --git a/nix/libstore/optimise-store.cc b/nix/libstore/optimise-store.cc index 9fd6f3cb356..8d5bf28da9d 100644 --- a/nix/libstore/optimise-store.cc +++ b/nix/libstore/optimise-store.cc | |||
| @@ -103,8 +103,8 @@ void LocalStore::optimisePath_(OptimiseStats & stats, const Path & path, InodeHa | |||
| 103 | 103 | ||
| 104 | if (S_ISDIR(st.st_mode)) { | 104 | if (S_ISDIR(st.st_mode)) { |
| 105 | Strings names = readDirectoryIgnoringInodes(path, inodeHash); | 105 | Strings names = readDirectoryIgnoringInodes(path, inodeHash); |
| 106 | foreach (Strings::iterator, i, names) | 106 | for (auto& i : names) |
| 107 | optimisePath_(stats, path + "/" + *i, inodeHash); | 107 | optimisePath_(stats, path + "/" + i, inodeHash); |
| 108 | return; | 108 | return; |
| 109 | } | 109 | } |
| 110 | 110 | ||
| @@ -244,11 +244,11 @@ void LocalStore::optimiseStore(OptimiseStats & stats) | |||
| 244 | PathSet paths = queryAllValidPaths(); | 244 | PathSet paths = queryAllValidPaths(); |
| 245 | InodeHash inodeHash = loadInodeHash(); | 245 | InodeHash inodeHash = loadInodeHash(); |
| 246 | 246 | ||
| 247 | foreach (PathSet::iterator, i, paths) { | 247 | for (auto& i : paths) { |
| 248 | addTempRoot(*i); | 248 | addTempRoot(i); |
| 249 | if (!isValidPath(*i)) continue; /* path was GC'ed, probably */ | 249 | if (!isValidPath(i)) continue; /* path was GC'ed, probably */ |
| 250 | startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i); | 250 | startNest(nest, lvlChatty, format("hashing files in `%1%'") % i); |
| 251 | optimisePath_(stats, *i, inodeHash); | 251 | optimisePath_(stats, i, inodeHash); |
| 252 | } | 252 | } |
| 253 | } | 253 | } |
| 254 | 254 | ||
diff --git a/nix/libstore/pathlocks.cc b/nix/libstore/pathlocks.cc index 9797ddd7abf..c07f047192c 100644 --- a/nix/libstore/pathlocks.cc +++ b/nix/libstore/pathlocks.cc | |||
| @@ -60,7 +60,7 @@ bool lockFile(int fd, LockType lockType, bool wait) | |||
| 60 | while (fcntl(fd, F_SETLK, &lock) != 0) { | 60 | while (fcntl(fd, F_SETLK, &lock) != 0) { |
| 61 | checkInterrupt(); | 61 | checkInterrupt(); |
| 62 | if (errno == EACCES || errno == EAGAIN) return false; | 62 | if (errno == EACCES || errno == EAGAIN) return false; |
| 63 | if (errno != EINTR) | 63 | if (errno != EINTR) |
| 64 | throw SysError(format("acquiring/releasing lock")); | 64 | throw SysError(format("acquiring/releasing lock")); |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| @@ -94,7 +94,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, | |||
| 94 | const string & waitMsg, bool wait) | 94 | const string & waitMsg, bool wait) |
| 95 | { | 95 | { |
| 96 | assert(fds.empty()); | 96 | assert(fds.empty()); |
| 97 | 97 | ||
| 98 | /* Note that `fds' is built incrementally so that the destructor | 98 | /* Note that `fds' is built incrementally so that the destructor |
| 99 | will only release those locks that we have already acquired. */ | 99 | will only release those locks that we have already acquired. */ |
| 100 | 100 | ||
| @@ -102,11 +102,11 @@ bool PathLocks::lockPaths(const PathSet & _paths, | |||
| 102 | the same order, thus preventing deadlocks. */ | 102 | the same order, thus preventing deadlocks. */ |
| 103 | Paths paths(_paths.begin(), _paths.end()); | 103 | Paths paths(_paths.begin(), _paths.end()); |
| 104 | paths.sort(); | 104 | paths.sort(); |
| 105 | 105 | ||
| 106 | /* Acquire the lock for each path. */ | 106 | /* Acquire the lock for each path. */ |
| 107 | foreach (Paths::iterator, i, paths) { | 107 | for (auto& i : paths) { |
| 108 | checkInterrupt(); | 108 | checkInterrupt(); |
| 109 | Path path = *i; | 109 | Path path = i; |
| 110 | Path lockPath = path + ".lock"; | 110 | Path lockPath = path + ".lock"; |
| 111 | 111 | ||
| 112 | debug(format("locking path `%1%'") % path); | 112 | debug(format("locking path `%1%'") % path); |
| @@ -115,7 +115,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, | |||
| 115 | throw Error("deadlock: trying to re-acquire self-held lock"); | 115 | throw Error("deadlock: trying to re-acquire self-held lock"); |
| 116 | 116 | ||
| 117 | AutoCloseFD fd; | 117 | AutoCloseFD fd; |
| 118 | 118 | ||
| 119 | while (1) { | 119 | while (1) { |
| 120 | 120 | ||
| 121 | /* Open/create the lock file. */ | 121 | /* Open/create the lock file. */ |
| @@ -172,15 +172,15 @@ PathLocks::~PathLocks() | |||
| 172 | 172 | ||
| 173 | void PathLocks::unlock() | 173 | void PathLocks::unlock() |
| 174 | { | 174 | { |
| 175 | foreach (list<FDPair>::iterator, i, fds) { | 175 | for (auto& i : fds) { |
| 176 | if (deletePaths) deleteLockFile(i->second, i->first); | 176 | if (deletePaths) deleteLockFile(i.second, i.first); |
| 177 | 177 | ||
| 178 | lockedPaths.erase(i->second); | 178 | lockedPaths.erase(i.second); |
| 179 | if (close(i->first) == -1) | 179 | if (close(i.first) == -1) |
| 180 | printMsg(lvlError, | 180 | printMsg(lvlError, |
| 181 | format("error (ignored): cannot close lock file on `%1%'") % i->second); | 181 | format("error (ignored): cannot close lock file on `%1%'") % i.second); |
| 182 | 182 | ||
| 183 | debug(format("lock released on `%1%'") % i->second); | 183 | debug(format("lock released on `%1%'") % i.second); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | fds.clear(); | 186 | fds.clear(); |
| @@ -199,5 +199,5 @@ bool pathIsLockedByMe(const Path & path) | |||
| 199 | return lockedPaths.find(lockPath) != lockedPaths.end(); | 199 | return lockedPaths.find(lockPath) != lockedPaths.end(); |
| 200 | } | 200 | } |
| 201 | 201 | ||
| 202 | 202 | ||
| 203 | } | 203 | } |
diff --git a/nix/libstore/references.cc b/nix/libstore/references.cc index 282b848938b..d9c8a9fbe38 100644 --- a/nix/libstore/references.cc +++ b/nix/libstore/references.cc | |||
| @@ -13,7 +13,7 @@ namespace nix { | |||
| 13 | static unsigned int refLength = 32; /* characters */ | 13 | static unsigned int refLength = 32; /* characters */ |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | static void search(const unsigned char * s, unsigned int len, | 16 | static void search(const unsigned char * s, unsigned int len, |
| 17 | StringSet & hashes, StringSet & seen) | 17 | StringSet & hashes, StringSet & seen) |
| 18 | { | 18 | { |
| 19 | static bool initialised = false; | 19 | static bool initialised = false; |
| @@ -24,7 +24,7 @@ static void search(const unsigned char * s, unsigned int len, | |||
| 24 | isBase32[(unsigned char) base32Chars[i]] = true; | 24 | isBase32[(unsigned char) base32Chars[i]] = true; |
| 25 | initialised = true; | 25 | initialised = true; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | for (unsigned int i = 0; i + refLength <= len; ) { | 28 | for (unsigned int i = 0; i + refLength <= len; ) { |
| 29 | int j; | 29 | int j; |
| 30 | bool match = true; | 30 | bool match = true; |
| @@ -56,7 +56,7 @@ struct RefScanSink : Sink | |||
| 56 | string tail; | 56 | string tail; |
| 57 | 57 | ||
| 58 | RefScanSink() : hashSink(htSHA256) { } | 58 | RefScanSink() : hashSink(htSHA256) { } |
| 59 | 59 | ||
| 60 | void operator () (const unsigned char * data, size_t len); | 60 | void operator () (const unsigned char * data, size_t len); |
| 61 | }; | 61 | }; |
| 62 | 62 | ||
| @@ -89,17 +89,17 @@ PathSet scanForReferences(const string & path, | |||
| 89 | /* For efficiency (and a higher hit rate), just search for the | 89 | /* For efficiency (and a higher hit rate), just search for the |
| 90 | hash part of the file name. (This assumes that all references | 90 | hash part of the file name. (This assumes that all references |
| 91 | have the form `HASH-bla'). */ | 91 | have the form `HASH-bla'). */ |
| 92 | foreach (PathSet::const_iterator, i, refs) { | 92 | for (const auto& i : refs) { |
| 93 | string baseName = baseNameOf(*i); | 93 | string baseName = baseNameOf(i); |
| 94 | string::size_type pos = baseName.find('-'); | 94 | string::size_type pos = baseName.find('-'); |
| 95 | if (pos == string::npos) | 95 | if (pos == string::npos) |
| 96 | throw Error(format("bad reference `%1%'") % *i); | 96 | throw Error(format("bad reference `%1%'") % i); |
| 97 | string s = string(baseName, 0, pos); | 97 | string s = string(baseName, 0, pos); |
| 98 | assert(s.size() == refLength); | 98 | assert(s.size() == refLength); |
| 99 | assert(backMap.find(s) == backMap.end()); | 99 | assert(backMap.find(s) == backMap.end()); |
| 100 | // parseHash(htSHA256, s); | 100 | // parseHash(htSHA256, s); |
| 101 | sink.hashes.insert(s); | 101 | sink.hashes.insert(s); |
| 102 | backMap[s] = *i; | 102 | backMap[s] = i; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | /* Look for the hashes in the NAR dump of the path. */ | 105 | /* Look for the hashes in the NAR dump of the path. */ |
| @@ -107,14 +107,14 @@ PathSet scanForReferences(const string & path, | |||
| 107 | 107 | ||
| 108 | /* Map the hashes found back to their store paths. */ | 108 | /* Map the hashes found back to their store paths. */ |
| 109 | PathSet found; | 109 | PathSet found; |
| 110 | foreach (StringSet::iterator, i, sink.seen) { | 110 | for (auto& i : sink.seen) { |
| 111 | std::map<string, Path>::iterator j; | 111 | std::map<string, Path>::iterator j; |
| 112 | if ((j = backMap.find(*i)) == backMap.end()) abort(); | 112 | if ((j = backMap.find(i)) == backMap.end()) abort(); |
| 113 | found.insert(j->second); | 113 | found.insert(j->second); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | hash = sink.hashSink.finish(); | 116 | hash = sink.hashSink.finish(); |
| 117 | 117 | ||
| 118 | return found; | 118 | return found; |
| 119 | } | 119 | } |
| 120 | 120 | ||
diff --git a/nix/libstore/store-api.cc b/nix/libstore/store-api.cc index 38a1403a712..7282188fb37 100644 --- a/nix/libstore/store-api.cc +++ b/nix/libstore/store-api.cc | |||
| @@ -62,14 +62,14 @@ void checkStoreName(const string & name) | |||
| 62 | reasons (e.g., "." and ".."). */ | 62 | reasons (e.g., "." and ".."). */ |
| 63 | if (string(name, 0, 1) == ".") | 63 | if (string(name, 0, 1) == ".") |
| 64 | throw Error(format("invalid name: `%1%' (can't begin with dot)") % name); | 64 | throw Error(format("invalid name: `%1%' (can't begin with dot)") % name); |
| 65 | foreach (string::const_iterator, i, name) | 65 | for (const auto& i : name) |
| 66 | if (!((*i >= 'A' && *i <= 'Z') || | 66 | if (!((i >= 'A' && i <= 'Z') || |
| 67 | (*i >= 'a' && *i <= 'z') || | 67 | (i >= 'a' && i <= 'z') || |
| 68 | (*i >= '0' && *i <= '9') || | 68 | (i >= '0' && i <= '9') || |
| 69 | validChars.find(*i) != string::npos)) | 69 | validChars.find(i) != string::npos)) |
| 70 | { | 70 | { |
| 71 | throw Error(format("invalid character `%1%' in name `%2%'") | 71 | throw Error(format("invalid character `%1%' in name `%2%'") |
| 72 | % *i % name); | 72 | % i % name); |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| 75 | 75 | ||
| @@ -81,22 +81,22 @@ void checkStoreName(const string & name) | |||
| 81 | where | 81 | where |
| 82 | 82 | ||
| 83 | <store> = the location of the store, usually /gnu/store | 83 | <store> = the location of the store, usually /gnu/store |
| 84 | 84 | ||
| 85 | <name> = a human readable name for the path, typically obtained | 85 | <name> = a human readable name for the path, typically obtained |
| 86 | from the name attribute of the derivation, or the name of the | 86 | from the name attribute of the derivation, or the name of the |
| 87 | source file from which the store path is created. For derivation | 87 | source file from which the store path is created. For derivation |
| 88 | outputs other than the default "out" output, the string "-<id>" | 88 | outputs other than the default "out" output, the string "-<id>" |
| 89 | is suffixed to <name>. | 89 | is suffixed to <name>. |
| 90 | 90 | ||
| 91 | <h> = base-32 representation of the first 160 bits of a SHA-256 | 91 | <h> = base-32 representation of the first 160 bits of a SHA-256 |
| 92 | hash of <s>; the hash part of the store name | 92 | hash of <s>; the hash part of the store name |
| 93 | 93 | ||
| 94 | <s> = the string "<type>:sha256:<h2>:<store>:<name>"; | 94 | <s> = the string "<type>:sha256:<h2>:<store>:<name>"; |
| 95 | note that it includes the location of the store as well as the | 95 | note that it includes the location of the store as well as the |
| 96 | name to make sure that changes to either of those are reflected | 96 | name to make sure that changes to either of those are reflected |
| 97 | in the hash (e.g. you won't get /nix/store/<h>-name1 and | 97 | in the hash (e.g. you won't get /nix/store/<h>-name1 and |
| 98 | /nix/store/<h>-name2 with equal hash parts). | 98 | /nix/store/<h>-name2 with equal hash parts). |
| 99 | 99 | ||
| 100 | <type> = one of: | 100 | <type> = one of: |
| 101 | "text:<r1>:<r2>:...<rN>" | 101 | "text:<r1>:<r2>:...<rN>" |
| 102 | for plain text files written to the store using | 102 | for plain text files written to the store using |
| @@ -188,9 +188,9 @@ Path computeStorePathForText(const string & name, const string & s, | |||
| 188 | hacky, but we can't put them in `s' since that would be | 188 | hacky, but we can't put them in `s' since that would be |
| 189 | ambiguous. */ | 189 | ambiguous. */ |
| 190 | string type = "text"; | 190 | string type = "text"; |
| 191 | foreach (PathSet::const_iterator, i, references) { | 191 | for (const auto& i : references) { |
| 192 | type += ":"; | 192 | type += ":"; |
| 193 | type += *i; | 193 | type += i; |
| 194 | } | 194 | } |
| 195 | return makeStorePath(type, hash, name); | 195 | return makeStorePath(type, hash, name); |
| 196 | } | 196 | } |
| @@ -203,11 +203,11 @@ string StoreAPI::makeValidityRegistration(const PathSet & paths, | |||
| 203 | bool showDerivers, bool showHash) | 203 | bool showDerivers, bool showHash) |
| 204 | { | 204 | { |
| 205 | string s = ""; | 205 | string s = ""; |
| 206 | |||
| 207 | foreach (PathSet::iterator, i, paths) { | ||
| 208 | s += *i + "\n"; | ||
| 209 | 206 | ||
| 210 | ValidPathInfo info = queryPathInfo(*i); | 207 | for (auto& i : paths) { |
| 208 | s += i + "\n"; | ||
| 209 | |||
| 210 | ValidPathInfo info = queryPathInfo(i); | ||
| 211 | 211 | ||
| 212 | if (showHash) { | 212 | if (showHash) { |
| 213 | s += printHash(info.hash) + "\n"; | 213 | s += printHash(info.hash) + "\n"; |
| @@ -219,8 +219,8 @@ string StoreAPI::makeValidityRegistration(const PathSet & paths, | |||
| 219 | 219 | ||
| 220 | s += (format("%1%\n") % info.references.size()).str(); | 220 | s += (format("%1%\n") % info.references.size()).str(); |
| 221 | 221 | ||
| 222 | foreach (PathSet::iterator, j, info.references) | 222 | for (auto& j : info.references) |
| 223 | s += *j + "\n"; | 223 | s += j + "\n"; |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | return s; | 226 | return s; |
| @@ -229,9 +229,9 @@ string StoreAPI::makeValidityRegistration(const PathSet & paths, | |||
| 229 | string showPaths(const PathSet & paths) | 229 | string showPaths(const PathSet & paths) |
| 230 | { | 230 | { |
| 231 | string s; | 231 | string s; |
| 232 | foreach (PathSet::const_iterator, i, paths) { | 232 | for (const auto& i : paths) { |
| 233 | if (s.size() != 0) s += ", "; | 233 | if (s.size() != 0) s += ", "; |
| 234 | s += "`" + *i + "'"; | 234 | s += "`" + i + "'"; |
| 235 | } | 235 | } |
| 236 | return s; | 236 | return s; |
| 237 | } | 237 | } |
| @@ -247,7 +247,7 @@ Path readStorePath(Source & from) | |||
| 247 | template<class T> T readStorePaths(Source & from) | 247 | template<class T> T readStorePaths(Source & from) |
| 248 | { | 248 | { |
| 249 | T paths = readStrings<T>(from); | 249 | T paths = readStrings<T>(from); |
| 250 | foreach (typename T::iterator, i, paths) assertStorePath(*i); | 250 | for (auto& i : paths) assertStorePath(i); |
| 251 | return paths; | 251 | return paths; |
| 252 | } | 252 | } |
| 253 | 253 | ||
diff --git a/nix/libutil/serialise.cc b/nix/libutil/serialise.cc index 6f04ab15918..01aeea25c0c 100644 --- a/nix/libutil/serialise.cc +++ b/nix/libutil/serialise.cc | |||
| @@ -188,8 +188,8 @@ void writeString(const string & s, Sink & sink) | |||
| 188 | template<class T> void writeStrings(const T & ss, Sink & sink) | 188 | template<class T> void writeStrings(const T & ss, Sink & sink) |
| 189 | { | 189 | { |
| 190 | writeInt(ss.size(), sink); | 190 | writeInt(ss.size(), sink); |
| 191 | foreach (typename T::const_iterator, i, ss) | 191 | for (auto& i : ss) |
| 192 | writeString(*i, sink); | 192 | writeString(i, sink); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | template void writeStrings(const Paths & ss, Sink & sink); | 195 | template void writeStrings(const Paths & ss, Sink & sink); |
diff --git a/nix/libutil/util.cc b/nix/libutil/util.cc index 398f61841f1..74f7a97cc4f 100644 --- a/nix/libutil/util.cc +++ b/nix/libutil/util.cc | |||
| @@ -1158,9 +1158,9 @@ template vector<string> tokenizeString(const string & s, const string & separato | |||
| 1158 | string concatStringsSep(const string & sep, const Strings & ss) | 1158 | string concatStringsSep(const string & sep, const Strings & ss) |
| 1159 | { | 1159 | { |
| 1160 | string s; | 1160 | string s; |
| 1161 | foreach (Strings::const_iterator, i, ss) { | 1161 | for (const auto& i : ss) { |
| 1162 | if (s.size() != 0) s += sep; | 1162 | if (s.size() != 0) s += sep; |
| 1163 | s += *i; | 1163 | s += i; |
| 1164 | } | 1164 | } |
| 1165 | return s; | 1165 | return s; |
| 1166 | } | 1166 | } |
| @@ -1169,9 +1169,9 @@ string concatStringsSep(const string & sep, const Strings & ss) | |||
| 1169 | string concatStringsSep(const string & sep, const StringSet & ss) | 1169 | string concatStringsSep(const string & sep, const StringSet & ss) |
| 1170 | { | 1170 | { |
| 1171 | string s; | 1171 | string s; |
| 1172 | foreach (StringSet::const_iterator, i, ss) { | 1172 | for (const auto& i : ss) { |
| 1173 | if (s.size() != 0) s += sep; | 1173 | if (s.size() != 0) s += sep; |
| 1174 | s += *i; | 1174 | s += i; |
| 1175 | } | 1175 | } |
| 1176 | return s; | 1176 | return s; |
| 1177 | } | 1177 | } |
diff --git a/nix/libutil/util.hh b/nix/libutil/util.hh index 176247e699d..a07c3be6eb6 100644 --- a/nix/libutil/util.hh +++ b/nix/libutil/util.hh | |||
| @@ -16,13 +16,6 @@ | |||
| 16 | namespace nix { | 16 | namespace nix { |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | #define foreach(it_type, it, collection) \ | ||
| 20 | for (it_type it = (collection).begin(); it != (collection).end(); ++it) | ||
| 21 | |||
| 22 | #define foreach_reverse(it_type, it, collection) \ | ||
| 23 | for (it_type it = (collection).rbegin(); it != (collection).rend(); ++it) | ||
| 24 | |||
| 25 | |||
| 26 | /* Return an environment variable. */ | 19 | /* Return an environment variable. */ |
| 27 | string getEnv(const string & key, const string & def = ""); | 20 | string getEnv(const string & key, const string & def = ""); |
| 28 | 21 | ||
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc index b43bcf7fc6e..9fff31a587c 100644 --- a/nix/nix-daemon/nix-daemon.cc +++ b/nix/nix-daemon/nix-daemon.cc | |||
| @@ -679,12 +679,12 @@ static void performOp(bool trusted, unsigned int clientVersion, | |||
| 679 | store->querySubstitutablePathInfos(paths, infos); | 679 | store->querySubstitutablePathInfos(paths, infos); |
| 680 | stopWork(); | 680 | stopWork(); |
| 681 | writeInt(infos.size(), to); | 681 | writeInt(infos.size(), to); |
| 682 | foreach (SubstitutablePathInfos::iterator, i, infos) { | 682 | for (auto& i : infos) { |
| 683 | writeString(i->first, to); | 683 | writeString(i.first, to); |
| 684 | writeString(i->second.deriver, to); | 684 | writeString(i.second.deriver, to); |
| 685 | writeStrings(i->second.references, to); | 685 | writeStrings(i.second.references, to); |
| 686 | writeLongLong(i->second.downloadSize, to); | 686 | writeLongLong(i.second.downloadSize, to); |
| 687 | writeLongLong(i->second.narSize, to); | 687 | writeLongLong(i.second.narSize, to); |
| 688 | } | 688 | } |
| 689 | break; | 689 | break; |
| 690 | } | 690 | } |
