mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Merge pull request #14290 from NixOS/dont-write-nar-to-tty
nix store dump-path: Refuse to write NARs to the terminal
This commit is contained in:
commit
3c03050cd6
1 changed files with 10 additions and 2 deletions
|
|
@ -4,6 +4,14 @@
|
|||
|
||||
using namespace nix;
|
||||
|
||||
static FdSink getNarSink()
|
||||
{
|
||||
auto fd = getStandardOutput();
|
||||
if (isatty(fd))
|
||||
throw UsageError("refusing to write NAR to a terminal");
|
||||
return FdSink(std::move(fd));
|
||||
}
|
||||
|
||||
struct CmdDumpPath : StorePathCommand
|
||||
{
|
||||
std::string description() override
|
||||
|
|
@ -20,7 +28,7 @@ struct CmdDumpPath : StorePathCommand
|
|||
|
||||
void run(ref<Store> store, const StorePath & storePath) override
|
||||
{
|
||||
FdSink sink(getStandardOutput());
|
||||
auto sink = getNarSink();
|
||||
store->narFromPath(storePath, sink);
|
||||
sink.flush();
|
||||
}
|
||||
|
|
@ -51,7 +59,7 @@ struct CmdDumpPath2 : Command
|
|||
|
||||
void run() override
|
||||
{
|
||||
FdSink sink(getStandardOutput());
|
||||
auto sink = getNarSink();
|
||||
dumpPath(path, sink);
|
||||
sink.flush();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue