Initial stab at untangling the #include maze. Probably needs a second pass.
[oweals/opkg-lede.git] / libopkg / pkg_dest.c
1 /* pkg_dest.c - the opkg package management system
2
3    Carl D. Worth
4
5    Copyright (C) 2001 University of Southern California
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program 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 GNU
15    General Public License for more details.
16 */
17
18 #include <stdio.h>
19
20 #include "pkg_dest.h"
21 #include "file_util.h"
22 #include "sprintf_alloc.h"
23 #include "opkg_conf.h"
24 #include "opkg_cmd.h"
25 #include "opkg_defines.h"
26 #include "libbb/libbb.h"
27
28 int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
29 {
30     dest->name = xstrdup(name);
31
32     /* Guarantee that dest->root_dir ends with a '/' */
33     if (root_dir[strlen(root_dir) -1] == '/') {
34         dest->root_dir = xstrdup(root_dir);
35     } else {
36         sprintf_alloc(&dest->root_dir, "%s/", root_dir);
37     }
38     file_mkdir_hier(dest->root_dir, 0755);
39
40     sprintf_alloc(&dest->opkg_dir, "%s%s",
41                   dest->root_dir, OPKG_STATE_DIR_PREFIX);
42     file_mkdir_hier(dest->opkg_dir, 0755);
43
44     if (lists_dir[0] == '/')
45         sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
46     else
47         sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
48
49     file_mkdir_hier(dest->lists_dir, 0755);
50
51     sprintf_alloc(&dest->info_dir, "%s/%s",
52                   dest->opkg_dir, OPKG_INFO_DIR_SUFFIX);
53     file_mkdir_hier(dest->info_dir, 0755);
54
55     sprintf_alloc(&dest->status_file_name, "%s/%s",
56                   dest->opkg_dir, OPKG_STATUS_FILE_SUFFIX);
57
58     return 0;
59 }
60
61 void pkg_dest_deinit(pkg_dest_t *dest)
62 {
63     free(dest->name);
64     dest->name = NULL;
65
66     free(dest->root_dir);
67     dest->root_dir = NULL;
68
69     free(dest->opkg_dir);
70     dest->opkg_dir = NULL;
71
72     free(dest->lists_dir);
73     dest->lists_dir = NULL;
74
75     free(dest->info_dir);
76     dest->info_dir = NULL;
77
78     free(dest->status_file_name);
79     dest->status_file_name = NULL;
80
81     dest->root_dir = NULL;
82 }