update.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * dpkg - main program for package management
  3. * update.c - options which update the ‘available’ database
  4. *
  5. * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <unistd.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <dpkg/i18n.h>
  28. #include <dpkg/dpkg.h>
  29. #include <dpkg/dpkg-db.h>
  30. #include <dpkg/options.h>
  31. #include "main.h"
  32. int
  33. updateavailable(const char *const *argv)
  34. {
  35. const char *sourcefile= argv[0];
  36. char *availfile;
  37. int count= 0;
  38. modstatdb_init();
  39. switch (cipaction->arg_int) {
  40. case act_avclear:
  41. if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
  42. break;
  43. case act_avreplace: case act_avmerge:
  44. if (sourcefile == NULL)
  45. sourcefile = "-";
  46. else if (sourcefile && argv[1])
  47. badusage(_("--%s takes at most one Packages-file argument"),
  48. cipaction->olong);
  49. break;
  50. default:
  51. internerr("unknown action '%d'", cipaction->arg_int);
  52. }
  53. if (!f_noact) {
  54. if (access(dpkg_db_get_dir(), W_OK)) {
  55. if (errno != EACCES)
  56. ohshite(_("unable to access dpkg status area for bulk available update"));
  57. else
  58. ohshit(_("bulk available update requires write access to dpkg status area"));
  59. }
  60. modstatdb_lock();
  61. }
  62. switch (cipaction->arg_int) {
  63. case act_avreplace:
  64. printf(_("Replacing available packages info, using %s.\n"),sourcefile);
  65. break;
  66. case act_avmerge:
  67. printf(_("Updating available packages info, using %s.\n"),sourcefile);
  68. break;
  69. case act_avclear:
  70. break;
  71. default:
  72. internerr("unknown action '%d'", cipaction->arg_int);
  73. }
  74. availfile = dpkg_db_get_path(AVAILFILE);
  75. if (cipaction->arg_int == act_avmerge)
  76. parsedb(availfile, pdb_parse_available, NULL);
  77. if (cipaction->arg_int != act_avclear)
  78. count += parsedb(sourcefile,
  79. pdb_parse_available | pdb_ignoreolder | pdb_dash_is_stdin,
  80. NULL);
  81. if (!f_noact) {
  82. writedb(availfile, wdb_dump_available);
  83. modstatdb_unlock();
  84. }
  85. free(availfile);
  86. if (cipaction->arg_int != act_avclear)
  87. printf(P_("Information about %d package was updated.\n",
  88. "Information about %d packages was updated.\n", count), count);
  89. modstatdb_done();
  90. return 0;
  91. }
  92. int
  93. forgetold(const char *const *argv)
  94. {
  95. if (*argv)
  96. badusage(_("--%s takes no arguments"), cipaction->olong);
  97. warning(_("obsolete '--%s' option; unavailable packages are automatically cleaned up"),
  98. cipaction->olong);
  99. return 0;
  100. }