[dpkg] 61/200: dpkg: Add new --validate-<thing> commands

Ximin Luo infinity0 at debian.org
Wed Apr 5 15:17:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository dpkg.

commit 4801f159330b344148e777071d50ebc02c0d9056
Author: Guillem Jover <guillem at debian.org>
Date:   Sun Dec 4 22:51:24 2016 +0100

    dpkg: Add new --validate-<thing> commands
    
    These commands make it possible to test if several of those <thing>s
    have a valid syntax. The current list of supported things is «pkgname»,
    «trigname», «archname» and «version».
---
 debian/changelog |  3 +++
 man/dpkg.man     | 23 ++++++++++++++++++-
 src/enquiry.c    | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/main.c       | 11 +++++++++-
 src/main.h       | 11 +++++++++-
 5 files changed, 111 insertions(+), 4 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index b10957d..a05bfdb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,9 @@ dpkg (1.18.16) UNRELEASED; urgency=medium
     needed on 32-bit architectures with many cores, which results in more
     than the userspace addressable memory, when using settings such as
     -z9 and/or -Sextreme in dpkg-deb. Closes: #846564
+  * Add new dpkg --validate-<thing> commands to validate the syntax of
+    various <thing>s, where the current list is «pkgname», «trigname»,
+    «archname» and «version».
   * Perl modules:
     - Whitelist DPKG_GENSYMBOLS_CHECK_LEVEL, DPKG_ROOT, DPKG_ADMINDIR and
       DPKG_DATADIR environment variables in Dpkg::Build::Info.
diff --git a/man/dpkg.man b/man/dpkg.man
index abdaf0f..6c8a75c 100644
--- a/man/dpkg.man
+++ b/man/dpkg.man
@@ -6,7 +6,7 @@
 .\" Copyright © 2000-2003 Adam Heath <doogie at debian.org>
 .\" Copyright © 2002 Josip Rodin
 .\" Copyright © 2004-2005 Scott James Remnant <keybuk at debian.org>
-.\" Copyright © 2006-2015 Guillem Jover <guillem at debian.org>
+.\" Copyright © 2006-2016 Guillem Jover <guillem at debian.org>
 .\" Copyright © 2007-2008 Ian Jackson <ijackson at chiark.greenend.org.uk>
 .\" Copyright © 2008-2011 Raphaël Hertzog <hertzog at debian.org>
 .\"
@@ -374,6 +374,27 @@ Supports multi-arch fields and semantics (since dpkg 1.16.2).
 Supports versioned \fBProvides\fP (since dpkg 1.17.11).
 .RE
 .TP
+.BI \-\-validate\- "thing string"
+Validate that the \fIthing\fP \fIstring\fP has a correct syntaxa
+(since dpkg 1.18.16).
+Returns 0 if the \fIstring\fP is valid, 1 if the \fIstring\fP is invalid but
+might be accepted in lax contexts, and 2 if the \fIstring\fP is invalid.
+The current list of validatable \fIthing\fPs is:
+.RS
+.TP
+.B pkgname
+Validates the given package name (since dpkg 1.18.16).
+.TP
+.B trigname
+Validates the given trigger name (since dpkg 1.18.16).
+.TP
+.B pkgname
+Validates the given architecture name (since dpkg 1.18.16).
+.TP
+.B version
+Validates the given version (since dpkg 1.18.16).
+.RE
+.TP
 .B \-\-compare\-versions \fIver1 op ver2\fP
 Compare version numbers, where \fIop\fP is a binary operator. \fBdpkg\fP
 returns true (\fB0\fP) if the specified condition is satisfied,
diff --git a/src/enquiry.c b/src/enquiry.c
index f3f92c4..b299f84 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -3,7 +3,7 @@
  * enquiry.c - status enquiry and listing options
  *
  * Copyright © 1995,1996 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2006, 2008-2015 Guillem Jover <guillem at debian.org>
+ * Copyright © 2006, 2008-2016 Guillem Jover <guillem at debian.org>
  * Copyright © 2011 Linaro Limited
  * Copyright © 2011 Raphaël Hertzog <hertzog at debian.org>
  *
@@ -40,6 +40,7 @@
 #include <dpkg/arch.h>
 #include <dpkg/pkg-array.h>
 #include <dpkg/pkg-show.h>
+#include <dpkg/triglib.h>
 #include <dpkg/string.h>
 #include <dpkg/options.h>
 
@@ -597,6 +598,70 @@ print_foreign_arches(const char *const *argv)
 }
 
 int
+validate_pkgname(const char *const *argv)
+{
+  const char *emsg;
+
+  if (!argv[0] || argv[1])
+    badusage(_("--%s takes one <pkgname> argument"), cipaction->olong);
+
+  emsg = pkg_name_is_illegal(argv[0]);
+  if (emsg)
+    ohshit(_("package name '%s' is invalid: %s"), argv[0], emsg);
+
+  return 0;
+}
+
+int
+validate_trigname(const char *const *argv)
+{
+  const char *emsg;
+
+  if (!argv[0] || argv[1])
+    badusage(_("--%s takes one <trigname> argument"), cipaction->olong);
+
+  emsg = trig_name_is_illegal(argv[0]);
+  if (emsg)
+    ohshit(_("trigger name '%s' is invalid: %s"), argv[0], emsg);
+
+  return 0;
+}
+
+int
+validate_archname(const char *const *argv)
+{
+  const char *emsg;
+
+  if (!argv[0] || argv[1])
+    badusage(_("--%s takes one <archname> argument"), cipaction->olong);
+
+  emsg = dpkg_arch_name_is_illegal(argv[0]);
+  if (emsg)
+    ohshit(_("architecture name '%s' is invalid: %s"), argv[0], emsg);
+
+  return 0;
+}
+
+int
+validate_version(const char *const *argv)
+{
+  struct dpkg_version version;
+  struct dpkg_error err;
+
+  if (!argv[0] || argv[1])
+    badusage(_("--%s takes one <version> argument"), cipaction->olong);
+
+  if (parseversion(&version, argv[0], &err) < 0) {
+    dpkg_error_print(&err, _("version '%s' has bad syntax"), argv[0]);
+    dpkg_error_destroy(&err);
+
+    return 1;
+  }
+
+  return 0;
+}
+
+int
 cmpversions(const char *const *argv)
 {
   struct relationinfo {
diff --git a/src/main.c b/src/main.c
index 5452f21..fb97d6f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3,7 +3,7 @@
  * main.c - main program
  *
  * Copyright © 1994,1995 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2006-2015 Guillem Jover <guillem at debian.org>
+ * Copyright © 2006-2016 Guillem Jover <guillem at debian.org>
  * Copyright © 2010 Canonical Ltd.
  *   written by Martin Pitt <martin.pitt at canonical.com>
  *
@@ -111,6 +111,7 @@ usage(const struct cmdinfo *ci, const char *value)
 "  --print-architecture             Print dpkg architecture.\n"
 "  --print-foreign-architectures    Print allowed foreign architectures.\n"
 "  --assert-<feature>               Assert support for the specified feature.\n"
+"  --validate-<thing> <string>      Validate a <thing>'s <string>.\n"
 "  --compare-versions <a> <op> <b>  Compare version numbers - see below.\n"
 "  --force-help                     Show help on forcing.\n"
 "  -Dh|--debug=help                 Show help on debugging.\n"
@@ -127,6 +128,10 @@ usage(const struct cmdinfo *ci, const char *value)
 "\n"));
 
   printf(_(
+"Validatable things: pkgname, archname, trigname, version.\n"
+"\n"));
+
+  printf(_(
 "Use dpkg with -b, --build, -c, --contents, -e, --control, -I, --info,\n"
 "  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfile\n"
 "on archives (type %s --help).\n"
@@ -704,6 +709,10 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "print-architecture",              0,  act_printarch,            printarch   ),
   ACTION( "print-foreign-architectures",     0,  act_printforeignarches,   print_foreign_arches ),
   ACTION( "predep-package",                  0,  act_predeppackage,        predeppackage   ),
+  ACTION( "validate-pkgname",                0,  act_validate_pkgname,     validate_pkgname ),
+  ACTION( "validate-trigname",               0,  act_validate_trigname,    validate_trigname ),
+  ACTION( "validate-archname",               0,  act_validate_archname,    validate_archname ),
+  ACTION( "validate-version",                0,  act_validate_version,     validate_version ),
   ACTION( "compare-versions",                0,  act_cmpversions,          cmpversions     ),
 /*
   ACTION( "command-fd",                   'c', act_commandfd,   commandfd     ),
diff --git a/src/main.h b/src/main.h
index fc083a9..1600abc 100644
--- a/src/main.h
+++ b/src/main.h
@@ -3,7 +3,7 @@
  * main.h - external definitions for this program
  *
  * Copyright © 1995 Ian Jackson <ijackson at chiark.greenend.org.uk>
- * Copyright © 2006, 2008-2015 Guillem Jover <guillem at debian.org>
+ * Copyright © 2006, 2008-2016 Guillem Jover <guillem at debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -110,6 +110,11 @@ enum action {
 	act_assertmultiarch,
 	act_assertverprovides,
 
+	act_validate_pkgname,
+	act_validate_trigname,
+	act_validate_archname,
+	act_validate_version,
+
 	act_audit,
 	act_unpackchk,
 	act_predeppackage,
@@ -177,6 +182,10 @@ int assertlongfilenames(const char *const *argv);
 int assertmulticonrep(const char *const *argv);
 int assertmultiarch(const char *const *argv);
 int assertverprovides(const char *const *argv);
+int validate_pkgname(const char *const *argv);
+int validate_trigname(const char *const *argv);
+int validate_archname(const char *const *argv);
+int validate_version(const char *const *argv);
 int predeppackage(const char *const *argv);
 int printarch(const char *const *argv);
 int printinstarch(const char *const *argv);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list