| 1 |
/*
|
| 2 |
* packages.c
|
| 3 |
*
|
| 4 |
* Copyright (C) 2003 Bastian Blank <waldi@debian.org>
|
| 5 |
*
|
| 6 |
* This program is free software; you can redistribute it and/or modify
|
| 7 |
* it under the terms of the GNU General Public License as published by
|
| 8 |
* the Free Software Foundation; either version 2 of the License, or
|
| 9 |
* (at your option) any later version.
|
| 10 |
*
|
| 11 |
* This program is distributed in the hope that it will be useful,
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
* GNU General Public License for more details.
|
| 15 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with this program; if not, write to the Free Software
|
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 19 |
*
|
| 20 |
* $Id: packages.c,v 1.14 2004/03/15 10:12:37 waldi Exp $
|
| 21 |
*/
|
| 22 |
|
| 23 |
#include <config.h>
|
| 24 |
|
| 25 |
#include <debian-installer/system/packages.h>
|
| 26 |
|
| 27 |
#include <debian-installer/package_internal.h>
|
| 28 |
#include <debian-installer/packages_internal.h>
|
| 29 |
#include <debian-installer/parser_rfc822.h>
|
| 30 |
#include <debian-installer/slist_internal.h>
|
| 31 |
|
| 32 |
#include <ctype.h>
|
| 33 |
#include <sys/utsname.h>
|
| 34 |
|
| 35 |
const di_parser_fieldinfo
|
| 36 |
internal_di_system_package_parser_field_installer_menu_item =
|
| 37 |
DI_PARSER_FIELDINFO (
|
| 38 |
"Installer-Menu-Item",
|
| 39 |
di_parser_read_int,
|
| 40 |
di_parser_write_int,
|
| 41 |
offsetof (di_system_package, installer_menu_item)
|
| 42 |
),
|
| 43 |
internal_di_system_package_parser_field_subarchitecture =
|
| 44 |
DI_PARSER_FIELDINFO (
|
| 45 |
"Subarchitecture",
|
| 46 |
di_parser_read_string,
|
| 47 |
di_parser_write_string,
|
| 48 |
offsetof (di_system_package, subarchitecture)
|
| 49 |
),
|
| 50 |
internal_di_system_package_parser_field_kernel_version =
|
| 51 |
DI_PARSER_FIELDINFO (
|
| 52 |
"Kernel-Version",
|
| 53 |
di_parser_read_string,
|
| 54 |
di_parser_write_string,
|
| 55 |
offsetof (di_system_package, kernel_version)
|
| 56 |
);
|
| 57 |
|
| 58 |
const di_parser_fieldinfo *di_system_package_parser_fieldinfo[] =
|
| 59 |
{
|
| 60 |
&internal_di_system_package_parser_field_installer_menu_item,
|
| 61 |
&internal_di_system_package_parser_field_subarchitecture,
|
| 62 |
&internal_di_system_package_parser_field_kernel_version,
|
| 63 |
NULL
|
| 64 |
};
|
| 65 |
|
| 66 |
static void internal_di_system_package_destroy_func (void *data)
|
| 67 |
{
|
| 68 |
di_system_package_destroy (data);
|
| 69 |
}
|
| 70 |
|
| 71 |
void di_system_package_destroy (di_system_package *package)
|
| 72 |
{
|
| 73 |
di_free (package->subarchitecture);
|
| 74 |
|
| 75 |
di_package_destroy (&package->p);
|
| 76 |
}
|
| 77 |
|
| 78 |
di_packages_allocator *di_system_packages_allocator_alloc (void)
|
| 79 |
{
|
| 80 |
di_packages_allocator *ret;
|
| 81 |
|
| 82 |
ret = internal_di_packages_allocator_alloc ();
|
| 83 |
ret->package_mem_chunk = di_mem_chunk_new (sizeof (di_system_package), 16384);
|
| 84 |
|
| 85 |
return ret;
|
| 86 |
}
|
| 87 |
|
| 88 |
di_packages *di_system_packages_alloc (void)
|
| 89 |
{
|
| 90 |
di_packages *ret;
|
| 91 |
|
| 92 |
ret = di_new0 (di_packages, 1);
|
| 93 |
ret->table = di_hash_table_new_full (di_rstring_hash, di_rstring_equal, NULL, internal_di_system_package_destroy_func);
|
| 94 |
|
| 95 |
return ret;
|
| 96 |
}
|
| 97 |
|
| 98 |
bool di_system_package_check_subarchitecture (di_package *package, const char *subarchitecture)
|
| 99 |
{
|
| 100 |
char *string, *begin, *end, *temp;
|
| 101 |
int ret = false;
|
| 102 |
|
| 103 |
if (!((di_system_package *) package)->subarchitecture)
|
| 104 |
return true;
|
| 105 |
|
| 106 |
string = begin = strdup (((di_system_package *) package)->subarchitecture);
|
| 107 |
end = begin + strlen (begin);
|
| 108 |
|
| 109 |
while (begin < end)
|
| 110 |
{
|
| 111 |
while (begin < end && isspace (*begin))
|
| 112 |
begin++;
|
| 113 |
temp = begin;
|
| 114 |
while (temp < end && !isspace (*++temp));
|
| 115 |
*temp = '\0';
|
| 116 |
|
| 117 |
if (!strcmp (begin, subarchitecture))
|
| 118 |
{
|
| 119 |
ret = true;
|
| 120 |
goto cleanup;
|
| 121 |
}
|
| 122 |
begin = temp + 1;
|
| 123 |
}
|
| 124 |
|
| 125 |
cleanup:
|
| 126 |
free (string);
|
| 127 |
|
| 128 |
return ret;
|
| 129 |
}
|
| 130 |
|
| 131 |
di_parser_info *di_system_package_parser_info (void)
|
| 132 |
{
|
| 133 |
di_parser_info *info;
|
| 134 |
|
| 135 |
info = di_package_parser_info ();
|
| 136 |
di_parser_info_add (info, di_system_package_parser_fieldinfo);
|
| 137 |
|
| 138 |
return info;
|
| 139 |
}
|
| 140 |
|
| 141 |
di_parser_info *di_system_packages_parser_info (void)
|
| 142 |
{
|
| 143 |
di_parser_info *info;
|
| 144 |
|
| 145 |
info = di_packages_parser_info ();
|
| 146 |
di_parser_info_add (info, di_system_package_parser_fieldinfo);
|
| 147 |
|
| 148 |
return info;
|
| 149 |
}
|
| 150 |
|
| 151 |
di_parser_info *di_system_packages_status_parser_info (void)
|
| 152 |
{
|
| 153 |
di_parser_info *info;
|
| 154 |
|
| 155 |
info = di_packages_status_parser_info ();
|
| 156 |
di_parser_info_add (info, di_system_package_parser_fieldinfo);
|
| 157 |
|
| 158 |
return info;
|
| 159 |
}
|
| 160 |
|
| 161 |
di_slist *di_system_packages_resolve_dependencies_array_permissive (di_packages *packages, di_package **array, di_packages_allocator *allocator)
|
| 162 |
{
|
| 163 |
struct di_packages_resolve_dependencies_check s =
|
| 164 |
{
|
| 165 |
di_packages_resolve_dependencies_check_real,
|
| 166 |
di_packages_resolve_dependencies_check_virtual,
|
| 167 |
di_packages_resolve_dependencies_check_non_existant_permissive,
|
| 168 |
{ NULL, NULL },
|
| 169 |
allocator,
|
| 170 |
0
|
| 171 |
};
|
| 172 |
|
| 173 |
return di_packages_resolve_dependencies_array_special (packages, array, &s);
|
| 174 |
}
|
| 175 |
|
| 176 |
static di_package *check_virtual_kernel (di_package *package __attribute__ ((unused)), di_package *best, di_package_dependency *d)
|
| 177 |
{
|
| 178 |
struct utsname uts;
|
| 179 |
if (uname(&uts) == 0)
|
| 180 |
if (((di_system_package *)d->ptr)->kernel_version &&
|
| 181 |
strcmp (((di_system_package *)d->ptr)->kernel_version, uts.release))
|
| 182 |
return best;
|
| 183 |
return di_packages_resolve_dependencies_check_virtual (package, best, d);
|
| 184 |
}
|
| 185 |
|
| 186 |
void di_system_packages_resolve_dependencies_mark_kernel (di_packages *packages)
|
| 187 |
{
|
| 188 |
struct di_packages_resolve_dependencies_check s =
|
| 189 |
{
|
| 190 |
di_packages_resolve_dependencies_check_real,
|
| 191 |
check_virtual_kernel,
|
| 192 |
di_packages_resolve_dependencies_check_non_existant,
|
| 193 |
{ NULL, NULL },
|
| 194 |
NULL,
|
| 195 |
0
|
| 196 |
};
|
| 197 |
|
| 198 |
return di_packages_resolve_dependencies_mark_special (packages, &s);
|
| 199 |
}
|
| 200 |
|