1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

nix store dump-path: Refuse to write NARs to the terminal

This commit is contained in:
Eelco Dolstra 2025-10-17 20:23:20 +02:00
parent ad2360c59f
commit 109f6449cc

View file

@ -4,6 +4,14 @@
using namespace nix; 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 struct CmdDumpPath : StorePathCommand
{ {
std::string description() override std::string description() override
@ -20,7 +28,7 @@ struct CmdDumpPath : StorePathCommand
void run(ref<Store> store, const StorePath & storePath) override void run(ref<Store> store, const StorePath & storePath) override
{ {
FdSink sink(getStandardOutput()); auto sink = getNarSink();
store->narFromPath(storePath, sink); store->narFromPath(storePath, sink);
sink.flush(); sink.flush();
} }
@ -51,7 +59,7 @@ struct CmdDumpPath2 : Command
void run() override void run() override
{ {
FdSink sink(getStandardOutput()); auto sink = getNarSink();
dumpPath(path, sink); dumpPath(path, sink);
sink.flush(); sink.flush();
} }