pkg_dest.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* pkg_dest.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_dest.h"
  15. #include "file_util.h"
  16. #include "sprintf_alloc.h"
  17. #include "opkg_conf.h"
  18. #include "opkg_cmd.h"
  19. #include "opkg_defines.h"
  20. #include "libbb/libbb.h"
  21. int pkg_dest_init(pkg_dest_t * dest, const char *name, const char *root_dir,
  22. const char *lists_dir)
  23. {
  24. dest->name = xstrdup(name);
  25. /* Guarantee that dest->root_dir ends with a '/' */
  26. if (root_dir[strlen(root_dir) - 1] == '/') {
  27. dest->root_dir = xstrdup(root_dir);
  28. } else {
  29. sprintf_alloc(&dest->root_dir, "%s/", root_dir);
  30. }
  31. file_mkdir_hier(dest->root_dir, 0755);
  32. sprintf_alloc(&dest->opkg_dir, "%s%s",
  33. dest->root_dir, OPKG_STATE_DIR_PREFIX);
  34. file_mkdir_hier(dest->opkg_dir, 0755);
  35. if (lists_dir[0] == '/')
  36. sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
  37. else
  38. sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
  39. file_mkdir_hier(dest->lists_dir, 0755);
  40. sprintf_alloc(&dest->info_dir, "%s/%s",
  41. dest->opkg_dir, OPKG_INFO_DIR_SUFFIX);
  42. file_mkdir_hier(dest->info_dir, 0755);
  43. sprintf_alloc(&dest->status_file_name, "%s/%s",
  44. dest->opkg_dir, OPKG_STATUS_FILE_SUFFIX);
  45. return 0;
  46. }
  47. void pkg_dest_deinit(pkg_dest_t * dest)
  48. {
  49. free(dest->name);
  50. dest->name = NULL;
  51. free(dest->root_dir);
  52. dest->root_dir = NULL;
  53. free(dest->opkg_dir);
  54. dest->opkg_dir = NULL;
  55. free(dest->lists_dir);
  56. dest->lists_dir = NULL;
  57. free(dest->info_dir);
  58. dest->info_dir = NULL;
  59. free(dest->status_file_name);
  60. dest->status_file_name = NULL;
  61. dest->root_dir = NULL;
  62. }