update.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * dpkg - main program for package management
  3. * update.c - options which update the ‘available’ database
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@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 <http://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/myopt.h>
  31. #include "main.h"
  32. void updateavailable(const char *const *argv) {
  33. const char *sourcefile= argv[0];
  34. int count= 0;
  35. static struct varbuf vb;
  36. switch (cipaction->arg) {
  37. case act_avclear:
  38. if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
  39. break;
  40. case act_avreplace: case act_avmerge:
  41. if (!sourcefile || argv[1])
  42. badusage(_("--%s needs exactly one Packages file argument"),cipaction->olong);
  43. break;
  44. default:
  45. internerr("unknown action '%d'", cipaction->arg);
  46. }
  47. if (!f_noact) {
  48. if (access(admindir,W_OK)) {
  49. if (errno != EACCES)
  50. ohshite(_("unable to access dpkg status area for bulk available update"));
  51. else
  52. ohshit(_("bulk available update requires write access to dpkg status area"));
  53. }
  54. modstatdb_lock(admindir);
  55. }
  56. switch (cipaction->arg) {
  57. case act_avreplace:
  58. printf(_("Replacing available packages info, using %s.\n"),sourcefile);
  59. break;
  60. case act_avmerge:
  61. printf(_("Updating available packages info, using %s.\n"),sourcefile);
  62. break;
  63. case act_avclear:
  64. break;
  65. default:
  66. internerr("unknown action '%d'", cipaction->arg);
  67. }
  68. varbufaddstr(&vb,admindir);
  69. varbufaddstr(&vb,"/" AVAILFILE);
  70. varbufaddc(&vb,0);
  71. if (cipaction->arg == act_avmerge)
  72. parsedb(vb.buf, pdb_recordavailable | pdb_rejectstatus | pdb_lax_parser,
  73. NULL, NULL);
  74. if (cipaction->arg != act_avclear)
  75. count += parsedb(sourcefile,
  76. pdb_recordavailable | pdb_rejectstatus | pdb_ignoreolder,
  77. NULL, NULL);
  78. if (!f_noact) {
  79. writedb(vb.buf,1,0);
  80. modstatdb_unlock();
  81. }
  82. if (cipaction->arg != act_avclear)
  83. printf(P_("Information about %d package was updated.\n",
  84. "Information about %d packages was updated.\n", count), count);
  85. }
  86. void forgetold(const char *const *argv) {
  87. if (*argv)
  88. badusage(_("--%s takes no arguments"), cipaction->olong);
  89. warning(_("obsolete '--%s' option, unavailable packages are automatically cleaned up."),
  90. cipaction->olong);
  91. }