filesdb-hash.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * dpkg - main program for package management
  3. * filesdb-hash.c - management of database of files installed on system
  4. *
  5. * Copyright © 2012 Guillem Jover <guillem@debian.org>
  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 <string.h>
  23. #include <stdio.h>
  24. #include <dpkg/dpkg.h>
  25. #include <dpkg/dpkg-db.h>
  26. #include <dpkg/debug.h>
  27. #include <dpkg/dir.h>
  28. #include "filesdb.h"
  29. #include "infodb.h"
  30. /*
  31. * If mask is nonzero, will not write any file whose filenamenode
  32. * has any flag bits set in mask.
  33. */
  34. void
  35. write_filehash_except(struct pkginfo *pkg, struct pkgbin *pkgbin,
  36. struct fileinlist *list, enum fnnflags mask)
  37. {
  38. struct atomic_file *file;
  39. const char *hashfile;
  40. debug(dbg_general, "generating infodb hashfile");
  41. if (pkg_infodb_has_file(pkg, &pkg->available, HASHFILE))
  42. return;
  43. hashfile = pkg_infodb_get_file(pkg, pkgbin, HASHFILE);
  44. file = atomic_file_new(hashfile, 0);
  45. atomic_file_open(file);
  46. for (; list; list = list->next) {
  47. struct filenamenode *namenode = list->namenode;
  48. if (mask && (namenode->flags & mask))
  49. continue;
  50. if (strcmp(namenode->newhash, EMPTYHASHFLAG) == 0)
  51. continue;
  52. fprintf(file->fp, "%s %s\n", namenode->newhash, namenode->name + 1);
  53. }
  54. atomic_file_sync(file);
  55. atomic_file_close(file);
  56. atomic_file_commit(file);
  57. atomic_file_free(file);
  58. dir_sync_path(pkg_infodb_get_dir());
  59. }