From c6ffbe445580d004c7b96313d265c9a7e6bd0815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Zborowski?= Date: Wed, 13 Jan 2016 20:50:27 +0100 Subject: [PATCH] more meaningful message printed in case ~/.rr file doesn't simply exist. fixes #1583 --- src/TraceStream.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/TraceStream.cc b/src/TraceStream.cc index d94ac9d2f3e..49247dd8996 100644 --- a/src/TraceStream.cc +++ b/src/TraceStream.cc @@ -51,9 +51,16 @@ static TraceStream::Substream operator++(TraceStream::Substream& s) { return s; } +static bool file_exists(const string& file) { + struct stat dummy; + return !file.empty() && stat(file.c_str(), &dummy) == 0 + && S_ISREG(dummy.st_mode); +} + static bool dir_exists(const string& dir) { struct stat dummy; - return !dir.empty() && stat(dir.c_str(), &dummy) == 0; + return !dir.empty() && stat(dir.c_str(), &dummy) == 0 + && S_ISDIR(dummy.st_mode); } static string default_rr_trace_dir() { @@ -592,6 +599,14 @@ TraceReader::TraceReader(const string& dir) } string path = version_path(); + if (!file_exists(path)) { + fprintf( + stderr, + "rr: warning: No traces have been recorded so far.\n" + "\n"); + exit(EX_DATAERR); + } + fstream vfile(path.c_str(), fstream::in); if (!vfile.good()) { fprintf(