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:
parent
ad2360c59f
commit
109f6449cc
1 changed files with 10 additions and 2 deletions
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue