eclipseo / rpms / dnf

Forked from rpms/dnf 5 years ago
Clone
Blob Blame History Raw
From b7c55d013542ce9e4c7775737bf454d9b10df977 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Tue, 17 Nov 2015 15:04:19 -0800
Subject: [PATCH] cli: don't crash if y/n and sys.stdin is None (RhBug:1278382)

Per https://bugzilla.redhat.com/show_bug.cgi?id=1278382 , if
sys.stdin is somehow None (which currently seems to be the case
when a dnf command is run in virt-builder) and a dnf command
leads to a y/n question, dnf will crash. This should fix it.
---
 AUTHORS        | 1 +
 dnf/cli/cli.py | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/AUTHORS b/AUTHORS
index 8e0d3be..ba95371 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -56,6 +56,7 @@ DNF AUTHORS
 DNF CONTRIBUTORS
 ----------------
     Adam Salih <salih.max@gmail.com>
+    Adam Williamson <awilliam@redhat.com>
     Albert Uchytil <auchytil@redhat.com>
     Alberto Ruiz <aruiz@redhat.com>
     Baurzhan Muftakhidinov <baurthefirst@gmail.com>
diff --git a/dnf/cli/cli.py b/dnf/cli/cli.py
index 0918736..80cfa48 100644
--- a/dnf/cli/cli.py
+++ b/dnf/cli/cli.py
@@ -248,7 +248,7 @@ class BaseCli(dnf.Base):
 
             elif result == 1:
                 ay = self.conf.assumeyes and not self.conf.assumeno
-                if not sys.stdin.isatty() and not ay:
+                if (not sys.stdin or not sys.stdin.isatty()) and not ay:
                     raise dnf.exceptions.Error(_('Refusing to automatically import keys when running ' \
                             'unattended.\nUse "-y" to override.'))
 
-- 
2.4.3