Use a proper enum rather than a boolean in runProgramInStore

Makes the call-site much easier to understand.
This commit is contained in:
Théophane Hufschmitt 2023-12-01 15:35:21 +01:00
parent 743232bf04
commit ea2dd16623
4 changed files with 12 additions and 7 deletions

View file

@ -662,7 +662,7 @@ struct CmdDevelop : Common, MixEnvironment
} }
} }
runProgramInStore(store, true, shell, args, buildEnvironment.getSystem()); runProgramInStore(store, UseSearchPath::Use, shell, args, buildEnvironment.getSystem());
} }
}; };

View file

@ -49,7 +49,7 @@ struct CmdFmt : SourceExprCommand {
} }
} }
runProgramInStore(store, false, app.program, programArgs); runProgramInStore(store, UseSearchPath::DontUse, app.program, programArgs);
}; };
}; };

View file

@ -25,7 +25,7 @@ std::string chrootHelperName = "__run_in_chroot";
namespace nix { namespace nix {
void runProgramInStore(ref<Store> store, void runProgramInStore(ref<Store> store,
bool search, UseSearchPath useSearchPath,
const std::string & program, const std::string & program,
const Strings & args, const Strings & args,
std::optional<std::string_view> system) std::optional<std::string_view> system)
@ -59,7 +59,7 @@ void runProgramInStore(ref<Store> store,
if (system) if (system)
setPersonality(*system); setPersonality(*system);
if (search) if (useSearchPath == UseSearchPath::Use)
execvp(program.c_str(), stringsToCharPtrs(args).data()); execvp(program.c_str(), stringsToCharPtrs(args).data());
else else
execv(program.c_str(), stringsToCharPtrs(args).data()); execv(program.c_str(), stringsToCharPtrs(args).data());
@ -136,7 +136,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment
Strings args; Strings args;
for (auto & arg : command) args.push_back(arg); for (auto & arg : command) args.push_back(arg);
runProgramInStore(store, true, *command.begin(), args); runProgramInStore(store, UseSearchPath::Use, *command.begin(), args);
} }
}; };
@ -198,7 +198,7 @@ struct CmdRun : InstallableValueCommand
Strings allArgs{app.program}; Strings allArgs{app.program};
for (auto & i : args) allArgs.push_back(i); for (auto & i : args) allArgs.push_back(i);
runProgramInStore(store, false, app.program, allArgs); runProgramInStore(store, UseSearchPath::DontUse, app.program, allArgs);
} }
}; };

View file

@ -5,8 +5,13 @@
namespace nix { namespace nix {
enum struct UseSearchPath {
Use,
DontUse
};
void runProgramInStore(ref<Store> store, void runProgramInStore(ref<Store> store,
bool search, UseSearchPath useSearchPath,
const std::string & program, const std::string & program,
const Strings & args, const Strings & args,
std::optional<std::string_view> system = std::nullopt); std::optional<std::string_view> system = std::nullopt);