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

dpkg: Add support for loading Packages-files from pipes or stdin

This allows loading Packages files in --update-avail and --merge-avail
from pipes, or stdin if the argument is omitted or is ‘-’.

Closes: #357093, #367297
Guillem Jover лет назад: 12
Родитель
Сommit
97f282bc09
4 измененных файлов с 21 добавлено и 8 удалено
  1. 3 0
      debian/changelog
  2. 9 3
      man/dpkg.1
  3. 2 2
      src/main.c
  4. 7 3
      src/update.c

+ 3 - 0
debian/changelog

@@ -79,6 +79,9 @@ dpkg (1.17.7) UNRELEASED; urgency=low
     - Test command_exec() exit code.
     - Test allocations with new test_alloc() instead of pass/fail macros.
     - Switch C test suite to use TAP.
+  * Add support for Packages-files in dpkg --update-avail and --merge-avail
+    from pipes, or standard input if the argument is omitted or is ‘-’.
+    Closes: #357093, #367297
 
   [ Updated dpkg translations ]
   * German (Sven Joachim).

+ 9 - 3
man/dpkg.1

@@ -214,14 +214,16 @@ option, which by default uses the \fBrpm\fP format, but that might
 change in the future, and as such programs parsing this command
 output should be explicit about the format they expect.
 .TP
-\fB\-\-update\-avail\fP, \fB\-\-merge\-avail\fP \fIPackages-file\fP
+\fB\-\-update\-avail\fP, \fB\-\-merge\-avail\fP [\fIPackages-file\fP]
 Update \fBdpkg\fP's and \fBdselect\fP's idea of which packages are
 available. With action \fB\-\-merge\-avail\fP, old information is
 combined with information from \fIPackages-file\fP. With action
 \fB\-\-update\-avail\fP, old information is replaced with the information
 in the \fIPackages-file\fP. The \fIPackages-file\fP distributed with
-Debian is simply named \fIPackages\fP. \fBdpkg\fP keeps its
-record of available packages in \fI/var/lib/dpkg/available\fP.
+Debian is simply named \fIPackages\fP. If the \fIPackages-file\fP
+argument is missing or named \fB-\fP then it will be read from
+standard input (since dpkg 1.17.7). \fBdpkg\fP keeps its record of
+available packages in \fI/var/lib/dpkg/available\fP.
 
 A simpler one-shot command to retrieve and update the \fIavailable\fR
 file is \fBdselect update\fR. Note that this file is mostly useless
@@ -832,6 +834,10 @@ You might transfer this file to another computer, and after having updated
 the \fIavailable\fP file there with your package manager frontend of choice
 (see https://wiki.debian.org/Teams/Dpkg/FAQ for more details), for example:
 .br
+\fB     apt\-cache dumpavail | dpkg \-\-merge\-avail\fP
+.br
+or with dpkg 1.17.6 and earlier:
+.br
 \fB     avail=`mktemp`\fP
 \fB     apt\-cache dumpavail >"$avail"\fP
 \fB     dpkg \-\-merge\-avail "$avail"\fP

+ 2 - 2
src/main.c

@@ -95,8 +95,8 @@ usage(const struct cmdinfo *ci, const char *value)
 "  --get-selections [<pattern> ...] Get list of selections to stdout.\n"
 "  --set-selections                 Set package selections from stdin.\n"
 "  --clear-selections               Deselect every non-essential package.\n"
-"  --update-avail <Packages-file>   Replace available packages info.\n"
-"  --merge-avail <Packages-file>    Merge with info from file.\n"
+"  --update-avail [<Packages-file>] Replace available packages info.\n"
+"  --merge-avail [<Packages-file>]  Merge with info from file.\n"
 "  --clear-avail                    Erase existing available info.\n"
 "  --forget-old-unavail             Forget uninstalled unavailable pkgs.\n"
 "  -s|--status <package> ...        Display package status details.\n"

+ 7 - 3
src/update.c

@@ -48,8 +48,10 @@ updateavailable(const char *const *argv)
     if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
     break;
   case act_avreplace: case act_avmerge:
-    if (!sourcefile || argv[1])
-      badusage(_("--%s needs exactly one Packages-file argument"),
+    if (sourcefile == NULL)
+      sourcefile = "-";
+    else if (sourcefile && argv[1])
+      badusage(_("--%s takes at most one Packages-file argument"),
                cipaction->olong);
     break;
   default:
@@ -85,7 +87,9 @@ updateavailable(const char *const *argv)
     parsedb(availfile, pdb_parse_available, NULL);
 
   if (cipaction->arg_int != act_avclear)
-    count += parsedb(sourcefile, pdb_parse_available | pdb_ignoreolder, NULL);
+    count += parsedb(sourcefile,
+                     pdb_parse_available | pdb_ignoreolder | pdb_dash_is_stdin,
+                     NULL);
 
   if (!f_noact) {
     writedb(availfile, wdb_dump_available);