update.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * dpkg - main program for package management
  3. * update.c - options which update the `available' database
  4. *
  5. * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.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 <stdio.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <fnmatch.h>
  25. #include <assert.h>
  26. #include <unistd.h>
  27. #include "config.h"
  28. #include "dpkg.h"
  29. #include "dpkg-db.h"
  30. #include "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("bad cipaction->arg in updateavailable");
  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. lockdatabase(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("bad cipaction->arg in update available");
  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, 0,0,0);
  73. if (cipaction->arg != act_avclear)
  74. count+= parsedb(sourcefile, pdb_recordavailable|pdb_rejectstatus, 0,0,0);
  75. if (!f_noact) {
  76. writedb(vb.buf,1,0);
  77. unlockdatabase(admindir);
  78. }
  79. if (cipaction->arg != act_avclear)
  80. printf("Information about %d package(s) was updated.\n",count);
  81. }
  82. void forgetold(const char *const *argv) {
  83. struct pkgiterator *it;
  84. struct pkginfo *pkg;
  85. enum pkgwant oldwant;
  86. if (*argv) badusage("--forget-old-unavail takes no arguments");
  87. modstatdb_init(admindir, f_noact ? msdbrw_readonly : msdbrw_write);
  88. it= iterpkgstart();
  89. while ((pkg= iterpkgnext(it))) {
  90. debug(dbg_eachfile,"forgetold checking %s",pkg->name);
  91. if (informative(pkg,&pkg->available)) {
  92. debug(dbg_eachfile,"forgetold ... informative available");
  93. continue;
  94. }
  95. if (pkg->want != want_purge && pkg->want != want_deinstall) {
  96. debug(dbg_eachfile,"forgetold ... informative want");
  97. continue;
  98. }
  99. oldwant= pkg->want;
  100. pkg->want= want_unknown;
  101. if (informative(pkg,&pkg->installed)) {
  102. debug(dbg_eachfile,"forgetold ... informative installed");
  103. pkg->want= oldwant;
  104. continue;
  105. }
  106. debug(dbg_general,"forgetold forgetting %s",pkg->name);
  107. }
  108. iterpkgend(it);
  109. modstatdb_shutdown();
  110. }