1 /* opkg_conf.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.
19 #include "opkg_conf.h"
20 #include "opkg_error.h"
23 #include "sprintf_alloc.h"
25 #include "opkg_message.h"
26 #include "file_util.h"
30 #include "opkg_defines.h"
32 #include <sys/types.h>
37 extern char *conf_file_dir;
39 static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
40 pkg_src_list_t *pkg_src_list,
41 nv_pair_list_t *tmp_dest_nv_pair_list,
42 char **tmp_lists_dir);
43 static int opkg_conf_set_option(const opkg_option_t *options,
44 const char *name, const char *value);
45 static int opkg_conf_set_default_dest(opkg_conf_t *conf,
46 const char *default_dest_name);
47 static int set_and_load_pkg_src_list(opkg_conf_t *conf,
48 pkg_src_list_t *nv_pair_list);
49 static int set_and_load_pkg_dest_list(opkg_conf_t *conf,
50 nv_pair_list_t *nv_pair_list, char * lists_dir);
52 int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options)
54 opkg_option_t tmp[] = {
55 { "cache", OPKG_OPT_TYPE_STRING, &conf->cache},
56 { "force_defaults", OPKG_OPT_TYPE_BOOL, &conf->force_defaults },
57 { "force_maintainer", OPKG_OPT_TYPE_BOOL, &conf->force_maintainer },
58 { "force_depends", OPKG_OPT_TYPE_BOOL, &conf->force_depends },
59 { "force_overwrite", OPKG_OPT_TYPE_BOOL, &conf->force_overwrite },
60 { "force_downgrade", OPKG_OPT_TYPE_BOOL, &conf->force_downgrade },
61 { "force_reinstall", OPKG_OPT_TYPE_BOOL, &conf->force_reinstall },
62 { "force_space", OPKG_OPT_TYPE_BOOL, &conf->force_space },
63 { "check_signature", OPKG_OPT_TYPE_INT, &conf->check_signature },
64 { "ftp_proxy", OPKG_OPT_TYPE_STRING, &conf->ftp_proxy },
65 { "http_proxy", OPKG_OPT_TYPE_STRING, &conf->http_proxy },
66 { "no_proxy", OPKG_OPT_TYPE_STRING, &conf->no_proxy },
67 { "test", OPKG_OPT_TYPE_INT, &conf->noaction },
68 { "noaction", OPKG_OPT_TYPE_INT, &conf->noaction },
69 { "nodeps", OPKG_OPT_TYPE_BOOL, &conf->nodeps },
70 { "offline_root", OPKG_OPT_TYPE_STRING, &conf->offline_root },
71 { "offline_root_path", OPKG_OPT_TYPE_STRING, &conf->offline_root_path },
72 { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd },
73 { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd },
74 { "proxy_passwd", OPKG_OPT_TYPE_STRING, &conf->proxy_passwd },
75 { "proxy_user", OPKG_OPT_TYPE_STRING, &conf->proxy_user },
76 { "query-all", OPKG_OPT_TYPE_BOOL, &conf->query_all },
77 { "verbosity", OPKG_OPT_TYPE_BOOL, &conf->verbosity },
78 #if defined(HAVE_OPENSSL)
79 { "signature_ca_file", OPKG_OPT_TYPE_STRING, &conf->signature_ca_file },
80 { "signature_ca_path", OPKG_OPT_TYPE_STRING, &conf->signature_ca_path },
82 #if defined(HAVE_SSLCURL) && defined(HAVE_CURL)
83 { "ssl_engine", OPKG_OPT_TYPE_STRING, &conf->ssl_engine },
84 { "ssl_cert", OPKG_OPT_TYPE_STRING, &conf->ssl_cert },
85 { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &conf->ssl_cert_type },
86 { "ssl_key", OPKG_OPT_TYPE_STRING, &conf->ssl_key },
87 { "ssl_key_type", OPKG_OPT_TYPE_STRING, &conf->ssl_key_type },
88 { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &conf->ssl_key_passwd },
89 { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_file },
90 { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_path },
91 { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &conf->ssl_dont_verify_peer },
96 *options = (opkg_option_t *)calloc(1, sizeof(tmp));
97 if ( options == NULL ){
98 fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__);
102 memcpy(*options, tmp, sizeof(tmp));
106 static void opkg_conf_override_string(char **conf_str, char *arg_str)
112 *conf_str = strdup(arg_str);
116 static void opkg_conf_free_string(char **conf_str)
124 int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
129 nv_pair_list_t tmp_dest_nv_pair_list;
130 char *lists_dir = NULL, *lock_file = NULL;
132 char *etc_opkg_conf_pattern;
133 char *pending_dir = NULL;
135 memset(conf, 0, sizeof(opkg_conf_t));
137 pkg_src_list_init(&conf->pkg_src_list);
139 nv_pair_list_init(&tmp_dest_nv_pair_list);
140 pkg_dest_list_init(&conf->pkg_dest_list);
142 nv_pair_list_init(&conf->arch_list);
144 conf->restrict_to_default_dest = 0;
145 conf->default_dest = NULL;
147 /* check for lock file */
148 if (args->offline_root)
149 sprintf_alloc (&lock_file, "%s/%s/lock", args->offline_root, OPKG_STATE_DIR_PREFIX);
151 sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX);
153 conf->lock_fd = creat (lock_file, S_IRUSR | S_IWUSR | S_IRGRP);
154 err = lockf (conf->lock_fd, F_TLOCK, 0);
161 if(args->offline_root) {
162 opkg_message (conf, OPKG_ERROR, "Could not obtain administrative lock for offline root (ERR: %s) at %s/%s/lock\n",
163 strerror(errno_copy), args->offline_root, OPKG_STATE_DIR_PREFIX);
165 opkg_message (conf, OPKG_ERROR, "Could not obtain administrative lock (ERR: %s) at %s/lock\n",
166 strerror(errno_copy), OPKG_STATE_DIR_PREFIX);
168 return OPKG_CONF_ERR_LOCK;
172 tmp_dir_base = args->tmp_dir;
174 tmp_dir_base = getenv("TMPDIR");
175 sprintf_alloc(&conf->tmp_dir, "%s/%s",
176 tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE,
177 OPKG_CONF_TMP_DIR_SUFFIX);
178 conf->tmp_dir = mkdtemp(conf->tmp_dir);
179 if (conf->tmp_dir == NULL) {
180 fprintf(stderr, "%s: Failed to create temporary directory `%s': %s\n",
181 __FUNCTION__, conf->tmp_dir, strerror(errno));
182 return OPKG_CONF_ERR_TMP_DIR;
185 pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN);
186 hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
187 hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN);
188 lists_dir=(char *)malloc(1);
190 if (args->conf_file) {
191 struct stat stat_buf;
192 err = stat(args->conf_file, &stat_buf);
194 if (opkg_conf_parse_file(conf, args->conf_file,
195 &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
196 /* Memory leakage from opkg_conf_parse-file */
197 return OPKG_CONF_ERR_PARSE;
201 if (strlen(lists_dir)<=1 ){
202 lists_dir = realloc(lists_dir,strlen(OPKG_CONF_LISTS_DIR)+2);
203 sprintf (lists_dir,"%s",OPKG_CONF_LISTS_DIR);
206 if (args->offline_root) {
208 sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
213 pending_dir = calloc(1, strlen(lists_dir)+strlen("/pending")+5);
214 snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending");
216 conf->lists_dir = strdup(lists_dir);
217 conf->pending_dir = strdup(pending_dir);
219 if (args->offline_root)
220 sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", args->offline_root);
222 sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir);
223 memset(&globbuf, 0, sizeof(globbuf));
224 err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf);
225 free (etc_opkg_conf_pattern);
228 for (i = 0; i < globbuf.gl_pathc; i++) {
229 if (globbuf.gl_pathv[i])
230 if ( opkg_conf_parse_file(conf, globbuf.gl_pathv[i],
231 &conf->pkg_src_list, &tmp_dest_nv_pair_list,&lists_dir)<0) {
232 /* Memory leakage from opkg_conf_parse-file */
233 return OPKG_CONF_ERR_PARSE;
239 /* if no architectures were defined, then default all, noarch, and host architecture */
240 if (nv_pair_list_empty(&conf->arch_list)) {
241 nv_pair_list_append(&conf->arch_list, "all", "1");
242 nv_pair_list_append(&conf->arch_list, "noarch", "1");
243 nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10");
246 /* Even if there is no conf file, we'll need at least one dest. */
247 if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) {
248 nv_pair_list_append(&tmp_dest_nv_pair_list,
249 OPKG_CONF_DEFAULT_DEST_NAME,
250 OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
253 /* After parsing the file, set options from command-line, (so that
254 command-line arguments take precedence) */
255 /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c
256 really needs to be cleaned up. There is so much duplication
257 right now it is ridiculous. Maybe opkg_conf_t should just save
258 a pointer to args_t (which could then not be freed), rather
259 than duplicating every field here? */
260 if (args->autoremove) {
261 conf->autoremove = 1;
263 if (args->force_depends) {
264 conf->force_depends = 1;
266 if (args->force_defaults) {
267 conf->force_defaults = 1;
269 if (args->force_maintainer) {
270 conf->force_maintainer = 1;
272 if (args->force_overwrite) {
273 conf->force_overwrite = 1;
275 if (args->force_downgrade) {
276 conf->force_downgrade = 1;
278 if (args->force_space) {
279 conf->force_space = 1;
281 if (args->force_reinstall) {
282 conf->force_reinstall = 1;
284 if (args->force_removal_of_dependent_packages) {
285 conf->force_removal_of_dependent_packages = 1;
287 if (args->force_removal_of_essential_packages) {
288 conf->force_removal_of_essential_packages = 1;
293 if (args->noaction) {
296 if (args->query_all) {
299 if (args->verbosity != conf->verbosity) {
300 conf->verbosity = args->verbosity;
303 opkg_conf_override_string(&conf->offline_root,
305 opkg_conf_override_string(&conf->offline_root_path,
306 args->offline_root_path);
307 opkg_conf_override_string(&conf->offline_root_pre_script_cmd,
308 args->offline_root_pre_script_cmd);
309 opkg_conf_override_string(&conf->offline_root_post_script_cmd,
310 args->offline_root_post_script_cmd);
312 opkg_conf_override_string(&conf->cache, args->cache);
314 /* Pigi: added a flag to disable the checking of structures if the command does not need to
315 read anything from there.
317 if ( !(args->nocheckfordirorfile)){
318 /* need to run load the source list before dest list -Jamey */
319 if ( !(args->noreadfeedsfile))
320 set_and_load_pkg_src_list(conf, &conf->pkg_src_list);
322 /* Now that we have resolved conf->offline_root, we can commit to
323 the directory names for the dests and load in all the package
325 set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list,lists_dir);
328 err = opkg_conf_set_default_dest(conf, args->dest);
330 return OPKG_CONF_ERR_DEFAULT_DEST;
334 nv_pair_list_deinit(&tmp_dest_nv_pair_list);
341 void opkg_conf_deinit(opkg_conf_t *conf)
343 #ifdef OPKG_DEBUG_NO_TMP_CLEANUP
345 fprintf(stderr, "%s: Not cleaning up %s since opkg compiled "
346 "with OPKG_DEBUG_NO_TMP_CLEANUP\n",
347 __FUNCTION__, conf->tmp_dir);
351 err = rmdir(conf->tmp_dir);
353 if (errno == ENOTEMPTY) {
355 sprintf_alloc(&cmd, "rm -fr %s\n", conf->tmp_dir);
360 fprintf(stderr, "WARNING: Unable to remove temporary directory: %s: %s\n", conf->tmp_dir, strerror(errno));
362 #endif /* OPKG_DEBUG_NO_TMP_CLEANUP */
364 free(conf->tmp_dir); /*XXX*/
365 free(conf->lists_dir);
366 free(conf->pending_dir);
368 pkg_src_list_deinit(&conf->pkg_src_list);
369 pkg_dest_list_deinit(&conf->pkg_dest_list);
370 nv_pair_list_deinit(&conf->arch_list);
372 pkg_hash_deinit(&conf->pkg_hash);
373 if (&conf->file_hash)
374 hash_table_deinit(&conf->file_hash);
375 if (&conf->obs_file_hash)
376 hash_table_deinit(&conf->obs_file_hash);
378 opkg_conf_free_string(&conf->offline_root);
379 opkg_conf_free_string(&conf->offline_root_path);
380 opkg_conf_free_string(&conf->offline_root_pre_script_cmd);
381 opkg_conf_free_string(&conf->offline_root_post_script_cmd);
383 opkg_conf_free_string(&conf->cache);
385 #if defined(HAVE_OPENSSL)
386 opkg_conf_free_string(&conf->signature_ca_file);
387 opkg_conf_free_string(&conf->signature_ca_path);
390 #if defined(HAVE_SSLCURL)
391 opkg_conf_free_string(&conf->ssl_engine);
392 opkg_conf_free_string(&conf->ssl_cert);
393 opkg_conf_free_string(&conf->ssl_cert_type);
394 opkg_conf_free_string(&conf->ssl_key);
395 opkg_conf_free_string(&conf->ssl_key_type);
396 opkg_conf_free_string(&conf->ssl_key_passwd);
397 opkg_conf_free_string(&conf->ssl_ca_file);
398 opkg_conf_free_string(&conf->ssl_ca_path);
401 if (conf->verbosity > 1) {
403 hash_table_t *hashes[] = {
406 &conf->obs_file_hash };
407 for (i = 0; i < 3; i++) {
408 hash_table_t *hash = hashes[i];
412 for (j = 0; j < hash->n_entries; j++) {
414 hash_entry_t *e = &hash->entries[j];
417 while (e && e->key) {
424 opkg_message(conf, OPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
425 hash->name, hash->n_entries, hash->n_elements, c, n_conflicts);
426 hash_table_deinit(hash);
431 static int opkg_conf_set_default_dest(opkg_conf_t *conf,
432 const char *default_dest_name)
434 pkg_dest_list_elt_t *iter;
437 for (iter = void_list_first(&conf->pkg_dest_list); iter; iter = void_list_next(&conf->pkg_dest_list, iter)) {
438 dest = (pkg_dest_t *)iter->data;
439 if (strcmp(dest->name, default_dest_name) == 0) {
440 conf->default_dest = dest;
441 conf->restrict_to_default_dest = 1;
446 fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name);
451 static int set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list)
453 pkg_src_list_elt_t *iter;
457 for (iter = void_list_first(pkg_src_list); iter; iter = void_list_next(pkg_src_list, iter)) {
458 src = (pkg_src_t *)iter->data;
463 sprintf_alloc(&list_file, "%s/%s",
464 conf->restrict_to_default_dest ? conf->default_dest->lists_dir : conf->lists_dir,
467 if (file_exists(list_file)) {
468 pkg_hash_add_from_file(conf, list_file, src, NULL, 0);
476 static int set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char *lists_dir )
478 nv_pair_list_elt_t *iter;
483 for (iter = nv_pair_list_first(nv_pair_list); iter; iter = nv_pair_list_next(nv_pair_list, iter)) {
484 nv_pair = (nv_pair_t *)iter->data;
486 if (conf->offline_root) {
487 sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
489 root_dir = strdup(nv_pair->value);
491 dest = pkg_dest_list_append(&conf->pkg_dest_list, nv_pair->name, root_dir, lists_dir);
496 if (conf->default_dest == NULL) {
497 conf->default_dest = dest;
499 if (file_exists(dest->status_file_name)) {
500 pkg_hash_add_from_file(conf, dest->status_file_name,
508 static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
509 pkg_src_list_t *pkg_src_list,
510 nv_pair_list_t *tmp_dest_nv_pair_list,
514 opkg_option_t * options;
515 FILE *file = fopen(filename, "r");
516 regex_t valid_line_re, comment_re;
517 #define regmatch_size 12
518 regmatch_t regmatch[regmatch_size];
520 if (opkg_init_options_array(conf, &options)<0)
524 fprintf(stderr, "%s: failed to open %s: %s\n",
525 __FUNCTION__, filename, strerror(errno));
529 opkg_message(conf, OPKG_NOTICE, "loading conf file %s\n", filename);
531 err = xregcomp(&comment_re,
532 "^[[:space:]]*(#.*|[[:space:]]*)$",
538 err = xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED);
547 char *type, *name, *value, *extra;
549 line = file_read_line_alloc(file);
557 if (regexec(&comment_re, line, 0, 0, 0) == 0) {
561 if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) {
563 fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n",
564 filename, line_num, line);
568 /* This has to be so ugly to deal with optional quotation marks */
569 if (regmatch[2].rm_so > 0) {
570 type = strndup(line + regmatch[2].rm_so,
571 regmatch[2].rm_eo - regmatch[2].rm_so);
573 type = strndup(line + regmatch[3].rm_so,
574 regmatch[3].rm_eo - regmatch[3].rm_so);
576 if (regmatch[5].rm_so > 0) {
577 name = strndup(line + regmatch[5].rm_so,
578 regmatch[5].rm_eo - regmatch[5].rm_so);
580 name = strndup(line + regmatch[6].rm_so,
581 regmatch[6].rm_eo - regmatch[6].rm_so);
583 if (regmatch[8].rm_so > 0) {
584 value = strndup(line + regmatch[8].rm_so,
585 regmatch[8].rm_eo - regmatch[8].rm_so);
587 value = strndup(line + regmatch[9].rm_so,
588 regmatch[9].rm_eo - regmatch[9].rm_so);
591 if (regmatch[11].rm_so > 0) {
592 extra = strndup (line + regmatch[11].rm_so,
593 regmatch[11].rm_eo - regmatch[11].rm_so);
596 /* We use the tmp_dest_nv_pair_list below instead of
597 conf->pkg_dest_list because we might encounter an
598 offline_root option later and that would invalidate the
599 directories we would have computed in
600 pkg_dest_list_init. (We do a similar thing with
601 tmp_src_nv_pair_list for sake of symmetry.) */
602 if (strcmp(type, "option") == 0) {
603 opkg_conf_set_option(options, name, value);
604 } else if (strcmp(type, "src") == 0) {
605 if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
606 pkg_src_list_append (pkg_src_list, name, value, extra, 0);
608 opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
611 } else if (strcmp(type, "src/gz") == 0) {
612 if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) {
613 pkg_src_list_append (pkg_src_list, name, value, extra, 1);
615 opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
618 } else if (strcmp(type, "dest") == 0) {
619 nv_pair_list_append(tmp_dest_nv_pair_list, name, value);
620 } else if (strcmp(type, "lists_dir") == 0) {
621 *lists_dir = realloc(*lists_dir,strlen(value)+1);
622 if (*lists_dir == NULL) {
623 opkg_message(conf, OPKG_ERROR, "ERROR: Not enough memory\n");
627 sprintf (*lists_dir,"%s",value);
628 } else if (strcmp(type, "arch") == 0) {
629 opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);
631 opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
632 value = strdup("10");
634 nv_pair_list_append(&conf->arch_list, name, value);
636 fprintf(stderr, "WARNING: Ignoring unknown configuration "
637 "parameter: %s %s %s\n", type, name, value);
653 regfree(&comment_re);
654 regfree(&valid_line_re);
660 static int opkg_conf_set_option(const opkg_option_t *options,
661 const char *name, const char *value)
664 while (options[i].name) {
665 if (strcmp(options[i].name, name) == 0) {
666 switch (options[i].type) {
667 case OPKG_OPT_TYPE_BOOL:
668 *((int *)options[i].value) = 1;
670 case OPKG_OPT_TYPE_INT:
672 *((int *)options[i].value) = atoi(value);
675 printf("%s: Option %s need an argument\n",
679 case OPKG_OPT_TYPE_STRING:
681 *((char **)options[i].value) = strdup(value);
684 printf("%s: Option %s need an argument\n",
693 fprintf(stderr, "%s: Unrecognized option: %s=%s\n",
694 __FUNCTION__, name, value);
698 int opkg_conf_write_status_files(opkg_conf_t *conf)
705 FILE * status_file=NULL;
710 dest = (pkg_dest_t *)void_list_first(&conf->pkg_dest_list)->data;
711 status_file = fopen(dest->status_file_tmp_name, "w");
712 if (status_file == NULL) {
713 fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
714 __FUNCTION__, dest->status_file_tmp_name, strerror(errno));
717 all = pkg_vec_alloc();
718 pkg_hash_fetch_available(&conf->pkg_hash, all);
720 for(i = 0; i < all->len; i++) {
722 /* We don't need most uninstalled packages in the status file */
723 if (pkg->state_status == SS_NOT_INSTALLED
724 && (pkg->state_want == SW_UNKNOWN
725 || pkg->state_want == SW_DEINSTALL
726 || pkg->state_want == SW_PURGE)) {
729 if (pkg->dest == NULL) {
730 fprintf(stderr, "%s: ERROR: Can't write status for "
731 "package %s since it has a NULL dest\n",
732 __FUNCTION__, pkg->name);
736 pkg_print_status(pkg, status_file);
743 err = ferror(status_file);
746 file_move(dest->status_file_tmp_name, dest->status_file_name);
748 fprintf(stderr, "%s: ERROR: An error has occurred writing %s, "
749 "retaining old %s\n", __FUNCTION__,
750 dest->status_file_tmp_name, dest->status_file_name);
758 char *root_filename_alloc(opkg_conf_t *conf, char *filename)
761 sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename);
762 return root_filename;