update.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * dpkg - main program for package management
  3. * update.c - options which update the `available' database
  4. *
  5. * Copyright (C) 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 <errno.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <fnmatch.h>
  27. #include <assert.h>
  28. #include <unistd.h>
  29. #include <dpkg.h>
  30. #include <dpkg-db.h>
  31. #include <myopt.h>
  32. #include "main.h"
  33. void updateavailable(const char *const *argv) {
  34. const char *sourcefile= argv[0];
  35. int count= 0;
  36. static struct varbuf vb;
  37. switch (cipaction->arg) {
  38. case act_avclear:
  39. if (sourcefile) badusage(_("--%s takes no arguments"),cipaction->olong);
  40. break;
  41. case act_avreplace: case act_avmerge:
  42. if (!sourcefile || argv[1])
  43. badusage(_("--%s needs exactly one Packages file argument"),cipaction->olong);
  44. break;
  45. default:
  46. internerr("bad cipaction->arg in updateavailable");
  47. }
  48. if (!f_noact) {
  49. if (access(admindir,W_OK)) {
  50. if (errno != EACCES)
  51. ohshite(_("unable to access dpkg status area for bulk available update"));
  52. else
  53. ohshit(_("bulk available update requires write access to dpkg status area"));
  54. }
  55. lockdatabase(admindir);
  56. }
  57. switch (cipaction->arg) {
  58. case act_avreplace:
  59. printf(_("Replacing available packages info, using %s.\n"),sourcefile);
  60. break;
  61. case act_avmerge:
  62. printf(_("Updating available packages info, using %s.\n"),sourcefile);
  63. break;
  64. case act_avclear:
  65. break;
  66. default:
  67. internerr("bad cipaction->arg in update available");
  68. }
  69. varbufaddstr(&vb,admindir);
  70. varbufaddstr(&vb,"/" AVAILFILE);
  71. varbufaddc(&vb,0);
  72. if (cipaction->arg == act_avmerge)
  73. parsedb(vb.buf, pdb_recordavailable|pdb_rejectstatus, 0,0,0);
  74. if (cipaction->arg != act_avclear)
  75. count+= parsedb(sourcefile, pdb_recordavailable|pdb_rejectstatus, 0,0,0);
  76. if (!f_noact) {
  77. writedb(vb.buf,1,0);
  78. unlockdatabase(admindir);
  79. }
  80. if (cipaction->arg != act_avclear)
  81. printf(_("Information about %d package(s) was updated.\n"),count);
  82. }
  83. void forgetold(const char *const *argv) {
  84. struct pkgiterator *it;
  85. struct pkginfo *pkg;
  86. enum pkgwant oldwant;
  87. if (*argv) badusage(_("--forget-old-unavail takes no arguments"));
  88. modstatdb_init(admindir, f_noact ? msdbrw_readonly : msdbrw_write);
  89. it= iterpkgstart();
  90. while ((pkg= iterpkgnext(it))) {
  91. debug(dbg_eachfile,"forgetold checking %s",pkg->name);
  92. if (informative(pkg,&pkg->available)) {
  93. debug(dbg_eachfile,"forgetold ... informative available");
  94. continue;
  95. }
  96. if (pkg->want != want_purge && pkg->want != want_deinstall) {
  97. debug(dbg_eachfile,"forgetold ... informative want");
  98. continue;
  99. }
  100. oldwant= pkg->want;
  101. pkg->want= want_unknown;
  102. if (informative(pkg,&pkg->installed)) {
  103. debug(dbg_eachfile,"forgetold ... informative installed");
  104. pkg->want= oldwant;
  105. continue;
  106. }
  107. debug(dbg_general,"forgetold forgetting %s",pkg->name);
  108. }
  109. iterpkgend(it);
  110. modstatdb_shutdown();
  111. }