pkg_extract.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* pkg_extract.c - the opkg package management system
  2. Carl D. Worth
  3. Copyright (C) 2001 University of Southern California
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. */
  13. #include <stdio.h>
  14. #include "pkg_extract.h"
  15. #include "libbb/libbb.h"
  16. #include "file_util.h"
  17. #include "sprintf_alloc.h"
  18. int pkg_extract_control_file_to_stream(pkg_t * pkg, FILE * stream)
  19. {
  20. int err;
  21. deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stream,
  22. extract_control_tar_gz
  23. | extract_to_stream, NULL, "control", &err);
  24. return err;
  25. }
  26. int
  27. pkg_extract_control_files_to_dir_with_prefix(pkg_t * pkg, const char *dir,
  28. const char *prefix)
  29. {
  30. int err;
  31. char *dir_with_prefix;
  32. sprintf_alloc(&dir_with_prefix, "%s/%s", dir, prefix);
  33. deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stderr,
  34. extract_control_tar_gz
  35. | extract_all_to_fs | extract_preserve_date
  36. | extract_unconditional, dir_with_prefix, NULL, &err);
  37. free(dir_with_prefix);
  38. return err;
  39. }
  40. int pkg_extract_control_files_to_dir(pkg_t * pkg, const char *dir)
  41. {
  42. return pkg_extract_control_files_to_dir_with_prefix(pkg, dir, "");
  43. }
  44. int pkg_extract_data_files_to_dir(pkg_t * pkg, const char *dir)
  45. {
  46. int err;
  47. deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stderr,
  48. extract_data_tar_gz
  49. | extract_all_to_fs | extract_preserve_date
  50. | extract_unconditional, dir, NULL, &err);
  51. return err;
  52. }
  53. int pkg_extract_data_file_names_to_stream(pkg_t * pkg, FILE * stream)
  54. {
  55. int err;
  56. /* XXX: DPKG_INCOMPATIBILITY: deb_extract will extract all of the
  57. data file names with a '.' as the first character. I've taught
  58. opkg how to cope with the presence or absence of the '.', but
  59. this may trip up dpkg.
  60. For all I know, this could actually be a bug in opkg-build. So,
  61. I'll have to try installing some .debs and comparing the *.list
  62. files.
  63. If we wanted to, we could workaround the deb_extract behavior
  64. right here, by writing to a tmpfile, then munging things as we
  65. wrote to the actual stream. */
  66. deb_extract(pkg_get_string(pkg, PKG_LOCAL_FILENAME), stream,
  67. extract_quiet | extract_data_tar_gz | extract_list,
  68. NULL, NULL, &err);
  69. return err;
  70. }