Просмотр исходного кода

dpkg: Warn on obsolete '<' and '>' operators in --compare-versions

These have very confusing semantics, and for the same reason that they
should be avoided in package control data, they should be avoided on
the command-line. Emit a warning for unsuspecting users that might get
trapped by these operators.
Guillem Jover лет назад: 11
Родитель
Сommit
ed4ce62868
2 измененных файлов с 8 добавлено и 2 удалено
  1. 1 0
      debian/changelog
  2. 7 2
      src/enquiry.c

+ 1 - 0
debian/changelog

@@ -58,6 +58,7 @@ dpkg (1.18.0) UNRELEASED; urgency=low
       symbol is available.
   * Use strftime() instead of «date -R» in dpkg-genchanges, as the latter
     is not specified by POSIX and is not widely portable.
+  * Warn on obsolete '<' and '>' operators in dpkg --compare-versions.
 
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).

+ 7 - 2
src/enquiry.c

@@ -612,6 +612,7 @@ cmpversions(const char *const *argv)
     /* These values are exit status codes, so 0 = true, 1 = false. */
     int if_lesser, if_equal, if_greater;
     int if_none_a, if_none_both, if_none_b;
+    bool obsolete;
   };
 
   static const struct relationinfo relationinfos[]= {
@@ -630,11 +631,11 @@ cmpversions(const char *const *argv)
     { "gt-nl",     1,1,0, 0,1,1  },
 
     /* For compatibility with dpkg control file syntax. */
-    { "<",         0,0,1, 0,0,1  },
+    { "<",         0,0,1, 0,0,1, .obsolete = true },
     { "<=",        0,0,1, 0,0,1  },
     { "<<",        0,1,1, 0,1,1  },
     { "=",         1,0,1, 1,0,1  },
-    { ">",         1,0,0, 1,0,0  },
+    { ">",         1,0,0, 1,0,0, .obsolete = true },
     { ">=",        1,0,0, 1,0,0  },
     { ">>",        1,1,0, 1,1,0  },
     { NULL                       }
@@ -653,6 +654,10 @@ cmpversions(const char *const *argv)
 
   if (!rip->string) badusage(_("--compare-versions bad relation"));
 
+  if (rip->obsolete)
+    warning(_("--%s used with obsolete relation operator '%s'"),
+            cipaction->olong, rip->string);
+
   if (*argv[0] && strcmp(argv[0],"<unknown>")) {
     if (parseversion(&a, argv[0], &err) < 0) {
       if (err.type == DPKG_MSG_WARN)