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
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * 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
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <dpkg/i18n.h>
  24. #include <errno.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <fnmatch.h>
  29. #include <unistd.h>
  30. #include <dpkg/dpkg.h>
  31. #include <dpkg/dpkg-db.h>
  32. #include <dpkg/myopt.h>
  33. #include "main.h"
  34. void updateavailable(const char *const *argv) {
  35. const char *sourcefile= argv[0];
  36. int count= 0;
  37. static struct varbuf vb;
  38. switch (cipaction->arg) {
  39. case act_avclear:
  40. if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
  41. break;
  42. case act_avreplace: case act_avmerge:
  43. if (!sourcefile || argv[1])
  44. badusage(_("--%s needs exactly one Packages file argument"),cipaction->olong);
  45. break;
  46. default:
  47. internerr("unknown action '%d'", cipaction->arg);
  48. }
  49. if (!f_noact) {
  50. if (access(admindir,W_OK)) {
  51. if (errno != EACCES)
  52. ohshite(_("unable to access dpkg status area for bulk available update"));
  53. else
  54. ohshit(_("bulk available update requires write access to dpkg status area"));
  55. }
  56. lockdatabase(admindir);
  57. }
  58. switch (cipaction->arg) {
  59. case act_avreplace:
  60. printf(_("Replacing available packages info, using %s.\n"),sourcefile);
  61. break;
  62. case act_avmerge:
  63. printf(_("Updating available packages info, using %s.\n"),sourcefile);
  64. break;
  65. case act_avclear:
  66. break;
  67. default:
  68. internerr("unknown action '%d'", cipaction->arg);
  69. }
  70. varbufaddstr(&vb,admindir);
  71. varbufaddstr(&vb,"/" AVAILFILE);
  72. varbufaddc(&vb,0);
  73. if (cipaction->arg == act_avmerge)
  74. parsedb(vb.buf, pdb_recordavailable | pdb_rejectstatus, NULL, NULL, NULL);
  75. if (cipaction->arg != act_avclear)
  76. count += parsedb(sourcefile,
  77. pdb_recordavailable | pdb_rejectstatus | pdb_ignoreolder,
  78. NULL, NULL, NULL);
  79. if (!f_noact) {
  80. writedb(vb.buf,1,0);
  81. unlockdatabase();
  82. }
  83. if (cipaction->arg != act_avclear)
  84. printf(_("Information about %d package(s) was updated.\n"),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. }