public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Ondrej Oprala <ondrej.oprala@gmail.com>
To: libabigail@sourceware.org
Subject: [PATCH] abipkgdiff should properly report missing files
Date: Fri, 01 Jan 2016 00:00:00 -0000	[thread overview]
Message-ID: <812c4d76-7ee5-3cd9-a657-f1f9f30e1df1@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

Hi,

this patch is based on our discussion on the IRC channel from today.

Basically, when abipkgdiff is given a non-existent path for a package, 
the logic will let it pass and just mark it as an unknown kind of 
package, giving the vague warning "<PKG> should be a valid package 
file". This patch ensures we properly diagnose the issue and quit 
prematurely.

Cheers,

Ondrej



[-- Attachment #2: 0001-Properly-report-missing-files-for-abipkgdiff.patch --]
[-- Type: text/x-patch, Size: 2995 bytes --]

From 20ca3d5e670877bcba57fefb791b05303d4ab1e0 Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <ondrej.oprala@gmail.com>
Date: Mon, 12 Dec 2016 16:27:15 +0100
Subject: [PATCH] Properly report missing files for abipkgdiff

Currently, if abipkgdiff is given a path to a nonexistent file,
it propagates all the way until package classification
and ends up being reported as "PKG should be a valid package file",
which doesn't hint it's not there at all.

        * tools/abipkgdiff.cc: (class options): Add the "nonexistent_file" flag
        (parse_command_line): Check if the files given exist.
        (main): Check the nonexistent_file flag. If any of the input
        files don't exist, report it and exit.

Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
---
 tools/abipkgdiff.cc | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc
index 0999141..a00073f 100644
--- a/tools/abipkgdiff.cc
+++ b/tools/abipkgdiff.cc
@@ -162,6 +162,7 @@ public:
   bool		display_usage;
   bool		display_version;
   bool		missing_operand;
+  bool		nonexistent_file;
   bool		abignore;
   bool		parallel;
   string	package1;
@@ -188,6 +189,7 @@ public:
       display_usage(),
       display_version(),
       missing_operand(),
+      nonexistent_file(),
       abignore(true),
       parallel(true),
       show_relative_offset_changes(true),
@@ -1844,14 +1846,26 @@ parse_command_line(int argc, char* argv[], options& opts)
       if (argv[i][0] != '-')
         {
           if (opts.package1.empty())
-            opts.package1 = abigail::tools_utils::make_path_absolute(argv[i]).get();
+            {
+              opts.package1 = abigail::tools_utils::make_path_absolute(argv[i]).get();
+              opts.nonexistent_file = !file_exists(opts.package1);
+            }
           else if (opts.package2.empty())
-            opts.package2 = abigail::tools_utils::make_path_absolute(argv[i]).get();
+            {
+              opts.package2 = abigail::tools_utils::make_path_absolute(argv[i]).get();
+              opts.nonexistent_file = !file_exists(opts.package2);
+            }
           else
 	    {
 	      opts.wrong_arg = argv[i];
 	      return false;
 	    }
+
+          if (opts.nonexistent_file)
+            {
+              opts.wrong_option = argv[i];
+              return true;
+            }
         }
       else if (!strcmp(argv[i], "--debug-info-pkg1")
 	       || !strcmp(argv[i], "--d1"))
@@ -1998,6 +2012,15 @@ main(int argc, char* argv[])
 	      | abigail::tools_utils::ABIDIFF_ERROR);
     }
 
+  if (opts.nonexistent_file)
+    {
+      emit_prefix("abipkgdiff", cerr)
+	<< "The input file " << opts.wrong_option << " doesn't exist\n"
+	"try the --help option for more information\n";
+      return (abigail::tools_utils::ABIDIFF_USAGE_ERROR
+	      | abigail::tools_utils::ABIDIFF_ERROR);
+    }
+
   if (opts.display_usage)
     {
       display_usage(argv[0], cout);
-- 
2.7.4


             reply	other threads:[~2016-12-12 15:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:00 Ondrej Oprala [this message]
2016-01-01  0:00 ` Dodji Seketeli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=812c4d76-7ee5-3cd9-a657-f1f9f30e1df1@gmail.com \
    --to=ondrej.oprala@gmail.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).