update.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <assert.h>
  30. #include <unistd.h>
  31. #include <dpkg.h>
  32. #include <dpkg-db.h>
  33. #include <myopt.h>
  34. #include "main.h"
  35. void updateavailable(const char *const *argv) {
  36. const char *sourcefile= argv[0];
  37. int count= 0;
  38. static struct varbuf vb;
  39. switch (cipaction->arg) {
  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 || argv[1])
  45. badusage(_("--%s needs exactly one Packages file argument"),cipaction->olong);
  46. break;
  47. default:
  48. internerr("unknown action '%d'", cipaction->arg);
  49. }
  50. if (!f_noact) {
  51. if (access(admindir,W_OK)) {
  52. if (errno != EACCES)
  53. ohshite(_("unable to access dpkg status area for bulk available update"));
  54. else
  55. ohshit(_("bulk available update requires write access to dpkg status area"));
  56. }
  57. lockdatabase(admindir);
  58. }
  59. switch (cipaction->arg) {
  60. case act_avreplace:
  61. printf(_("Replacing available packages info, using %s.\n"),sourcefile);
  62. break;
  63. case act_avmerge:
  64. printf(_("Updating available packages info, using %s.\n"),sourcefile);
  65. break;
  66. case act_avclear:
  67. break;
  68. default:
  69. internerr("unknown action '%d'", cipaction->arg);
  70. }
  71. varbufaddstr(&vb,admindir);
  72. varbufaddstr(&vb,"/" AVAILFILE);
  73. varbufaddc(&vb,0);
  74. if (cipaction->arg == act_avmerge)
  75. parsedb(vb.buf, pdb_recordavailable | pdb_rejectstatus, NULL, NULL, NULL);
  76. if (cipaction->arg != act_avclear)
  77. count += parsedb(sourcefile, pdb_recordavailable | pdb_rejectstatus,
  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. struct pkgiterator *it;
  88. struct pkginfo *pkg;
  89. enum pkgwant oldwant;
  90. if (*argv) badusage(_("--forget-old-unavail takes no arguments"));
  91. modstatdb_init(admindir, f_noact ? msdbrw_readonly : msdbrw_write);
  92. it= iterpkgstart();
  93. while ((pkg= iterpkgnext(it))) {
  94. debug(dbg_eachfile,"forgetold checking %s",pkg->name);
  95. if (informative(pkg,&pkg->available)) {
  96. debug(dbg_eachfile,"forgetold ... informative available");
  97. continue;
  98. }
  99. if (pkg->want != want_purge && pkg->want != want_deinstall) {
  100. debug(dbg_eachfile,"forgetold ... informative want");
  101. continue;
  102. }
  103. oldwant= pkg->want;
  104. pkg->want= want_unknown;
  105. if (informative(pkg,&pkg->installed)) {
  106. debug(dbg_eachfile,"forgetold ... informative installed");
  107. pkg->want= oldwant;
  108. continue;
  109. }
  110. debug(dbg_general,"forgetold forgetting %s",pkg->name);
  111. }
  112. iterpkgend(it);
  113. modstatdb_shutdown();
  114. }