1
1
Fork 0
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:
Eelco Dolstra 2025-10-19 12:41:55 +00:00 committed by GitHub
commit 3c03050cd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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();
}