1 /* pkg_dest.c - the opkg package management system
5 Copyright (C) 2001 University of Southern California
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.
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.
21 #include "file_util.h"
23 #include "sprintf_alloc.h"
24 #include "opkg_state.h"
25 #include "opkg_defines.h"
27 int pkg_dest_init(pkg_dest_t *dest, const char *name, const char *root_dir,const char * lists_dir)
29 dest->name = strdup(name);
31 /* Guarantee that dest->root_dir ends with a '/' */
32 if (str_ends_with(root_dir, "/")) {
33 dest->root_dir = strdup(root_dir);
35 sprintf_alloc(&dest->root_dir, "%s/", root_dir);
37 file_mkdir_hier(dest->root_dir, 0755);
39 sprintf_alloc(&dest->opkg_dir, "%s%s",
40 dest->root_dir, OPKG_STATE_DIR_PREFIX);
41 file_mkdir_hier(dest->opkg_dir, 0755);
43 if (str_starts_with (lists_dir, "/"))
44 sprintf_alloc(&dest->lists_dir, "%s", lists_dir);
46 sprintf_alloc(&dest->lists_dir, "/%s", lists_dir);
48 file_mkdir_hier(dest->lists_dir, 0755);
50 sprintf_alloc(&dest->info_dir, "%s/%s",
51 dest->opkg_dir, OPKG_INFO_DIR_SUFFIX);
52 file_mkdir_hier(dest->info_dir, 0755);
54 sprintf_alloc(&dest->status_file_name, "%s/%s",
55 dest->opkg_dir, OPKG_STATUS_FILE_SUFFIX);
57 sprintf_alloc(&dest->status_file_tmp_name, "%s/%s.tmp",
58 dest->opkg_dir, OPKG_STATUS_FILE_SUFFIX);
60 dest->status_file = NULL;
65 void pkg_dest_deinit(pkg_dest_t *dest)
71 dest->root_dir = NULL;
74 dest->opkg_dir = NULL;
76 free(dest->lists_dir);
77 dest->lists_dir = NULL;
80 dest->info_dir = NULL;
82 free(dest->status_file_name);
83 dest->status_file_name = NULL;
85 free(dest->status_file_tmp_name);
86 dest->status_file_tmp_name = NULL;
88 if (dest->status_file) {
89 fclose(dest->status_file);
91 dest->status_file = NULL;
93 dest->root_dir = NULL;