mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-16 10:50:43 +03:00
Refactor ostree_sysroot_query_bootloader
This is more regular, so will make it easier to add more bootloader types in the future.
This commit is contained in:
parent
31acd2ef99
commit
a8dce46b5f
@ -1325,6 +1325,31 @@ ostree_sysroot_repo (OstreeSysroot *self)
|
||||
return self->repo;
|
||||
}
|
||||
|
||||
static OstreeBootloader*
|
||||
_ostree_sysroot_new_bootloader_by_type (
|
||||
OstreeSysroot *sysroot,
|
||||
OstreeCfgSysrootBootloaderOpt bl_type)
|
||||
{
|
||||
switch (bl_type)
|
||||
{
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_NONE:
|
||||
/* No bootloader specified; do not query bootloaders to run. */
|
||||
return NULL;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_GRUB2:
|
||||
return (OstreeBootloader*) _ostree_bootloader_grub2_new (sysroot);
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX:
|
||||
return (OstreeBootloader*) _ostree_bootloader_syslinux_new (sysroot);
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_UBOOT:
|
||||
return (OstreeBootloader*) _ostree_bootloader_uboot_new (sysroot);
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_ZIPL:
|
||||
/* We never consider zipl as active by default, so it can only be created
|
||||
* if it's explicitly requested in the config */
|
||||
return (OstreeBootloader*) _ostree_bootloader_zipl_new (sysroot);
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ostree_sysroot_query_bootloader:
|
||||
* @sysroot: Sysroot
|
||||
@ -1346,58 +1371,31 @@ _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||
CFG_SYSROOT_BOOTLOADER_OPTS_STR[bootloader_config]);
|
||||
|
||||
g_autoptr(OstreeBootloader) ret_loader = NULL;
|
||||
switch (repo->bootloader)
|
||||
if (bootloader_config == CFG_SYSROOT_BOOTLOADER_OPT_AUTO)
|
||||
{
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_NONE:
|
||||
/* No bootloader specified; do not query bootloaders to run. */
|
||||
ret_loader = NULL;
|
||||
break;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_GRUB2:
|
||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_grub2_new (sysroot);
|
||||
break;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX:
|
||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_syslinux_new (sysroot);
|
||||
break;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_UBOOT:
|
||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_uboot_new (sysroot);
|
||||
break;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_ZIPL:
|
||||
/* We never consider zipl as active by default, so it can only be created
|
||||
* if it's explicitly requested in the config */
|
||||
ret_loader = (OstreeBootloader*) _ostree_bootloader_zipl_new (sysroot);
|
||||
break;
|
||||
case CFG_SYSROOT_BOOTLOADER_OPT_AUTO:
|
||||
{
|
||||
gboolean is_active;
|
||||
ret_loader = (OstreeBootloader*)_ostree_bootloader_syslinux_new (sysroot);
|
||||
if (!_ostree_bootloader_query (ret_loader, &is_active,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (!is_active)
|
||||
{
|
||||
g_object_unref (ret_loader);
|
||||
ret_loader = (OstreeBootloader*)_ostree_bootloader_grub2_new (sysroot);
|
||||
if (!_ostree_bootloader_query (ret_loader, &is_active,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
if (!is_active)
|
||||
{
|
||||
g_object_unref (ret_loader);
|
||||
ret_loader = (OstreeBootloader*)_ostree_bootloader_uboot_new (sysroot);
|
||||
if (!_ostree_bootloader_query (ret_loader, &is_active, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
if (!is_active)
|
||||
g_clear_object (&ret_loader);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
OstreeCfgSysrootBootloaderOpt probe[] = {
|
||||
CFG_SYSROOT_BOOTLOADER_OPT_SYSLINUX,
|
||||
CFG_SYSROOT_BOOTLOADER_OPT_GRUB2,
|
||||
CFG_SYSROOT_BOOTLOADER_OPT_UBOOT,
|
||||
};
|
||||
for (int i = 0; i < G_N_ELEMENTS (probe); i++)
|
||||
{
|
||||
g_autoptr(OstreeBootloader) bl = _ostree_sysroot_new_bootloader_by_type (
|
||||
sysroot, probe[i]);
|
||||
gboolean is_active = FALSE;
|
||||
if (!_ostree_bootloader_query (bl, &is_active, cancellable, error))
|
||||
return FALSE;
|
||||
if (is_active)
|
||||
{
|
||||
ret_loader = g_steal_pointer (&bl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
ret_loader = _ostree_sysroot_new_bootloader_by_type (sysroot, bootloader_config);
|
||||
|
||||
ot_transfer_out_value(out_bootloader, &ret_loader);
|
||||
ot_transfer_out_value (out_bootloader, &ret_loader)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user