* Use foreach in a lot of places.
This commit is contained in:
parent
8f1bf28505
commit
d5eab2fc82
|
@ -290,13 +290,11 @@ void Goal::waiteeDone(GoalPtr waitee, ExitCode result)
|
||||||
|
|
||||||
/* If we failed and keepGoing is not set, we remove all
|
/* If we failed and keepGoing is not set, we remove all
|
||||||
remaining waitees. */
|
remaining waitees. */
|
||||||
for (Goals::iterator i = waitees.begin(); i != waitees.end(); ++i) {
|
foreach (Goals::iterator, i, waitees) {
|
||||||
GoalPtr goal = *i;
|
GoalPtr goal = *i;
|
||||||
WeakGoals waiters2;
|
WeakGoals waiters2;
|
||||||
for (WeakGoals::iterator j = goal->waiters.begin();
|
foreach (WeakGoals::iterator, j, goal->waiters)
|
||||||
j != goal->waiters.end(); ++j)
|
if (j->lock() != shared_from_this()) waiters2.insert(*j);
|
||||||
if (j->lock() != shared_from_this())
|
|
||||||
waiters2.insert(*j);
|
|
||||||
goal->waiters = waiters2;
|
goal->waiters = waiters2;
|
||||||
}
|
}
|
||||||
waitees.clear();
|
waitees.clear();
|
||||||
|
@ -312,7 +310,7 @@ void Goal::amDone(ExitCode result)
|
||||||
assert(exitCode == ecBusy);
|
assert(exitCode == ecBusy);
|
||||||
assert(result == ecSuccess || result == ecFailed);
|
assert(result == ecSuccess || result == ecFailed);
|
||||||
exitCode = result;
|
exitCode = result;
|
||||||
for (WeakGoals::iterator i = waiters.begin(); i != waiters.end(); ++i) {
|
foreach (WeakGoals::iterator, i, waiters) {
|
||||||
GoalPtr goal = i->lock();
|
GoalPtr goal = i->lock();
|
||||||
if (goal) goal->waiteeDone(shared_from_this(), result);
|
if (goal) goal->waiteeDone(shared_from_this(), result);
|
||||||
}
|
}
|
||||||
|
@ -365,8 +363,7 @@ const char * * strings2CharPtrs(const Strings & ss)
|
||||||
{
|
{
|
||||||
const char * * arr = new const char * [ss.size() + 1];
|
const char * * arr = new const char * [ss.size() + 1];
|
||||||
const char * * p = arr;
|
const char * * p = arr;
|
||||||
for (Strings::const_iterator i = ss.begin(); i != ss.end(); ++i)
|
foreach (Strings::const_iterator, i, ss) *p++ = i->c_str();
|
||||||
*p++ = i->c_str();
|
|
||||||
*p = 0;
|
*p = 0;
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
@ -462,7 +459,7 @@ void UserLock::acquire()
|
||||||
|
|
||||||
/* Find a user account that isn't currently in use for another
|
/* Find a user account that isn't currently in use for another
|
||||||
build. */
|
build. */
|
||||||
for (Strings::iterator i = users.begin(); i != users.end(); ++i) {
|
foreach (Strings::iterator, i, users) {
|
||||||
debug(format("trying user `%1%'") % *i);
|
debug(format("trying user `%1%'") % *i);
|
||||||
|
|
||||||
struct passwd * pw = getpwnam(i->c_str());
|
struct passwd * pw = getpwnam(i->c_str());
|
||||||
|
@ -877,8 +874,7 @@ void DerivationGoal::outputsSubstituted()
|
||||||
foreach (DerivationInputs::iterator, i, drv.inputDrvs)
|
foreach (DerivationInputs::iterator, i, drv.inputDrvs)
|
||||||
addWaitee(worker.makeDerivationGoal(i->first));
|
addWaitee(worker.makeDerivationGoal(i->first));
|
||||||
|
|
||||||
for (PathSet::iterator i = drv.inputSrcs.begin();
|
foreach (PathSet::iterator, i, drv.inputSrcs)
|
||||||
i != drv.inputSrcs.end(); ++i)
|
|
||||||
addWaitee(worker.makeSubstitutionGoal(*i));
|
addWaitee(worker.makeSubstitutionGoal(*i));
|
||||||
|
|
||||||
state = &DerivationGoal::inputsRealised;
|
state = &DerivationGoal::inputsRealised;
|
||||||
|
@ -949,8 +945,7 @@ void DerivationGoal::inputsRealised()
|
||||||
PathSet outputPaths(const DerivationOutputs & outputs)
|
PathSet outputPaths(const DerivationOutputs & outputs)
|
||||||
{
|
{
|
||||||
PathSet paths;
|
PathSet paths;
|
||||||
for (DerivationOutputs::const_iterator i = outputs.begin();
|
foreach (DerivationOutputs::const_iterator, i, outputs)
|
||||||
i != outputs.end(); ++i)
|
|
||||||
paths.insert(i->second.path);
|
paths.insert(i->second.path);
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
@ -1313,17 +1308,14 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
|
||||||
computeFSClosure(drvPath, allInputs);
|
computeFSClosure(drvPath, allInputs);
|
||||||
|
|
||||||
string s;
|
string s;
|
||||||
for (PathSet::iterator i = allInputs.begin();
|
foreach (PathSet::iterator, i, allInputs) s += *i + "\n";
|
||||||
i != allInputs.end(); ++i)
|
|
||||||
s += *i + "\n";
|
|
||||||
|
|
||||||
writeStringToFile(inputListFN, s);
|
writeStringToFile(inputListFN, s);
|
||||||
|
|
||||||
/* The `outputs' file lists all outputs that have to be copied
|
/* The `outputs' file lists all outputs that have to be copied
|
||||||
from the remote system. */
|
from the remote system. */
|
||||||
s = "";
|
s = "";
|
||||||
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
i != drv.outputs.end(); ++i)
|
|
||||||
s += i->second.path + "\n";
|
s += i->second.path + "\n";
|
||||||
writeStringToFile(outputListFN, s);
|
writeStringToFile(outputListFN, s);
|
||||||
|
|
||||||
|
@ -1411,8 +1403,7 @@ void DerivationGoal::startBuilder()
|
||||||
env["NIX_STORE"] = nixStore;
|
env["NIX_STORE"] = nixStore;
|
||||||
|
|
||||||
/* Add all bindings specified in the derivation. */
|
/* Add all bindings specified in the derivation. */
|
||||||
for (StringPairs::iterator i = drv.env.begin();
|
foreach (StringPairs::iterator, i, drv.env)
|
||||||
i != drv.env.end(); ++i)
|
|
||||||
env[i->first] = i->second;
|
env[i->first] = i->second;
|
||||||
|
|
||||||
/* Create a temporary directory where the build will take
|
/* Create a temporary directory where the build will take
|
||||||
|
@ -1449,8 +1440,7 @@ void DerivationGoal::startBuilder()
|
||||||
already know the cryptographic hash of the output). */
|
already know the cryptographic hash of the output). */
|
||||||
if (fixedOutput) {
|
if (fixedOutput) {
|
||||||
Strings varNames = tokenizeString(drv.env["impureEnvVars"]);
|
Strings varNames = tokenizeString(drv.env["impureEnvVars"]);
|
||||||
for (Strings::iterator i = varNames.begin(); i != varNames.end(); ++i)
|
foreach (Strings::iterator, i, varNames) env[*i] = getEnv(*i);
|
||||||
env[*i] = getEnv(*i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The `exportReferencesGraph' feature allows the references graph
|
/* The `exportReferencesGraph' feature allows the references graph
|
||||||
|
@ -1690,8 +1680,7 @@ void DerivationGoal::startBuilder()
|
||||||
|
|
||||||
/* Fill in the environment. */
|
/* Fill in the environment. */
|
||||||
Strings envStrs;
|
Strings envStrs;
|
||||||
for (Environment::const_iterator i = env.begin();
|
foreach (Environment::const_iterator, i, env)
|
||||||
i != env.end(); ++i)
|
|
||||||
envStrs.push_back(i->first + "=" + i->second);
|
envStrs.push_back(i->first + "=" + i->second);
|
||||||
const char * * envArr = strings2CharPtrs(envStrs);
|
const char * * envArr = strings2CharPtrs(envStrs);
|
||||||
|
|
||||||
|
@ -1737,8 +1726,7 @@ void DerivationGoal::startBuilder()
|
||||||
/* Fill in the arguments. */
|
/* Fill in the arguments. */
|
||||||
string builderBasename = baseNameOf(drv.builder);
|
string builderBasename = baseNameOf(drv.builder);
|
||||||
args.push_back(builderBasename.c_str());
|
args.push_back(builderBasename.c_str());
|
||||||
for (Strings::iterator i = drv.args.begin();
|
foreach (Strings::iterator, i, drv.args)
|
||||||
i != drv.args.end(); ++i)
|
|
||||||
args.push_back(i->c_str());
|
args.push_back(i->c_str());
|
||||||
args.push_back(0);
|
args.push_back(0);
|
||||||
|
|
||||||
|
@ -1777,7 +1765,7 @@ PathSet parseReferenceSpecifiers(const Derivation & drv, string attr)
|
||||||
{
|
{
|
||||||
PathSet result;
|
PathSet result;
|
||||||
Paths paths = tokenizeString(attr);
|
Paths paths = tokenizeString(attr);
|
||||||
for (Strings::iterator i = paths.begin(); i != paths.end(); ++i) {
|
foreach (Strings::iterator, i, paths) {
|
||||||
if (isStorePath(*i))
|
if (isStorePath(*i))
|
||||||
result.insert(*i);
|
result.insert(*i);
|
||||||
else if (drv.outputs.find(*i) != drv.outputs.end())
|
else if (drv.outputs.find(*i) != drv.outputs.end())
|
||||||
|
@ -1886,7 +1874,7 @@ void DerivationGoal::computeClosure()
|
||||||
allowedReferences should really be per-output. */
|
allowedReferences should really be per-output. */
|
||||||
if (drv.env.find("allowedReferences") != drv.env.end()) {
|
if (drv.env.find("allowedReferences") != drv.env.end()) {
|
||||||
PathSet allowed = parseReferenceSpecifiers(drv, drv.env["allowedReferences"]);
|
PathSet allowed = parseReferenceSpecifiers(drv, drv.env["allowedReferences"]);
|
||||||
for (PathSet::iterator i = references.begin(); i != references.end(); ++i)
|
foreach (PathSet::iterator, i, references)
|
||||||
if (allowed.find(*i) == allowed.end())
|
if (allowed.find(*i) == allowed.end())
|
||||||
throw BuildError(format("output is not allowed to refer to path `%1%'") % *i);
|
throw BuildError(format("output is not allowed to refer to path `%1%'") % *i);
|
||||||
}
|
}
|
||||||
|
@ -1990,8 +1978,7 @@ void DerivationGoal::handleEOF(int fd)
|
||||||
PathSet DerivationGoal::checkPathValidity(bool returnValid)
|
PathSet DerivationGoal::checkPathValidity(bool returnValid)
|
||||||
{
|
{
|
||||||
PathSet result;
|
PathSet result;
|
||||||
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
i != drv.outputs.end(); ++i)
|
|
||||||
if (worker.store.isValidPath(i->second.path)) {
|
if (worker.store.isValidPath(i->second.path)) {
|
||||||
if (returnValid) result.insert(i->second.path);
|
if (returnValid) result.insert(i->second.path);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2495,9 +2482,7 @@ void Worker::childTerminated(pid_t pid, bool wakeSleepers)
|
||||||
if (wakeSleepers) {
|
if (wakeSleepers) {
|
||||||
|
|
||||||
/* Wake up goals waiting for a build slot. */
|
/* Wake up goals waiting for a build slot. */
|
||||||
for (WeakGoals::iterator i = wantingToBuild.begin();
|
foreach (WeakGoals::iterator, i, wantingToBuild) {
|
||||||
i != wantingToBuild.end(); ++i)
|
|
||||||
{
|
|
||||||
GoalPtr goal = i->lock();
|
GoalPtr goal = i->lock();
|
||||||
if (goal) wakeUp(goal);
|
if (goal) wakeUp(goal);
|
||||||
}
|
}
|
||||||
|
@ -2533,9 +2518,7 @@ void Worker::waitForAWhile(GoalPtr goal)
|
||||||
|
|
||||||
void Worker::run(const Goals & _topGoals)
|
void Worker::run(const Goals & _topGoals)
|
||||||
{
|
{
|
||||||
for (Goals::iterator i = _topGoals.begin();
|
foreach (Goals::iterator, i, _topGoals) topGoals.insert(*i);
|
||||||
i != _topGoals.end(); ++i)
|
|
||||||
topGoals.insert(*i);
|
|
||||||
|
|
||||||
startNest(nest, lvlDebug, format("entered goal loop"));
|
startNest(nest, lvlDebug, format("entered goal loop"));
|
||||||
|
|
||||||
|
@ -2547,7 +2530,7 @@ void Worker::run(const Goals & _topGoals)
|
||||||
while (!awake.empty() && !topGoals.empty()) {
|
while (!awake.empty() && !topGoals.empty()) {
|
||||||
WeakGoals awake2(awake);
|
WeakGoals awake2(awake);
|
||||||
awake.clear();
|
awake.clear();
|
||||||
for (WeakGoals::iterator i = awake2.begin(); i != awake2.end(); ++i) {
|
foreach (WeakGoals::iterator, i, awake2) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
GoalPtr goal = i->lock();
|
GoalPtr goal = i->lock();
|
||||||
if (goal) goal->work();
|
if (goal) goal->work();
|
||||||
|
@ -2709,14 +2692,13 @@ void LocalStore::buildDerivations(const PathSet & drvPaths)
|
||||||
Worker worker(*this);
|
Worker worker(*this);
|
||||||
|
|
||||||
Goals goals;
|
Goals goals;
|
||||||
for (PathSet::const_iterator i = drvPaths.begin();
|
foreach (PathSet::const_iterator, i, drvPaths)
|
||||||
i != drvPaths.end(); ++i)
|
|
||||||
goals.insert(worker.makeDerivationGoal(*i));
|
goals.insert(worker.makeDerivationGoal(*i));
|
||||||
|
|
||||||
worker.run(goals);
|
worker.run(goals);
|
||||||
|
|
||||||
PathSet failed;
|
PathSet failed;
|
||||||
for (Goals::iterator i = goals.begin(); i != goals.end(); ++i)
|
foreach (Goals::iterator, i, goals)
|
||||||
if ((*i)->getExitCode() == Goal::ecFailed) {
|
if ((*i)->getExitCode() == Goal::ecFailed) {
|
||||||
DerivationGoal * i2 = dynamic_cast<DerivationGoal *>(i->get());
|
DerivationGoal * i2 = dynamic_cast<DerivationGoal *>(i->get());
|
||||||
assert(i2);
|
assert(i2);
|
||||||
|
|
|
@ -21,8 +21,7 @@ Path writeDerivation(const Derivation & drv, const string & name)
|
||||||
{
|
{
|
||||||
PathSet references;
|
PathSet references;
|
||||||
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
||||||
for (DerivationInputs::const_iterator i = drv.inputDrvs.begin();
|
foreach (DerivationInputs::const_iterator, i, drv.inputDrvs)
|
||||||
i != drv.inputDrvs.end(); ++i)
|
|
||||||
references.insert(i->first);
|
references.insert(i->first);
|
||||||
/* Note that the outputs of a derivation are *not* references
|
/* Note that the outputs of a derivation are *not* references
|
||||||
(that can be missing (of course) and should not necessarily be
|
(that can be missing (of course) and should not necessarily be
|
||||||
|
|
|
@ -247,9 +247,7 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
|
||||||
Strings tempRootFiles = readDirectory(
|
Strings tempRootFiles = readDirectory(
|
||||||
(format("%1%/%2%") % nixStateDir % tempRootsDir).str());
|
(format("%1%/%2%") % nixStateDir % tempRootsDir).str());
|
||||||
|
|
||||||
for (Strings::iterator i = tempRootFiles.begin();
|
foreach (Strings::iterator, i, tempRootFiles) {
|
||||||
i != tempRootFiles.end(); ++i)
|
|
||||||
{
|
|
||||||
Path path = (format("%1%/%2%/%3%") % nixStateDir % tempRootsDir % *i).str();
|
Path path = (format("%1%/%2%/%3%") % nixStateDir % tempRootsDir % *i).str();
|
||||||
|
|
||||||
debug(format("reading temporary root file `%1%'") % path);
|
debug(format("reading temporary root file `%1%'") % path);
|
||||||
|
@ -328,7 +326,7 @@ static void findRoots(const Path & path, bool recurseSymlinks,
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
foreach (Strings::iterator, i, names)
|
||||||
findRoots(path + "/" + *i, recurseSymlinks, deleteStale, roots);
|
findRoots(path + "/" + *i, recurseSymlinks, deleteStale, roots);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +397,7 @@ static void addAdditionalRoots(PathSet & roots)
|
||||||
|
|
||||||
Strings paths = tokenizeString(result, "\n");
|
Strings paths = tokenizeString(result, "\n");
|
||||||
|
|
||||||
for (Strings::iterator i = paths.begin(); i != paths.end(); ++i) {
|
foreach (Strings::iterator, i, paths) {
|
||||||
if (isInStore(*i)) {
|
if (isInStore(*i)) {
|
||||||
Path path = toStorePath(*i);
|
Path path = toStorePath(*i);
|
||||||
if (roots.find(path) == roots.end() && store->isValidPath(path)) {
|
if (roots.find(path) == roots.end() && store->isValidPath(path)) {
|
||||||
|
@ -421,8 +419,7 @@ static void dfsVisit(const PathSet & paths, const Path & path,
|
||||||
if (store->isValidPath(path))
|
if (store->isValidPath(path))
|
||||||
store->queryReferences(path, references);
|
store->queryReferences(path, references);
|
||||||
|
|
||||||
for (PathSet::iterator i = references.begin();
|
foreach (PathSet::iterator, i, references)
|
||||||
i != references.end(); ++i)
|
|
||||||
/* Don't traverse into paths that don't exist. That can
|
/* Don't traverse into paths that don't exist. That can
|
||||||
happen due to substitutes for non-existent paths. */
|
happen due to substitutes for non-existent paths. */
|
||||||
if (*i != path && paths.find(*i) != paths.end())
|
if (*i != path && paths.find(*i) != paths.end())
|
||||||
|
@ -436,7 +433,7 @@ Paths topoSortPaths(const PathSet & paths)
|
||||||
{
|
{
|
||||||
Paths sorted;
|
Paths sorted;
|
||||||
PathSet visited;
|
PathSet visited;
|
||||||
for (PathSet::const_iterator i = paths.begin(); i != paths.end(); ++i)
|
foreach (PathSet::const_iterator, i, paths)
|
||||||
dfsVisit(paths, *i, visited, sorted);
|
dfsVisit(paths, *i, visited, sorted);
|
||||||
return sorted;
|
return sorted;
|
||||||
}
|
}
|
||||||
|
@ -453,7 +450,7 @@ static time_t lastFileAccessTime(const Path & path)
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
time_t last = 0;
|
time_t last = 0;
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i) {
|
foreach (Strings::iterator, i, names) {
|
||||||
time_t t = lastFileAccessTime(path + "/" + *i);
|
time_t t = lastFileAccessTime(path + "/" + *i);
|
||||||
if (t > last) last = t;
|
if (t > last) last = t;
|
||||||
}
|
}
|
||||||
|
@ -594,8 +591,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
Roots rootMap = options.ignoreLiveness ? Roots() : nix::findRoots(true);
|
Roots rootMap = options.ignoreLiveness ? Roots() : nix::findRoots(true);
|
||||||
|
|
||||||
PathSet roots;
|
PathSet roots;
|
||||||
for (Roots::iterator i = rootMap.begin(); i != rootMap.end(); ++i)
|
foreach (Roots::iterator, i, rootMap) roots.insert(i->second);
|
||||||
roots.insert(i->second);
|
|
||||||
|
|
||||||
/* Add additional roots returned by the program specified by the
|
/* Add additional roots returned by the program specified by the
|
||||||
NIX_ROOT_FINDER environment variable. This is typically used
|
NIX_ROOT_FINDER environment variable. This is typically used
|
||||||
|
@ -613,13 +609,11 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
roots under the `references' relation. */
|
roots under the `references' relation. */
|
||||||
printMsg(lvlError, format("computing live paths..."));
|
printMsg(lvlError, format("computing live paths..."));
|
||||||
PathSet livePaths;
|
PathSet livePaths;
|
||||||
for (PathSet::const_iterator i = roots.begin(); i != roots.end(); ++i)
|
foreach (PathSet::const_iterator, i, roots)
|
||||||
computeFSClosure(canonPath(*i), livePaths);
|
computeFSClosure(canonPath(*i), livePaths);
|
||||||
|
|
||||||
if (gcKeepDerivations) {
|
if (gcKeepDerivations) {
|
||||||
for (PathSet::iterator i = livePaths.begin();
|
foreach (PathSet::iterator, i, livePaths) {
|
||||||
i != livePaths.end(); ++i)
|
|
||||||
{
|
|
||||||
/* Note that the deriver need not be valid (e.g., if we
|
/* Note that the deriver need not be valid (e.g., if we
|
||||||
previously ran the collector with `gcKeepDerivations'
|
previously ran the collector with `gcKeepDerivations'
|
||||||
turned off). */
|
turned off). */
|
||||||
|
@ -631,8 +625,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
|
|
||||||
if (gcKeepOutputs) {
|
if (gcKeepOutputs) {
|
||||||
/* Hmz, identical to storePathRequisites in nix-store. */
|
/* Hmz, identical to storePathRequisites in nix-store. */
|
||||||
for (PathSet::iterator i = livePaths.begin();
|
foreach (PathSet::iterator, i, livePaths)
|
||||||
i != livePaths.end(); ++i)
|
|
||||||
if (isDerivation(*i)) {
|
if (isDerivation(*i)) {
|
||||||
Derivation drv = derivationFromPath(*i);
|
Derivation drv = derivationFromPath(*i);
|
||||||
|
|
||||||
|
@ -642,8 +635,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
gcLevel = defaultGcLevel;
|
gcLevel = defaultGcLevel;
|
||||||
|
|
||||||
if (gcLevel >= gcKeepOutputsThreshold)
|
if (gcLevel >= gcKeepOutputsThreshold)
|
||||||
for (DerivationOutputs::iterator j = drv.outputs.begin();
|
foreach (DerivationOutputs::iterator, j, drv.outputs)
|
||||||
j != drv.outputs.end(); ++j)
|
|
||||||
if (isValidPath(j->second.path))
|
if (isValidPath(j->second.path))
|
||||||
computeFSClosure(j->second.path, livePaths);
|
computeFSClosure(j->second.path, livePaths);
|
||||||
}
|
}
|
||||||
|
@ -668,7 +660,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
|
||||||
(and computeFSClosure() assumes that the presence of a path
|
(and computeFSClosure() assumes that the presence of a path
|
||||||
means that it has already been closed). */
|
means that it has already been closed). */
|
||||||
PathSet tempRootsClosed;
|
PathSet tempRootsClosed;
|
||||||
for (PathSet::iterator i = tempRoots.begin(); i != tempRoots.end(); ++i)
|
foreach (PathSet::iterator, i, tempRoots)
|
||||||
if (isValidPath(*i))
|
if (isValidPath(*i))
|
||||||
computeFSClosure(*i, tempRootsClosed);
|
computeFSClosure(*i, tempRootsClosed);
|
||||||
else
|
else
|
||||||
|
|
|
@ -162,7 +162,7 @@ void canonicalisePathMetaData(const Path & path, bool recurse)
|
||||||
|
|
||||||
if (recurse && S_ISDIR(st.st_mode)) {
|
if (recurse && S_ISDIR(st.st_mode)) {
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
foreach (Strings::iterator, i, names)
|
||||||
canonicalisePathMetaData(path + "/" + *i, true);
|
canonicalisePathMetaData(path + "/" + *i, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,7 @@ ValidPathInfo LocalStore::queryPathInfo(const Path & path, bool ignoreErrors)
|
||||||
/* Parse it. */
|
/* Parse it. */
|
||||||
Strings lines = tokenizeString(info, "\n");
|
Strings lines = tokenizeString(info, "\n");
|
||||||
|
|
||||||
for (Strings::iterator i = lines.begin(); i != lines.end(); ++i) {
|
foreach (Strings::iterator, i, lines) {
|
||||||
string::size_type p = i->find(':');
|
string::size_type p = i->find(':');
|
||||||
if (p == string::npos) continue; /* bad line */
|
if (p == string::npos) continue; /* bad line */
|
||||||
string name(*i, 0, p);
|
string name(*i, 0, p);
|
||||||
|
@ -433,7 +433,7 @@ PathSet LocalStore::queryValidPaths()
|
||||||
{
|
{
|
||||||
PathSet paths;
|
PathSet paths;
|
||||||
Strings entries = readDirectory(nixDBPath + "/info");
|
Strings entries = readDirectory(nixDBPath + "/info");
|
||||||
for (Strings::iterator i = entries.begin(); i != entries.end(); ++i)
|
foreach (Strings::iterator, i, entries)
|
||||||
if (i->at(0) != '.') paths.insert(nixStore + "/" + *i);
|
if (i->at(0) != '.') paths.insert(nixStore + "/" + *i);
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ bool LocalStore::queryReferrersInternal(const Path & path, PathSet & referrers)
|
||||||
|
|
||||||
Paths refs = tokenizeString(readFile(fd), " ");
|
Paths refs = tokenizeString(readFile(fd), " ");
|
||||||
|
|
||||||
for (Paths::iterator i = refs.begin(); i != refs.end(); ++i)
|
foreach (Paths::iterator, i, refs)
|
||||||
/* Referrers can be invalid (see registerValidPath() for the
|
/* Referrers can be invalid (see registerValidPath() for the
|
||||||
invariant), so we only return one if it is valid. */
|
invariant), so we only return one if it is valid. */
|
||||||
if (isStorePath(*i) && isValidPath(*i)) referrers.insert(*i); else allValid = false;
|
if (isStorePath(*i) && isValidPath(*i)) referrers.insert(*i); else allValid = false;
|
||||||
|
@ -600,8 +600,7 @@ static void dfsVisit(std::map<Path, ValidPathInfo> & infos,
|
||||||
|
|
||||||
ValidPathInfo & info(infos[path]);
|
ValidPathInfo & info(infos[path]);
|
||||||
|
|
||||||
for (PathSet::iterator i = info.references.begin();
|
foreach (PathSet::iterator, i, info.references)
|
||||||
i != info.references.end(); ++i)
|
|
||||||
if (infos.find(*i) != infos.end())
|
if (infos.find(*i) != infos.end())
|
||||||
dfsVisit(infos, *i, visited, sorted);
|
dfsVisit(infos, *i, visited, sorted);
|
||||||
|
|
||||||
|
@ -616,15 +615,15 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
||||||
/* Sort the paths topologically under the references relation, so
|
/* Sort the paths topologically under the references relation, so
|
||||||
that if path A is referenced by B, then A is registered before
|
that if path A is referenced by B, then A is registered before
|
||||||
B. */
|
B. */
|
||||||
for (ValidPathInfos::const_iterator i = infos.begin(); i != infos.end(); ++i)
|
foreach (ValidPathInfos::const_iterator, i, infos)
|
||||||
infosMap[i->path] = *i;
|
infosMap[i->path] = *i;
|
||||||
|
|
||||||
PathSet visited;
|
PathSet visited;
|
||||||
Paths sorted;
|
Paths sorted;
|
||||||
for (ValidPathInfos::const_iterator i = infos.begin(); i != infos.end(); ++i)
|
foreach (ValidPathInfos::const_iterator, i, infos)
|
||||||
dfsVisit(infosMap, i->path, visited, sorted);
|
dfsVisit(infosMap, i->path, visited, sorted);
|
||||||
|
|
||||||
for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i)
|
foreach (Paths::iterator, i, sorted)
|
||||||
registerValidPath(infosMap[*i]);
|
registerValidPath(infosMap[*i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,16 +30,14 @@ void computeFSClosure(const Path & storePath,
|
||||||
else
|
else
|
||||||
store->queryReferences(storePath, references);
|
store->queryReferences(storePath, references);
|
||||||
|
|
||||||
for (PathSet::iterator i = references.begin();
|
foreach (PathSet::iterator, i, references)
|
||||||
i != references.end(); ++i)
|
|
||||||
computeFSClosure(*i, paths, flipDirection);
|
computeFSClosure(*i, paths, flipDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Path findOutput(const Derivation & drv, string id)
|
Path findOutput(const Derivation & drv, string id)
|
||||||
{
|
{
|
||||||
for (DerivationOutputs::const_iterator i = drv.outputs.begin();
|
foreach (DerivationOutputs::const_iterator, i, drv.outputs)
|
||||||
i != drv.outputs.end(); ++i)
|
|
||||||
if (i->first == id) return i->second.path;
|
if (i->first == id) return i->second.path;
|
||||||
throw Error(format("derivation has no output `%1%'") % id);
|
throw Error(format("derivation has no output `%1%'") % id);
|
||||||
}
|
}
|
||||||
|
@ -67,20 +65,17 @@ void queryMissing(const PathSet & targets,
|
||||||
Derivation drv = derivationFromPath(p);
|
Derivation drv = derivationFromPath(p);
|
||||||
|
|
||||||
bool mustBuild = false;
|
bool mustBuild = false;
|
||||||
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
i != drv.outputs.end(); ++i)
|
|
||||||
if (!store->isValidPath(i->second.path) && !store->hasSubstitutes(i->second.path))
|
if (!store->isValidPath(i->second.path) && !store->hasSubstitutes(i->second.path))
|
||||||
mustBuild = true;
|
mustBuild = true;
|
||||||
|
|
||||||
if (mustBuild) {
|
if (mustBuild) {
|
||||||
willBuild.insert(p);
|
willBuild.insert(p);
|
||||||
todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
||||||
for (DerivationInputs::iterator i = drv.inputDrvs.begin();
|
foreach (DerivationInputs::iterator, i, drv.inputDrvs)
|
||||||
i != drv.inputDrvs.end(); ++i)
|
|
||||||
todo.insert(i->first);
|
todo.insert(i->first);
|
||||||
} else
|
} else
|
||||||
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
||||||
i != drv.outputs.end(); ++i)
|
|
||||||
todo.insert(i->second.path);
|
todo.insert(i->second.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ static void hashAndLink(bool dryRun, HashToPath & hashToPath,
|
||||||
|
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
Strings names = readDirectory(path);
|
Strings names = readDirectory(path);
|
||||||
for (Strings::iterator i = names.begin(); i != names.end(); ++i)
|
foreach (Strings::iterator, i, names)
|
||||||
hashAndLink(dryRun, hashToPath, stats, path + "/" + *i);
|
hashAndLink(dryRun, hashToPath, stats, path + "/" + *i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ void LocalStore::optimiseStore(bool dryRun, OptimiseStats & stats)
|
||||||
|
|
||||||
PathSet paths = queryValidPaths();
|
PathSet paths = queryValidPaths();
|
||||||
|
|
||||||
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) {
|
foreach (PathSet::iterator, i, paths) {
|
||||||
addTempRoot(*i);
|
addTempRoot(*i);
|
||||||
if (!isValidPath(*i)) continue; /* path was GC'ed, probably */
|
if (!isValidPath(*i)) continue; /* path was GC'ed, probably */
|
||||||
startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i);
|
startNest(nest, lvlChatty, format("hashing files in `%1%'") % *i);
|
||||||
|
|
|
@ -155,7 +155,7 @@ bool PathLocks::lockPaths(const PathSet & _paths,
|
||||||
paths.sort();
|
paths.sort();
|
||||||
|
|
||||||
/* Acquire the lock for each path. */
|
/* Acquire the lock for each path. */
|
||||||
for (Paths::iterator i = paths.begin(); i != paths.end(); i++) {
|
foreach (Paths::iterator, i, paths) {
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
Path path = *i;
|
Path path = *i;
|
||||||
Path lockPath = path + ".lock";
|
Path lockPath = path + ".lock";
|
||||||
|
@ -219,7 +219,7 @@ PathLocks::~PathLocks()
|
||||||
|
|
||||||
void PathLocks::unlock()
|
void PathLocks::unlock()
|
||||||
{
|
{
|
||||||
for (list<FDPair>::iterator i = fds.begin(); i != fds.end(); i++) {
|
foreach (list<FDPair>::iterator, i, fds) {
|
||||||
if (deletePaths) deleteLockFilePreClose(i->second, i->first);
|
if (deletePaths) deleteLockFilePreClose(i->second, i->first);
|
||||||
|
|
||||||
lockedPaths.erase(i->second);
|
lockedPaths.erase(i->second);
|
||||||
|
|
|
@ -29,8 +29,7 @@ Path readStorePath(Source & from)
|
||||||
PathSet readStorePaths(Source & from)
|
PathSet readStorePaths(Source & from)
|
||||||
{
|
{
|
||||||
PathSet paths = readStringSet(from);
|
PathSet paths = readStringSet(from);
|
||||||
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i)
|
foreach (PathSet::iterator, i, paths) assertStorePath(*i);
|
||||||
assertStorePath(*i);
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ void checkStoreName(const string & name)
|
||||||
reasons (e.g., "." and ".."). */
|
reasons (e.g., "." and ".."). */
|
||||||
if (string(name, 0, 1) == ".")
|
if (string(name, 0, 1) == ".")
|
||||||
throw Error(format("illegal name: `%1%'") % name);
|
throw Error(format("illegal name: `%1%'") % name);
|
||||||
for (string::const_iterator i = name.begin(); i != name.end(); ++i)
|
foreach (string::const_iterator, i, name)
|
||||||
if (!((*i >= 'A' && *i <= 'Z') ||
|
if (!((*i >= 'A' && *i <= 'Z') ||
|
||||||
(*i >= 'a' && *i <= 'z') ||
|
(*i >= 'a' && *i <= 'z') ||
|
||||||
(*i >= '0' && *i <= '9') ||
|
(*i >= '0' && *i <= '9') ||
|
||||||
|
@ -207,7 +207,7 @@ Path computeStorePathForText(const string & name, const string & s,
|
||||||
hacky, but we can't put them in `s' since that would be
|
hacky, but we can't put them in `s' since that would be
|
||||||
ambiguous. */
|
ambiguous. */
|
||||||
string type = "text";
|
string type = "text";
|
||||||
for (PathSet::const_iterator i = references.begin(); i != references.end(); ++i) {
|
foreach (PathSet::const_iterator, i, references) {
|
||||||
type += ":";
|
type += ":";
|
||||||
type += *i;
|
type += *i;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ string makeValidityRegistration(const PathSet & paths,
|
||||||
{
|
{
|
||||||
string s = "";
|
string s = "";
|
||||||
|
|
||||||
for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) {
|
foreach (PathSet::iterator, i, paths) {
|
||||||
s += *i + "\n";
|
s += *i + "\n";
|
||||||
|
|
||||||
if (showHash)
|
if (showHash)
|
||||||
|
@ -237,8 +237,7 @@ string makeValidityRegistration(const PathSet & paths,
|
||||||
|
|
||||||
s += (format("%1%\n") % references.size()).str();
|
s += (format("%1%\n") % references.size()).str();
|
||||||
|
|
||||||
for (PathSet::iterator j = references.begin();
|
foreach (PathSet::iterator, j, references)
|
||||||
j != references.end(); ++j)
|
|
||||||
s += *j + "\n";
|
s += *j + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,9 +271,7 @@ ValidPathInfo decodeValidPathInfo(std::istream & str, bool hashGiven)
|
||||||
string showPaths(const PathSet & paths)
|
string showPaths(const PathSet & paths)
|
||||||
{
|
{
|
||||||
string s;
|
string s;
|
||||||
for (PathSet::const_iterator i = paths.begin();
|
foreach (PathSet::const_iterator, i, paths) {
|
||||||
i != paths.end(); ++i)
|
|
||||||
{
|
|
||||||
if (s.size() != 0) s += ", ";
|
if (s.size() != 0) s += ", ";
|
||||||
s += "`" + *i + "'";
|
s += "`" + *i + "'";
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ void LocalStore::upgradeStore12()
|
||||||
Paths paths;
|
Paths paths;
|
||||||
nixDB.enumTable(noTxn, dbValidPaths, paths);
|
nixDB.enumTable(noTxn, dbValidPaths, paths);
|
||||||
|
|
||||||
for (Paths::iterator i = paths.begin(); i != paths.end(); ++i) {
|
foreach (Paths::iterator, i, paths) {
|
||||||
ValidPathInfo info;
|
ValidPathInfo info;
|
||||||
info.path = *i;
|
info.path = *i;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue