From 546463964e8de7c82f976c9b1808b9867504b4ef Mon Sep 17 00:00:00 2001
From: Matthew Heon <matthew.heon@gmail.com>
Date: Thu, 1 Mar 2018 17:38:22 -0500
Subject: Fix issue with podman logs on fresh containers

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #434
Approved by: baude
---
 cmd/podman/logs.go | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

(limited to 'cmd')

diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go
index 5551d6157..07d95aaf8 100644
--- a/cmd/podman/logs.go
+++ b/cmd/podman/logs.go
@@ -10,6 +10,7 @@ import (
 	"bufio"
 	"github.com/pkg/errors"
 	"github.com/projectatomic/libpod/libpod"
+	"github.com/sirupsen/logrus"
 	"github.com/urfave/cli"
 )
 
@@ -104,7 +105,24 @@ func logsCmd(c *cli.Context) error {
 		return err
 	}
 
-	file, err := os.Open(ctr.LogPath())
+	logPath := ctr.LogPath()
+
+	state, err := ctr.State()
+	if err != nil {
+		return err
+	}
+
+	// If the log file does not exist yet and the container is in the
+	// Configured state, it has never been started before and no logs exist
+	// Exit cleanly in this case
+	if _, err := os.Stat(logPath); err != nil {
+		if state == libpod.ContainerStateConfigured {
+			logrus.Debugf("Container has not been created, no logs exist yet")
+			return nil
+		}
+	}
+
+	file, err := os.Open(logPath)
 	if err != nil {
 		return errors.Wrapf(err, "unable to read container log file")
 	}
-- 
cgit v1.2.3-54-g00ecf