Move loading of feeds and status files out of opkg_conf_init().
[oweals/opkg-lede.git] / libopkg / libopkg.c
1 /* opkglib.c - the opkg package management system
2
3    Florian Boor
4
5    Copyright (C) 2003 kernel concepts
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 "includes.h"
19 #include "libopkg.h"
20
21 #include "args.h"
22 #include "opkg_conf.h"
23 #include "opkg_cmd.h"
24 #include "file_util.h"
25
26 #include "opkg_message.h"
27
28 /* This is used for backward compatibility */
29 int
30 opkg_op (int argc, char *argv[])
31 {
32         int err, opts;
33         args_t args;
34         char *cmd_name;
35         opkg_cmd_t *cmd;
36         int nocheckfordirorfile = 0;
37         int noreadfeedsfile = 0;
38
39         args_init (&args);
40
41         opts = args_parse (&args, argc, argv);
42         if (opts == argc || opts < 0)
43         {
44                 args_usage ("opkg must have one sub-command argument");
45         }
46
47         cmd_name = argv[opts++];
48
49         if ( !strcmp(cmd_name,"print-architecture") ||
50              !strcmp(cmd_name,"print_architecture") ||
51              !strcmp(cmd_name,"print-installation-architecture") ||
52              !strcmp(cmd_name,"print_installation_architecture") )
53            nocheckfordirorfile = 1;
54
55         if ( !strcmp(cmd_name,"flag") ||
56              !strcmp(cmd_name,"configure") ||
57              !strcmp(cmd_name,"remove") ||
58              !strcmp(cmd_name,"files") ||
59              !strcmp(cmd_name,"search") ||
60              !strcmp(cmd_name,"compare_versions") ||
61              !strcmp(cmd_name,"compare-versions") ||
62              !strcmp(cmd_name,"list_installed") ||
63              !strcmp(cmd_name,"list-installed") ||
64              !strcmp(cmd_name,"status") )
65            noreadfeedsfile = 1;
66
67         cmd = opkg_cmd_find (cmd_name);
68         if (cmd == NULL)
69         {
70                 fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
71                          cmd_name);
72                 args_usage (NULL);
73         }
74
75         conf->pfm = cmd->pfm;
76
77         err = opkg_conf_init (&args);
78         args_deinit (&args);
79         if (err)
80                 goto err0;
81
82         if (!nocheckfordirorfile) {
83                 if (!noreadfeedsfile) {
84                         if ((err = pkg_hash_load_feeds()))
85                                 goto err1;
86                 }
87    
88                 if ((err = pkg_hash_load_status_files()))
89                         goto err1;
90         }
91
92         if (cmd->requires_args && opts == argc)
93         {
94                 fprintf (stderr,
95                          "%s: the ``%s'' command requires at least one argument\n",
96                          argv[0], cmd_name);
97                 args_usage (NULL);
98         }
99
100         err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts));
101
102
103 #ifdef HAVE_CURL
104         opkg_curl_cleanup();
105 #endif
106 err1:
107         opkg_conf_deinit ();
108
109 err0:
110         print_error_list();
111         free_error_list();
112
113         return err;
114 }