libostree: Move a lot more sysroot API here
OstreeBootloader is temporarily public API.
This commit is contained in:
parent
6f929ca5af
commit
95f07d486a
|
|
@ -26,4 +26,8 @@ libostree_public_headers = \
|
||||||
src/libostree/ostree-types.h \
|
src/libostree/ostree-types.h \
|
||||||
src/libostree/ostree-repo-file.h \
|
src/libostree/ostree-repo-file.h \
|
||||||
src/libostree/ostree-diff.h \
|
src/libostree/ostree-diff.h \
|
||||||
|
src/libostree/ostree-sysroot.h \
|
||||||
|
src/libostree/ostree-bootloader.h \
|
||||||
|
src/libostree/ostree-deployment.h \
|
||||||
|
src/libostree/ostree-bootconfig-parser.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,16 @@ libostree_1_la_SOURCES = \
|
||||||
src/libostree/ostree-repo-file.c \
|
src/libostree/ostree-repo-file.c \
|
||||||
src/libostree/ostree-repo-file-enumerator.c \
|
src/libostree/ostree-repo-file-enumerator.c \
|
||||||
src/libostree/ostree-repo-file-enumerator.h \
|
src/libostree/ostree-repo-file-enumerator.h \
|
||||||
|
src/libostree/ostree-sysroot-private.h \
|
||||||
src/libostree/ostree-sysroot.c \
|
src/libostree/ostree-sysroot.c \
|
||||||
src/libostree/ostree-sysroot.h \
|
src/libostree/ostree-sysroot-cleanup.c \
|
||||||
src/libostree/ostree-bootconfig-parser.h \
|
|
||||||
src/libostree/ostree-bootconfig-parser.c \
|
src/libostree/ostree-bootconfig-parser.c \
|
||||||
src/libostree/ostree-deployment.h \
|
|
||||||
src/libostree/ostree-deployment.c \
|
src/libostree/ostree-deployment.c \
|
||||||
|
src/libostree/ostree-bootloader.c \
|
||||||
|
src/libostree/ostree-bootloader-syslinux.h \
|
||||||
|
src/libostree/ostree-bootloader-syslinux.c \
|
||||||
|
src/libostree/ostree-bootloader-uboot.h \
|
||||||
|
src/libostree/ostree-bootloader-uboot.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
if USE_LIBARCHIVE
|
if USE_LIBARCHIVE
|
||||||
libostree_1_la_SOURCES += src/libostree/ostree-libarchive-input-stream.h \
|
libostree_1_la_SOURCES += src/libostree/ostree-libarchive-input-stream.h \
|
||||||
|
|
|
||||||
|
|
@ -59,18 +59,11 @@ ostree_SOURCES += \
|
||||||
src/ostree/ot-admin-builtin-status.c \
|
src/ostree/ot-admin-builtin-status.c \
|
||||||
src/ostree/ot-admin-builtin-upgrade.c \
|
src/ostree/ot-admin-builtin-upgrade.c \
|
||||||
src/ostree/ot-admin-builtins.h \
|
src/ostree/ot-admin-builtins.h \
|
||||||
src/ostree/ot-admin-cleanup.c \
|
|
||||||
src/ostree/ot-admin-util.c \
|
src/ostree/ot-admin-util.c \
|
||||||
src/ostree/ot-admin-functions.h \
|
src/ostree/ot-admin-functions.h \
|
||||||
src/ostree/ot-admin-functions.c \
|
src/ostree/ot-admin-functions.c \
|
||||||
src/ostree/ot-admin-deploy.h \
|
src/ostree/ot-admin-deploy.h \
|
||||||
src/ostree/ot-admin-deploy.c \
|
src/ostree/ot-admin-deploy.c \
|
||||||
src/ostree/ot-bootloader.h \
|
|
||||||
src/ostree/ot-bootloader.c \
|
|
||||||
src/ostree/ot-bootloader-syslinux.h \
|
|
||||||
src/ostree/ot-bootloader-syslinux.c \
|
|
||||||
src/ostree/ot-bootloader-uboot.h \
|
|
||||||
src/ostree/ot-bootloader-uboot.c \
|
|
||||||
src/ostree/ot-ordered-hash.h \
|
src/ostree/ot-ordered-hash.h \
|
||||||
src/ostree/ot-ordered-hash.c \
|
src/ostree/ot-ordered-hash.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
|
||||||
|
|
@ -20,43 +20,43 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ot-bootloader-syslinux.h"
|
#include "ostree-sysroot-private.h"
|
||||||
|
#include "ostree-bootloader-syslinux.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "ot-admin-functions.h"
|
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct _OtBootloaderSyslinux
|
struct _OstreeBootloaderSyslinux
|
||||||
{
|
{
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
GFile *sysroot;
|
OstreeSysroot *sysroot;
|
||||||
GFile *config_path;
|
GFile *config_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef GObjectClass OtBootloaderSyslinuxClass;
|
typedef GObjectClass OstreeBootloaderSyslinuxClass;
|
||||||
|
|
||||||
static void ot_bootloader_syslinux_bootloader_iface_init (OtBootloaderInterface *iface);
|
static void ostree_bootloader_syslinux_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||||
G_DEFINE_TYPE_WITH_CODE (OtBootloaderSyslinux, ot_bootloader_syslinux, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderSyslinux, ostree_bootloader_syslinux, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (OT_TYPE_BOOTLOADER, ot_bootloader_syslinux_bootloader_iface_init));
|
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, ostree_bootloader_syslinux_bootloader_iface_init));
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ot_bootloader_syslinux_query (OtBootloader *bootloader)
|
ostree_bootloader_syslinux_query (OstreeBootloader *bootloader)
|
||||||
{
|
{
|
||||||
OtBootloaderSyslinux *self = OT_BOOTLOADER_SYSLINUX (bootloader);
|
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);
|
||||||
|
|
||||||
return g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK;
|
return g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
ot_bootloader_syslinux_get_name (OtBootloader *bootloader)
|
ostree_bootloader_syslinux_get_name (OstreeBootloader *bootloader)
|
||||||
{
|
{
|
||||||
return "syslinux";
|
return "syslinux";
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
append_config_from_boot_loader_entries (OtBootloaderSyslinux *self,
|
append_config_from_boostree_loader_entries (OstreeBootloaderSyslinux *self,
|
||||||
gboolean regenerate_default,
|
gboolean regenerate_default,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
GPtrArray *new_lines,
|
GPtrArray *new_lines,
|
||||||
|
|
@ -64,16 +64,16 @@ append_config_from_boot_loader_entries (OtBootloaderSyslinux *self,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_unref_ptrarray GPtrArray *boot_loader_configs = NULL;
|
gs_unref_ptrarray GPtrArray *boostree_loader_configs = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
if (!ot_admin_read_boot_loader_configs (self->sysroot, bootversion, &boot_loader_configs,
|
if (!_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &boostree_loader_configs,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < boot_loader_configs->len; i++)
|
for (i = 0; i < boostree_loader_configs->len; i++)
|
||||||
{
|
{
|
||||||
OstreeBootconfigParser *config = boot_loader_configs->pdata[i];
|
OstreeBootconfigParser *config = boostree_loader_configs->pdata[i];
|
||||||
const char *val;
|
const char *val;
|
||||||
|
|
||||||
val = ostree_bootconfig_parser_get (config, "title");
|
val = ostree_bootconfig_parser_get (config, "title");
|
||||||
|
|
@ -111,13 +111,13 @@ append_config_from_boot_loader_entries (OtBootloaderSyslinux *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
OtBootloaderSyslinux *self = OT_BOOTLOADER_SYSLINUX (bootloader);
|
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);
|
||||||
gs_unref_object GFile *new_config_path = NULL;
|
gs_unref_object GFile *new_config_path = NULL;
|
||||||
gs_free char *config_contents = NULL;
|
gs_free char *config_contents = NULL;
|
||||||
gs_free char *new_config_contents = NULL;
|
gs_free char *new_config_contents = NULL;
|
||||||
|
|
@ -131,7 +131,7 @@ ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
||||||
char **iter;
|
char **iter;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
new_config_path = ot_gfile_resolve_path_printf (self->sysroot, "boot/loader.%d/syslinux.cfg",
|
new_config_path = ot_gfile_resolve_path_printf (self->sysroot->path, "boot/loader.%d/syslinux.cfg",
|
||||||
bootversion);
|
bootversion);
|
||||||
|
|
||||||
/* This should follow the symbolic link to the current bootversion. */
|
/* This should follow the symbolic link to the current bootversion. */
|
||||||
|
|
@ -230,12 +230,12 @@ ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
||||||
if (!saw_default)
|
if (!saw_default)
|
||||||
regenerate_default = TRUE;
|
regenerate_default = TRUE;
|
||||||
|
|
||||||
if (!append_config_from_boot_loader_entries (self, regenerate_default,
|
if (!append_config_from_boostree_loader_entries (self, regenerate_default,
|
||||||
bootversion, new_lines,
|
bootversion, new_lines,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
new_config_contents = ot_admin_join_lines (new_lines);
|
new_config_contents = _ostree_sysroot_join_lines (new_lines);
|
||||||
|
|
||||||
if (strcmp (new_config_contents, config_contents) != 0)
|
if (strcmp (new_config_contents, config_contents) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -254,42 +254,42 @@ ot_bootloader_syslinux_write_config (OtBootloader *bootloader,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ot_bootloader_syslinux_finalize (GObject *object)
|
ostree_bootloader_syslinux_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
OtBootloaderSyslinux *self = OT_BOOTLOADER_SYSLINUX (object);
|
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (object);
|
||||||
|
|
||||||
g_clear_object (&self->sysroot);
|
g_clear_object (&self->sysroot);
|
||||||
g_clear_object (&self->config_path);
|
g_clear_object (&self->config_path);
|
||||||
|
|
||||||
G_OBJECT_CLASS (ot_bootloader_syslinux_parent_class)->finalize (object);
|
G_OBJECT_CLASS (ostree_bootloader_syslinux_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ot_bootloader_syslinux_init (OtBootloaderSyslinux *self)
|
ostree_bootloader_syslinux_init (OstreeBootloaderSyslinux *self)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ot_bootloader_syslinux_bootloader_iface_init (OtBootloaderInterface *iface)
|
ostree_bootloader_syslinux_bootloader_iface_init (OstreeBootloaderInterface *iface)
|
||||||
{
|
{
|
||||||
iface->query = ot_bootloader_syslinux_query;
|
iface->query = ostree_bootloader_syslinux_query;
|
||||||
iface->get_name = ot_bootloader_syslinux_get_name;
|
iface->get_name = ostree_bootloader_syslinux_get_name;
|
||||||
iface->write_config = ot_bootloader_syslinux_write_config;
|
iface->write_config = ostree_bootloader_syslinux_write_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ot_bootloader_syslinux_class_init (OtBootloaderSyslinuxClass *class)
|
ostree_bootloader_syslinux_class_init (OstreeBootloaderSyslinuxClass *class)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
|
||||||
object_class->finalize = ot_bootloader_syslinux_finalize;
|
object_class->finalize = ostree_bootloader_syslinux_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
OtBootloaderSyslinux *
|
OstreeBootloaderSyslinux *
|
||||||
ot_bootloader_syslinux_new (GFile *sysroot)
|
ostree_bootloader_syslinux_new (OstreeSysroot *sysroot)
|
||||||
{
|
{
|
||||||
OtBootloaderSyslinux *self = g_object_new (OT_TYPE_BOOTLOADER_SYSLINUX, NULL);
|
OstreeBootloaderSyslinux *self = g_object_new (OSTREE_TYPE_BOOTLOADER_SYSLINUX, NULL);
|
||||||
self->sysroot = g_object_ref (sysroot);
|
self->sysroot = g_object_ref (sysroot);
|
||||||
self->config_path = g_file_resolve_relative_path (self->sysroot, "boot/syslinux/syslinux.cfg");
|
self->config_path = g_file_resolve_relative_path (self->sysroot->path, "boot/syslinux/syslinux.cfg");
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -20,19 +20,19 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ot-bootloader.h"
|
#include "ostree-bootloader.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define OT_TYPE_BOOTLOADER_SYSLINUX (ot_bootloader_syslinux_get_type ())
|
#define OSTREE_TYPE_BOOTLOADER_SYSLINUX (ostree_bootloader_syslinux_get_type ())
|
||||||
#define OT_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OT_TYPE_BOOTLOADER_SYSLINUX, OtBootloaderSyslinux))
|
#define OSTREE_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX, OstreeBootloaderSyslinux))
|
||||||
#define OT_IS_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OT_TYPE_BOOTLOADER_SYSLINUX))
|
#define OSTREE_IS_BOOTLOADER_SYSLINUX(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_SYSLINUX))
|
||||||
|
|
||||||
typedef struct _OtBootloaderSyslinux OtBootloaderSyslinux;
|
typedef struct _OstreeBootloaderSyslinux OstreeBootloaderSyslinux;
|
||||||
|
|
||||||
GType ot_bootloader_syslinux_get_type (void) G_GNUC_CONST;
|
GType ostree_bootloader_syslinux_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
OtBootloaderSyslinux * ot_bootloader_syslinux_new (GFile *sysroot);
|
OstreeBootloaderSyslinux * ostree_bootloader_syslinux_new (OstreeSysroot *sysroot);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
@ -24,43 +24,43 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ot-bootloader-uboot.h"
|
#include "ostree-sysroot-private.h"
|
||||||
|
#include "ostree-bootloader-uboot.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "ot-admin-functions.h"
|
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct _OtBootloaderUboot
|
struct _OstreeBootloaderUboot
|
||||||
{
|
{
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
GFile *sysroot;
|
OstreeSysroot *sysroot;
|
||||||
GFile *config_path;
|
GFile *config_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef GObjectClass OtBootloaderUbootClass;
|
typedef GObjectClass OstreeBootloaderUbootClass;
|
||||||
|
|
||||||
static void ot_bootloader_uboot_bootloader_iface_init (OtBootloaderInterface *iface);
|
static void ostree_bootloader_uboot_bootloader_iface_init (OstreeBootloaderInterface *iface);
|
||||||
G_DEFINE_TYPE_WITH_CODE (OtBootloaderUboot, ot_bootloader_uboot, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderUboot, ostree_bootloader_uboot, G_TYPE_OBJECT,
|
||||||
G_IMPLEMENT_INTERFACE (OT_TYPE_BOOTLOADER, ot_bootloader_uboot_bootloader_iface_init));
|
G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, ostree_bootloader_uboot_bootloader_iface_init));
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ot_bootloader_uboot_query (OtBootloader *bootloader)
|
ostree_bootloader_uboot_query (OstreeBootloader *bootloader)
|
||||||
{
|
{
|
||||||
OtBootloaderUboot *self = OT_BOOTLOADER_UBOOT (bootloader);
|
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);
|
||||||
|
|
||||||
return g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK;
|
return g_file_query_file_type (self->config_path, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
ot_bootloader_uboot_get_name (OtBootloader *bootloader)
|
ostree_bootloader_uboot_get_name (OstreeBootloader *bootloader)
|
||||||
{
|
{
|
||||||
return "U-Boot";
|
return "U-Boot";
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
create_config_from_boot_loader_entries (OtBootloaderUboot *self,
|
create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
GPtrArray *new_lines,
|
GPtrArray *new_lines,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -70,8 +70,8 @@ create_config_from_boot_loader_entries (OtBootloaderUboot *self,
|
||||||
OstreeBootconfigParser *config;
|
OstreeBootconfigParser *config;
|
||||||
const char *val;
|
const char *val;
|
||||||
|
|
||||||
if (!ot_admin_read_boot_loader_configs (self->sysroot, bootversion, &boot_loader_configs,
|
if (!_ostree_sysroot_read_boot_loader_configs (self->sysroot, bootversion, &boot_loader_configs,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* U-Boot doesn't support a menu so just pick the first one since the list is ordered */
|
/* U-Boot doesn't support a menu so just pick the first one since the list is ordered */
|
||||||
|
|
@ -98,12 +98,12 @@ create_config_from_boot_loader_entries (OtBootloaderUboot *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ot_bootloader_uboot_write_config (OtBootloader *bootloader,
|
ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
OtBootloaderUboot *self = OT_BOOTLOADER_UBOOT (bootloader);
|
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);
|
||||||
gs_unref_object GFile *new_config_path = NULL;
|
gs_unref_object GFile *new_config_path = NULL;
|
||||||
gs_free char *config_contents = NULL;
|
gs_free char *config_contents = NULL;
|
||||||
gs_free char *new_config_contents = NULL;
|
gs_free char *new_config_contents = NULL;
|
||||||
|
|
@ -114,8 +114,8 @@ ot_bootloader_uboot_write_config (OtBootloader *bootloader,
|
||||||
if (!config_contents)
|
if (!config_contents)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
new_config_path = ot_gfile_resolve_path_printf (self->sysroot, "boot/loader.%d/uEnv.txt",
|
new_config_path = ot_gfile_resolve_path_printf (self->sysroot->path, "boot/loader.%d/uEnv.txt",
|
||||||
bootversion);
|
bootversion);
|
||||||
|
|
||||||
new_lines = g_ptr_array_new_with_free_func (g_free);
|
new_lines = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
|
||||||
|
|
@ -123,7 +123,7 @@ ot_bootloader_uboot_write_config (OtBootloader *bootloader,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
new_config_contents = ot_admin_join_lines (new_lines);
|
new_config_contents = _ostree_sysroot_join_lines (new_lines);
|
||||||
|
|
||||||
if (strcmp (new_config_contents, config_contents) != 0)
|
if (strcmp (new_config_contents, config_contents) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -139,42 +139,42 @@ ot_bootloader_uboot_write_config (OtBootloader *bootloader,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ot_bootloader_uboot_finalize (GObject *object)
|
ostree_bootloader_uboot_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
OtBootloaderUboot *self = OT_BOOTLOADER_UBOOT (object);
|
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (object);
|
||||||
|
|
||||||
g_clear_object (&self->sysroot);
|
g_clear_object (&self->sysroot);
|
||||||
g_clear_object (&self->config_path);
|
g_clear_object (&self->config_path);
|
||||||
|
|
||||||
G_OBJECT_CLASS (ot_bootloader_uboot_parent_class)->finalize (object);
|
G_OBJECT_CLASS (ostree_bootloader_uboot_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ot_bootloader_uboot_init (OtBootloaderUboot *self)
|
ostree_bootloader_uboot_init (OstreeBootloaderUboot *self)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ot_bootloader_uboot_bootloader_iface_init (OtBootloaderInterface *iface)
|
ostree_bootloader_uboot_bootloader_iface_init (OstreeBootloaderInterface *iface)
|
||||||
{
|
{
|
||||||
iface->query = ot_bootloader_uboot_query;
|
iface->query = ostree_bootloader_uboot_query;
|
||||||
iface->get_name = ot_bootloader_uboot_get_name;
|
iface->get_name = ostree_bootloader_uboot_get_name;
|
||||||
iface->write_config = ot_bootloader_uboot_write_config;
|
iface->write_config = ostree_bootloader_uboot_write_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ot_bootloader_uboot_class_init (OtBootloaderUbootClass *class)
|
ostree_bootloader_uboot_class_init (OstreeBootloaderUbootClass *class)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||||
|
|
||||||
object_class->finalize = ot_bootloader_uboot_finalize;
|
object_class->finalize = ostree_bootloader_uboot_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
OtBootloaderUboot *
|
OstreeBootloaderUboot *
|
||||||
ot_bootloader_uboot_new (GFile *sysroot)
|
ostree_bootloader_uboot_new (OstreeSysroot *sysroot)
|
||||||
{
|
{
|
||||||
OtBootloaderUboot *self = g_object_new (OT_TYPE_BOOTLOADER_UBOOT, NULL);
|
OstreeBootloaderUboot *self = g_object_new (OSTREE_TYPE_BOOTLOADER_UBOOT, NULL);
|
||||||
self->sysroot = g_object_ref (sysroot);
|
self->sysroot = g_object_ref (sysroot);
|
||||||
self->config_path = g_file_resolve_relative_path (self->sysroot, "boot/uEnv.txt");
|
self->config_path = g_file_resolve_relative_path (self->sysroot->path, "boot/uEnv.txt");
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
@ -24,18 +24,18 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ot-bootloader.h"
|
#include "ostree-bootloader.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define OT_TYPE_BOOTLOADER_UBOOT (ot_bootloader_uboot_get_type ())
|
#define OSTREE_TYPE_BOOTLOADER_UBOOT (ostree_bootloader_uboot_get_type ())
|
||||||
#define OT_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OT_TYPE_BOOTLOADER_UBOOT, OtBootloaderUboot))
|
#define OSTREE_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT, OstreeBootloaderUboot))
|
||||||
#define OT_IS_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OT_TYPE_BOOTLOADER_UBOOT))
|
#define OSTREE_IS_BOOTLOADER_UBOOT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER_UBOOT))
|
||||||
|
|
||||||
typedef struct _OtBootloaderUboot OtBootloaderUboot;
|
typedef struct _OstreeBootloaderUboot OstreeBootloaderUboot;
|
||||||
|
|
||||||
GType ot_bootloader_uboot_get_type (void) G_GNUC_CONST;
|
GType ostree_bootloader_uboot_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
OtBootloaderUboot * ot_bootloader_uboot_new (GFile *sysroot);
|
OstreeBootloaderUboot * ostree_bootloader_uboot_new (OstreeSysroot *sysroot);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
@ -19,45 +19,45 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ot-bootloader.h"
|
#include "ostree-bootloader.h"
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
||||||
G_DEFINE_INTERFACE (OtBootloader, ot_bootloader, G_TYPE_OBJECT)
|
G_DEFINE_INTERFACE (OstreeBootloader, ostree_bootloader, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ot_bootloader_default_init (OtBootloaderInterface *iface)
|
ostree_bootloader_default_init (OstreeBootloaderInterface *iface)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ot_bootloader_query (OtBootloader *self)
|
ostree_bootloader_query (OstreeBootloader *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (OT_IS_BOOTLOADER (self), FALSE);
|
g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE);
|
||||||
|
|
||||||
return OT_BOOTLOADER_GET_IFACE (self)->query (self);
|
return OSTREE_BOOTLOADER_GET_IFACE (self)->query (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ot_bootloader_get_name:
|
* ostree_bootloader_get_name:
|
||||||
*
|
*
|
||||||
* Returns: (transfer none): Name of this bootloader
|
* Returns: (transfer none): Name of this bootloader
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
ot_bootloader_get_name (OtBootloader *self)
|
ostree_bootloader_get_name (OstreeBootloader *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (OT_IS_BOOTLOADER (self), NULL);
|
g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), NULL);
|
||||||
|
|
||||||
return OT_BOOTLOADER_GET_IFACE (self)->get_name (self);
|
return OSTREE_BOOTLOADER_GET_IFACE (self)->get_name (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ot_bootloader_write_config (OtBootloader *self,
|
ostree_bootloader_write_config (OstreeBootloader *self,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (OT_IS_BOOTLOADER (self), FALSE);
|
g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE);
|
||||||
|
|
||||||
return OT_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion,
|
return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion,
|
||||||
cancellable, error);
|
cancellable, error);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Colin Walters <walters@verbum.org>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published
|
||||||
|
* by the Free Software Foundation; either version 2 of the licence or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General
|
||||||
|
* Public License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define OSTREE_TYPE_BOOTLOADER (ostree_bootloader_get_type ())
|
||||||
|
#define OSTREE_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloader))
|
||||||
|
#define OSTREE_IS_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_BOOTLOADER))
|
||||||
|
#define OSTREE_BOOTLOADER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), OSTREE_TYPE_BOOTLOADER, OstreeBootloaderInterface))
|
||||||
|
|
||||||
|
typedef struct _OstreeBootloader OstreeBootloader;
|
||||||
|
typedef struct _OstreeBootloaderInterface OstreeBootloaderInterface;
|
||||||
|
|
||||||
|
struct _OstreeBootloaderInterface
|
||||||
|
{
|
||||||
|
GTypeInterface g_iface;
|
||||||
|
|
||||||
|
/* virtual functions */
|
||||||
|
gboolean (* query) (OstreeBootloader *self);
|
||||||
|
const char * (* get_name) (OstreeBootloader *self);
|
||||||
|
gboolean (* write_config) (OstreeBootloader *self,
|
||||||
|
int bootversion,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
};
|
||||||
|
|
||||||
|
GType ostree_bootloader_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
gboolean ostree_bootloader_query (OstreeBootloader *self);
|
||||||
|
|
||||||
|
const char *ostree_bootloader_get_name (OstreeBootloader *self);
|
||||||
|
|
||||||
|
gboolean ostree_bootloader_write_config (OstreeBootloader *self,
|
||||||
|
int bootversion,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Colin Walters <walters@verbum.org>
|
* Copyright (C) 2013 Colin Walters <walters@verbum.org>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
|
@ -16,17 +16,15 @@
|
||||||
* License along with this library; if not, write to the
|
* License along with this library; if not, write to the
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*
|
|
||||||
* Author: Colin Walters <walters@verbum.org>
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ot-admin-functions.h"
|
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "ostree.h"
|
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
||||||
|
#include "ostree-sysroot-private.h"
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
list_deployment_dirs_for_os (GFile *osdir,
|
list_deployment_dirs_for_os (GFile *osdir,
|
||||||
GPtrArray *inout_deployments,
|
GPtrArray *inout_deployments,
|
||||||
|
|
@ -78,7 +76,7 @@ list_deployment_dirs_for_os (GFile *osdir,
|
||||||
if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY)
|
if (g_file_info_get_file_type (file_info) != G_FILE_TYPE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!ot_admin_parse_deploy_path_name (name, &csum, &deployserial, error))
|
if (!_ostree_sysroot_parse_deploy_path_name (name, &csum, &deployserial, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
deployment = ostree_deployment_new (-1, osname, csum, deployserial, NULL, -1);
|
deployment = ostree_deployment_new (-1, osname, csum, deployserial, NULL, -1);
|
||||||
|
|
@ -92,7 +90,7 @@ list_deployment_dirs_for_os (GFile *osdir,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
list_all_deployment_directories (GFile *sysroot,
|
list_all_deployment_directories (OstreeSysroot *self,
|
||||||
GPtrArray **out_deployments,
|
GPtrArray **out_deployments,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
|
@ -103,7 +101,7 @@ list_all_deployment_directories (GFile *sysroot,
|
||||||
gs_unref_ptrarray GPtrArray *ret_deployments = NULL;
|
gs_unref_ptrarray GPtrArray *ret_deployments = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
deploydir = g_file_resolve_relative_path (sysroot, "ostree/deploy");
|
deploydir = g_file_resolve_relative_path (self->path, "ostree/deploy");
|
||||||
|
|
||||||
ret_deployments = g_ptr_array_new_with_free_func (g_object_unref);
|
ret_deployments = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
|
|
||||||
|
|
@ -178,7 +176,7 @@ parse_bootdir_name (const char *name,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
list_all_boot_directories (GFile *sysroot,
|
list_all_boot_directories (OstreeSysroot *self,
|
||||||
GPtrArray **out_bootdirs,
|
GPtrArray **out_bootdirs,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
|
@ -189,7 +187,7 @@ list_all_boot_directories (GFile *sysroot,
|
||||||
gs_unref_ptrarray GPtrArray *ret_bootdirs = NULL;
|
gs_unref_ptrarray GPtrArray *ret_bootdirs = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
boot_ostree = g_file_resolve_relative_path (sysroot, "boot/ostree");
|
boot_ostree = g_file_resolve_relative_path (self->path, "boot/ostree");
|
||||||
|
|
||||||
ret_bootdirs = g_ptr_array_new_with_free_func (g_object_unref);
|
ret_bootdirs = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
|
|
||||||
|
|
@ -243,7 +241,7 @@ list_all_boot_directories (GFile *sysroot,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
cleanup_other_bootversions (GFile *sysroot,
|
cleanup_other_bootversions (OstreeSysroot *self,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
int subbootversion,
|
int subbootversion,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -257,27 +255,27 @@ cleanup_other_bootversions (GFile *sysroot,
|
||||||
cleanup_bootversion = bootversion == 0 ? 1 : 0;
|
cleanup_bootversion = bootversion == 0 ? 1 : 0;
|
||||||
cleanup_subbootversion = subbootversion == 0 ? 1 : 0;
|
cleanup_subbootversion = subbootversion == 0 ? 1 : 0;
|
||||||
|
|
||||||
cleanup_boot_dir = ot_gfile_resolve_path_printf (sysroot, "boot/loader.%d", cleanup_bootversion);
|
cleanup_boot_dir = ot_gfile_resolve_path_printf (self->path, "boot/loader.%d", cleanup_bootversion);
|
||||||
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
g_clear_object (&cleanup_boot_dir);
|
g_clear_object (&cleanup_boot_dir);
|
||||||
|
|
||||||
cleanup_boot_dir = ot_gfile_resolve_path_printf (sysroot, "ostree/boot.%d", cleanup_bootversion);
|
cleanup_boot_dir = ot_gfile_resolve_path_printf (self->path, "ostree/boot.%d", cleanup_bootversion);
|
||||||
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
g_clear_object (&cleanup_boot_dir);
|
g_clear_object (&cleanup_boot_dir);
|
||||||
|
|
||||||
cleanup_boot_dir = ot_gfile_resolve_path_printf (sysroot, "ostree/boot.%d.0", cleanup_bootversion);
|
cleanup_boot_dir = ot_gfile_resolve_path_printf (self->path, "ostree/boot.%d.0", cleanup_bootversion);
|
||||||
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
g_clear_object (&cleanup_boot_dir);
|
g_clear_object (&cleanup_boot_dir);
|
||||||
|
|
||||||
cleanup_boot_dir = ot_gfile_resolve_path_printf (sysroot, "ostree/boot.%d.1", cleanup_bootversion);
|
cleanup_boot_dir = ot_gfile_resolve_path_printf (self->path, "ostree/boot.%d.1", cleanup_bootversion);
|
||||||
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
g_clear_object (&cleanup_boot_dir);
|
g_clear_object (&cleanup_boot_dir);
|
||||||
|
|
||||||
cleanup_boot_dir = ot_gfile_resolve_path_printf (sysroot, "ostree/boot.%d.%d", bootversion,
|
cleanup_boot_dir = ot_gfile_resolve_path_printf (self->path, "ostree/boot.%d.%d", bootversion,
|
||||||
cleanup_subbootversion);
|
cleanup_subbootversion);
|
||||||
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
if (!gs_shutil_rm_rf (cleanup_boot_dir, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -289,7 +287,7 @@ cleanup_other_bootversions (GFile *sysroot,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
cleanup_old_deployments (GFile *sysroot,
|
cleanup_old_deployments (OstreeSysroot *self,
|
||||||
GPtrArray *deployments,
|
GPtrArray *deployments,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
|
|
@ -304,8 +302,8 @@ cleanup_old_deployments (GFile *sysroot,
|
||||||
gs_unref_ptrarray GPtrArray *all_deployment_dirs = NULL;
|
gs_unref_ptrarray GPtrArray *all_deployment_dirs = NULL;
|
||||||
gs_unref_ptrarray GPtrArray *all_boot_dirs = NULL;
|
gs_unref_ptrarray GPtrArray *all_boot_dirs = NULL;
|
||||||
|
|
||||||
if (!ot_admin_util_get_devino (active_root, &root_device, &root_inode,
|
if (!_ostree_sysroot_get_devino (active_root, &root_device, &root_inode,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
active_deployment_dirs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, g_object_unref);
|
active_deployment_dirs = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, NULL, g_object_unref);
|
||||||
|
|
@ -314,29 +312,29 @@ cleanup_old_deployments (GFile *sysroot,
|
||||||
for (i = 0; i < deployments->len; i++)
|
for (i = 0; i < deployments->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = deployments->pdata[i];
|
OstreeDeployment *deployment = deployments->pdata[i];
|
||||||
GFile *deployment_path = ot_admin_get_deployment_directory (sysroot, deployment);
|
GFile *deployment_path = ostree_sysroot_get_deployment_directory (self, deployment);
|
||||||
char *bootcsum = g_strdup (ostree_deployment_get_bootcsum (deployment));
|
char *bootcsum = g_strdup (ostree_deployment_get_bootcsum (deployment));
|
||||||
/* Transfer ownership */
|
/* Transfer ownership */
|
||||||
g_hash_table_insert (active_deployment_dirs, deployment_path, deployment_path);
|
g_hash_table_insert (active_deployment_dirs, deployment_path, deployment_path);
|
||||||
g_hash_table_insert (active_boot_checksums, bootcsum, bootcsum);
|
g_hash_table_insert (active_boot_checksums, bootcsum, bootcsum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list_all_deployment_directories (sysroot, &all_deployment_dirs,
|
if (!list_all_deployment_directories (self, &all_deployment_dirs,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (i = 0; i < all_deployment_dirs->len; i++)
|
for (i = 0; i < all_deployment_dirs->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = all_deployment_dirs->pdata[i];
|
OstreeDeployment *deployment = all_deployment_dirs->pdata[i];
|
||||||
gs_unref_object GFile *deployment_path = ot_admin_get_deployment_directory (sysroot, deployment);
|
gs_unref_object GFile *deployment_path = ostree_sysroot_get_deployment_directory (self, deployment);
|
||||||
gs_unref_object GFile *origin_path = ot_admin_get_deployment_origin_path (deployment_path);
|
gs_unref_object GFile *origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
|
||||||
if (!g_hash_table_lookup (active_deployment_dirs, deployment_path))
|
if (!g_hash_table_lookup (active_deployment_dirs, deployment_path))
|
||||||
{
|
{
|
||||||
guint32 device;
|
guint32 device;
|
||||||
guint64 inode;
|
guint64 inode;
|
||||||
|
|
||||||
if (!ot_admin_util_get_devino (deployment_path, &device, &inode,
|
if (!_ostree_sysroot_get_devino (deployment_path, &device, &inode,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* This shouldn't happen, because higher levels should
|
/* This shouldn't happen, because higher levels should
|
||||||
|
|
@ -353,7 +351,7 @@ cleanup_old_deployments (GFile *sysroot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!list_all_boot_directories (sysroot, &all_boot_dirs,
|
if (!list_all_boot_directories (self, &all_boot_dirs,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -419,7 +417,7 @@ cleanup_ref_prefix (OstreeRepo *repo,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
generate_deployment_refs_and_prune (GFile *sysroot,
|
generate_deployment_refs_and_prune (OstreeSysroot *self,
|
||||||
OstreeRepo *repo,
|
OstreeRepo *repo,
|
||||||
int bootversion,
|
int bootversion,
|
||||||
int subbootversion,
|
int subbootversion,
|
||||||
|
|
@ -481,10 +479,19 @@ generate_deployment_refs_and_prune (GFile *sysroot,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_cleanup:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Delete any state that resulted from a partially completed
|
||||||
|
* transaction, such as incomplete deployments.
|
||||||
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
ot_admin_cleanup (GFile *sysroot,
|
ostree_sysroot_cleanup (OstreeSysroot *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_unref_ptrarray GPtrArray *deployments = NULL;
|
gs_unref_ptrarray GPtrArray *deployments = NULL;
|
||||||
|
|
@ -492,28 +499,28 @@ ot_admin_cleanup (GFile *sysroot,
|
||||||
int bootversion;
|
int bootversion;
|
||||||
int subbootversion;
|
int subbootversion;
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (sysroot, &bootversion, &deployments,
|
if (!ostree_sysroot_list_deployments (self, &bootversion, &deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ot_admin_read_current_subbootversion (sysroot, bootversion, &subbootversion,
|
if (!ostree_sysroot_read_current_subbootversion (self, bootversion, &subbootversion,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!cleanup_other_bootversions (sysroot, bootversion, subbootversion,
|
if (!cleanup_other_bootversions (self, bootversion, subbootversion,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!cleanup_old_deployments (sysroot, deployments,
|
if (!cleanup_old_deployments (self, deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (deployments->len > 0)
|
if (deployments->len > 0)
|
||||||
{
|
{
|
||||||
if (!ot_admin_get_repo (sysroot, &repo, cancellable, error))
|
if (!ostree_sysroot_get_repo (self, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!generate_deployment_refs_and_prune (sysroot, repo, bootversion,
|
if (!generate_deployment_refs_and_prune (self, repo, bootversion,
|
||||||
subbootversion, deployments,
|
subbootversion, deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012,2013 Colin Walters <walters@verbum.org>
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the
|
||||||
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
* Boston, MA 02111-1307, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ostree.h"
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
struct OstreeSysroot {
|
||||||
|
GObject parent;
|
||||||
|
|
||||||
|
GFile *path;
|
||||||
|
int sysroot_fd;
|
||||||
|
};
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||||
|
int bootversion,
|
||||||
|
GPtrArray **out_loader_configs,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_parse_deploy_path_name (const char *name,
|
||||||
|
char **out_csum,
|
||||||
|
int *out_serial,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_get_devino (GFile *path,
|
||||||
|
guint32 *out_device,
|
||||||
|
guint64 *out_inode,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
char *_ostree_sysroot_join_lines (GPtrArray *lines);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
@ -23,7 +23,9 @@
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
||||||
#include "ostree-sysroot.h"
|
#include "ostree-sysroot-private.h"
|
||||||
|
#include "ostree-bootloader-uboot.h"
|
||||||
|
#include "ostree-bootloader-syslinux.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:libostree-sysroot
|
* SECTION:libostree-sysroot
|
||||||
|
|
@ -35,14 +37,6 @@
|
||||||
* Inside this directory is an #OstreeRepo in /ostree/repo, plus a set
|
* Inside this directory is an #OstreeRepo in /ostree/repo, plus a set
|
||||||
* of deployments in /ostree/deploy.
|
* of deployments in /ostree/deploy.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct OstreeSysroot {
|
|
||||||
GObject parent;
|
|
||||||
|
|
||||||
GFile *path;
|
|
||||||
int sysroot_fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
} OstreeSysrootClass;
|
} OstreeSysrootClass;
|
||||||
|
|
@ -175,6 +169,28 @@ ostree_sysroot_get_path (OstreeSysroot *self)
|
||||||
return self->path;
|
return self->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_get_devino (GFile *path,
|
||||||
|
guint32 *out_device,
|
||||||
|
guint64 *out_inode,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object GFileInfo *finfo = g_file_query_info (path, "unix::device,unix::inode",
|
||||||
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
cancellable, error);
|
||||||
|
|
||||||
|
if (!finfo)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
*out_device = g_file_info_get_attribute_uint32 (finfo, "unix::device");
|
||||||
|
*out_inode = g_file_info_get_attribute_uint64 (finfo, "unix::inode");
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_sysroot_ensure_initialized:
|
* ostree_sysroot_ensure_initialized:
|
||||||
* @self:
|
* @self:
|
||||||
|
|
@ -223,3 +239,603 @@ ostree_sysroot_ensure_initialized (OstreeSysroot *self,
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
match_info_cleanup (void *loc)
|
||||||
|
{
|
||||||
|
GMatchInfo **match = (GMatchInfo**)loc;
|
||||||
|
if (*match) g_match_info_unref (*match);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_parse_deploy_path_name (const char *name,
|
||||||
|
char **out_csum,
|
||||||
|
int *out_serial,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
__attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL;
|
||||||
|
gs_free char *serial_str = NULL;
|
||||||
|
|
||||||
|
static gsize regex_initialized;
|
||||||
|
static GRegex *regex;
|
||||||
|
|
||||||
|
if (g_once_init_enter (®ex_initialized))
|
||||||
|
{
|
||||||
|
regex = g_regex_new ("^([0-9a-f]+)\\.([0-9]+)$", 0, 0, NULL);
|
||||||
|
g_assert (regex);
|
||||||
|
g_once_init_leave (®ex_initialized, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_regex_match (regex, name, 0, &match))
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Invalid deploy name '%s', expected CHECKSUM.TREESERIAL", name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out_csum = g_match_info_fetch (match, 1);
|
||||||
|
serial_str = g_match_info_fetch (match, 2);
|
||||||
|
*out_serial = (int)g_ascii_strtoll (serial_str, NULL, 10);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_read_current_subbootversion:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @bootversion: Current boot version
|
||||||
|
* @out_subbootversion: (out): The active subbootversion
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Determine the active subbootversion.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
|
||||||
|
int bootversion,
|
||||||
|
int *out_subbootversion,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object GFile *ostree_dir = g_file_get_child (self->path, "ostree");
|
||||||
|
gs_free char *ostree_bootdir_name = g_strdup_printf ("boot.%d", bootversion);
|
||||||
|
gs_unref_object GFile *ostree_bootdir = g_file_resolve_relative_path (ostree_dir, ostree_bootdir_name);
|
||||||
|
gs_unref_object GFile *ostree_subbootdir = NULL;
|
||||||
|
|
||||||
|
if (!ot_gfile_query_symlink_target_allow_noent (ostree_bootdir, &ostree_subbootdir,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (ostree_subbootdir == NULL)
|
||||||
|
{
|
||||||
|
*out_subbootversion = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const char *current_subbootdir_name = gs_file_get_basename_cached (ostree_subbootdir);
|
||||||
|
if (g_str_has_suffix (current_subbootdir_name, ".0"))
|
||||||
|
*out_subbootversion = 0;
|
||||||
|
else if (g_str_has_suffix (current_subbootdir_name, ".1"))
|
||||||
|
*out_subbootversion = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Invalid target '%s' in %s",
|
||||||
|
gs_file_get_path_cached (ostree_subbootdir),
|
||||||
|
gs_file_get_path_cached (ostree_bootdir));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||||
|
int bootversion,
|
||||||
|
GPtrArray **out_loader_configs,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
||||||
|
gs_unref_object GFile *loader_entries_dir = NULL;
|
||||||
|
gs_unref_ptrarray GPtrArray *ret_loader_configs = NULL;
|
||||||
|
GError *temp_error = NULL;
|
||||||
|
|
||||||
|
loader_entries_dir = ot_gfile_resolve_path_printf (self->path, "boot/loader.%d/entries",
|
||||||
|
bootversion);
|
||||||
|
ret_loader_configs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
||||||
|
|
||||||
|
dir_enum = g_file_enumerate_children (loader_entries_dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
|
0, NULL, &temp_error);
|
||||||
|
if (!dir_enum)
|
||||||
|
{
|
||||||
|
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||||
|
{
|
||||||
|
g_clear_error (&temp_error);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_propagate_error (error, temp_error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (TRUE)
|
||||||
|
{
|
||||||
|
GFileInfo *file_info;
|
||||||
|
GFile *child;
|
||||||
|
const char *name;
|
||||||
|
|
||||||
|
if (!gs_file_enumerator_iterate (dir_enum, &file_info, &child,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
if (file_info == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
name = g_file_info_get_name (file_info);
|
||||||
|
|
||||||
|
if (g_str_has_prefix (name, "ostree-") &&
|
||||||
|
g_str_has_suffix (name, ".conf") &&
|
||||||
|
g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
|
||||||
|
{
|
||||||
|
gs_unref_object OstreeBootconfigParser *config = ostree_bootconfig_parser_new ();
|
||||||
|
|
||||||
|
if (!ostree_bootconfig_parser_parse (config, child, cancellable, error))
|
||||||
|
{
|
||||||
|
g_prefix_error (error, "Parsing %s: ", gs_file_get_path_cached (child));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_add (ret_loader_configs, g_object_ref (config));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
gs_transfer_out_value (out_loader_configs, &ret_loader_configs);
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
read_current_bootversion (OstreeSysroot *self,
|
||||||
|
int *out_bootversion,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object GFile *boot_loader_path = g_file_resolve_relative_path (self->path, "boot/loader");
|
||||||
|
gs_unref_object GFileInfo *info = NULL;
|
||||||
|
const char *target;
|
||||||
|
int ret_bootversion;
|
||||||
|
|
||||||
|
if (!ot_gfile_query_info_allow_noent (boot_loader_path, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
&info,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (info == NULL)
|
||||||
|
ret_bootversion = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (g_file_info_get_file_type (info) != G_FILE_TYPE_SYMBOLIC_LINK)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Not a symbolic link: %s", gs_file_get_path_cached (boot_loader_path));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
target = g_file_info_get_symlink_target (info);
|
||||||
|
if (g_strcmp0 (target, "loader.0") == 0)
|
||||||
|
ret_bootversion = 0;
|
||||||
|
else if (g_strcmp0 (target, "loader.1") == 0)
|
||||||
|
ret_bootversion = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Invalid target '%s' in %s", target, gs_file_get_path_cached (boot_loader_path));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
*out_bootversion = ret_bootversion;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_origin (OstreeSysroot *self,
|
||||||
|
GFile *deployment_path,
|
||||||
|
GKeyFile **out_origin,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
GKeyFile *ret_origin = NULL;
|
||||||
|
gs_unref_object GFile *origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
|
||||||
|
gs_free char *origin_contents = NULL;
|
||||||
|
|
||||||
|
if (!ot_gfile_load_contents_utf8_allow_noent (origin_path, &origin_contents,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (origin_contents)
|
||||||
|
{
|
||||||
|
ret_origin = g_key_file_new ();
|
||||||
|
if (!g_key_file_load_from_data (ret_origin, origin_contents, -1, 0, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
gs_transfer_out_value (out_origin, &ret_origin);
|
||||||
|
out:
|
||||||
|
if (error)
|
||||||
|
g_prefix_error (error, "Parsing %s: ", gs_file_get_path_cached (origin_path));
|
||||||
|
if (ret_origin)
|
||||||
|
g_key_file_unref (ret_origin);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_bootlink (const char *bootlink,
|
||||||
|
int *out_entry_bootversion,
|
||||||
|
char **out_osname,
|
||||||
|
char **out_bootcsum,
|
||||||
|
int *out_treebootserial,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
__attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL;
|
||||||
|
gs_free char *bootversion_str = NULL;
|
||||||
|
gs_free char *treebootserial_str = NULL;
|
||||||
|
|
||||||
|
static gsize regex_initialized;
|
||||||
|
static GRegex *regex;
|
||||||
|
|
||||||
|
if (g_once_init_enter (®ex_initialized))
|
||||||
|
{
|
||||||
|
regex = g_regex_new ("^/ostree/boot.([01])/([^/]+)/([^/]+)/([0-9]+)$", 0, 0, NULL);
|
||||||
|
g_assert (regex);
|
||||||
|
g_once_init_leave (®ex_initialized, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_regex_match (regex, bootlink, 0, &match))
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Invalid ostree= argument '%s', expected ostree=/ostree/boot.BOOTVERSION/OSNAME/BOOTCSUM/TREESERIAL", bootlink);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
bootversion_str = g_match_info_fetch (match, 1);
|
||||||
|
*out_entry_bootversion = (int)g_ascii_strtoll (bootversion_str, NULL, 10);
|
||||||
|
*out_osname = g_match_info_fetch (match, 2);
|
||||||
|
*out_bootcsum = g_match_info_fetch (match, 3);
|
||||||
|
treebootserial_str = g_match_info_fetch (match, 4);
|
||||||
|
*out_treebootserial = (int)g_ascii_strtoll (treebootserial_str, NULL, 10);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_deployment (OstreeSysroot *self,
|
||||||
|
const char *boot_link,
|
||||||
|
OstreeDeployment **out_deployment,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
const char *relative_boot_link;
|
||||||
|
gs_unref_object OstreeDeployment *ret_deployment = NULL;
|
||||||
|
int entry_boot_version;
|
||||||
|
int treebootserial = -1;
|
||||||
|
int deployserial = -1;
|
||||||
|
gs_free char *osname = NULL;
|
||||||
|
gs_free char *bootcsum = NULL;
|
||||||
|
gs_free char *treecsum = NULL;
|
||||||
|
gs_unref_object GFile *treebootserial_link = NULL;
|
||||||
|
gs_unref_object GFileInfo *treebootserial_info = NULL;
|
||||||
|
gs_unref_object GFile *treebootserial_target = NULL;
|
||||||
|
GKeyFile *origin = NULL;
|
||||||
|
|
||||||
|
if (!parse_bootlink (boot_link, &entry_boot_version,
|
||||||
|
&osname, &bootcsum, &treebootserial,
|
||||||
|
error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
relative_boot_link = boot_link;
|
||||||
|
if (*relative_boot_link == '/')
|
||||||
|
relative_boot_link++;
|
||||||
|
treebootserial_link = g_file_resolve_relative_path (self->path, relative_boot_link);
|
||||||
|
treebootserial_info = g_file_query_info (treebootserial_link, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
cancellable, error);
|
||||||
|
if (!treebootserial_info)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!ot_gfile_get_symlink_target_from_info (treebootserial_link, treebootserial_info,
|
||||||
|
&treebootserial_target, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!_ostree_sysroot_parse_deploy_path_name (gs_file_get_basename_cached (treebootserial_target),
|
||||||
|
&treecsum, &deployserial, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!parse_origin (self, treebootserial_target, &origin,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret_deployment = ostree_deployment_new (-1, osname, treecsum, deployserial,
|
||||||
|
bootcsum, treebootserial);
|
||||||
|
if (origin)
|
||||||
|
ostree_deployment_set_origin (ret_deployment, origin);
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
gs_transfer_out_value (out_deployment, &ret_deployment);
|
||||||
|
out:
|
||||||
|
if (origin)
|
||||||
|
g_key_file_unref (origin);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config)
|
||||||
|
{
|
||||||
|
const char *options;
|
||||||
|
char *ret = NULL;
|
||||||
|
char **opts, **iter;
|
||||||
|
|
||||||
|
options = ostree_bootconfig_parser_get (config, "options");
|
||||||
|
if (!options)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
opts = g_strsplit (options, " ", -1);
|
||||||
|
for (iter = opts; *iter; iter++)
|
||||||
|
{
|
||||||
|
const char *opt = *iter;
|
||||||
|
if (g_str_has_prefix (opt, "ostree="))
|
||||||
|
{
|
||||||
|
ret = g_strdup (opt + strlen ("ostree="));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_strfreev (opts);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
list_deployments_process_one_boot_entry (OstreeSysroot *self,
|
||||||
|
OstreeBootconfigParser *config,
|
||||||
|
GPtrArray *inout_deployments,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_free char *ostree_arg = NULL;
|
||||||
|
gs_unref_object OstreeDeployment *deployment = NULL;
|
||||||
|
|
||||||
|
ostree_arg = get_ostree_kernel_arg_from_config (config);
|
||||||
|
if (ostree_arg == NULL)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"No ostree= kernel argument found");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parse_deployment (self, ostree_arg, &deployment,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ostree_deployment_set_bootconfig (deployment, config);
|
||||||
|
|
||||||
|
g_ptr_array_add (inout_deployments, g_object_ref (deployment));
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp,
|
||||||
|
gconstpointer b_pp)
|
||||||
|
{
|
||||||
|
OstreeDeployment *a = *((OstreeDeployment**)a_pp);
|
||||||
|
OstreeDeployment *b = *((OstreeDeployment**)b_pp);
|
||||||
|
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
|
||||||
|
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
|
||||||
|
const char *a_version = ostree_bootconfig_parser_get (a_bootconfig, "version");
|
||||||
|
const char *b_version = ostree_bootconfig_parser_get (b_bootconfig, "version");
|
||||||
|
|
||||||
|
if (a_version && b_version)
|
||||||
|
{
|
||||||
|
int r = strverscmp (a_version, b_version);
|
||||||
|
/* Reverse */
|
||||||
|
return -r;
|
||||||
|
}
|
||||||
|
else if (a_version)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_list_deployments:
|
||||||
|
* @sysroot: Sysroot
|
||||||
|
* @out_current_bootversion: (out): Current bootversion
|
||||||
|
* @out_deployments: (out) (element-type OstreeDeployment): Deployment list
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Enumerate all deployments, in the boot order. Also returns the
|
||||||
|
* active bootversion.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_sysroot_list_deployments (OstreeSysroot *self,
|
||||||
|
int *out_current_bootversion,
|
||||||
|
GPtrArray **out_deployments,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_ptrarray GPtrArray *boot_loader_configs = NULL;
|
||||||
|
gs_unref_ptrarray GPtrArray *ret_deployments = NULL;
|
||||||
|
guint i;
|
||||||
|
int bootversion = -1;
|
||||||
|
|
||||||
|
if (!read_current_bootversion (self, &bootversion, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!_ostree_sysroot_read_boot_loader_configs (self, bootversion, &boot_loader_configs,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret_deployments = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
||||||
|
|
||||||
|
for (i = 0; i < boot_loader_configs->len; i++)
|
||||||
|
{
|
||||||
|
OstreeBootconfigParser *config = boot_loader_configs->pdata[i];
|
||||||
|
|
||||||
|
if (!list_deployments_process_one_boot_entry (self, config, ret_deployments,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_ptr_array_sort (ret_deployments, compare_deployments_by_boot_loader_version_reversed);
|
||||||
|
for (i = 0; i < ret_deployments->len; i++)
|
||||||
|
{
|
||||||
|
OstreeDeployment *deployment = ret_deployments->pdata[i];
|
||||||
|
ostree_deployment_set_index (deployment, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
*out_current_bootversion = bootversion;
|
||||||
|
gs_transfer_out_value (out_deployments, &ret_deployments);
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_get_deployment_directory:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @deployment: A deployment
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): Path to deployment root directory
|
||||||
|
*/
|
||||||
|
GFile *
|
||||||
|
ostree_sysroot_get_deployment_directory (OstreeSysroot *self,
|
||||||
|
OstreeDeployment *deployment)
|
||||||
|
{
|
||||||
|
gs_free char *path = g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d",
|
||||||
|
ostree_deployment_get_osname (deployment),
|
||||||
|
ostree_deployment_get_csum (deployment),
|
||||||
|
ostree_deployment_get_deployserial (deployment));
|
||||||
|
return g_file_resolve_relative_path (self->path, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_get_deployment_origin_path:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @deployment: A deployment
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): Path to deployment origin file
|
||||||
|
*/
|
||||||
|
GFile *
|
||||||
|
ostree_sysroot_get_deployment_origin_path (GFile *deployment_path)
|
||||||
|
{
|
||||||
|
gs_unref_object GFile *deployment_parent = g_file_get_parent (deployment_path);
|
||||||
|
return ot_gfile_resolve_path_printf (deployment_parent,
|
||||||
|
"%s.origin",
|
||||||
|
gs_file_get_path_cached (deployment_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_get_repo:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @out_repo: (out): Repository in sysroot @self
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Retrieve the OSTree repository in sysroot @self.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_sysroot_get_repo (OstreeSysroot *self,
|
||||||
|
OstreeRepo **out_repo,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object OstreeRepo *ret_repo = NULL;
|
||||||
|
gs_unref_object GFile *repo_path = g_file_resolve_relative_path (self->path, "ostree/repo");
|
||||||
|
|
||||||
|
ret_repo = ostree_repo_new (repo_path);
|
||||||
|
if (!ostree_repo_open (ret_repo, cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
ot_transfer_out_value (out_repo, &ret_repo);
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_query_bootloader:
|
||||||
|
* @sysroot: Sysroot
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): Currently active bootloader in @sysroot
|
||||||
|
*/
|
||||||
|
OstreeBootloader *
|
||||||
|
ostree_sysroot_query_bootloader (OstreeSysroot *self)
|
||||||
|
{
|
||||||
|
OstreeBootloaderSyslinux *syslinux;
|
||||||
|
OstreeBootloaderUboot *uboot;
|
||||||
|
|
||||||
|
syslinux = ostree_bootloader_syslinux_new (self);
|
||||||
|
if (ostree_bootloader_query ((OstreeBootloader*)syslinux))
|
||||||
|
return (OstreeBootloader*) (syslinux);
|
||||||
|
|
||||||
|
uboot = ostree_bootloader_uboot_new (self);
|
||||||
|
if (ostree_bootloader_query ((OstreeBootloader*)uboot))
|
||||||
|
return (OstreeBootloader*) (uboot);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
_ostree_sysroot_join_lines (GPtrArray *lines)
|
||||||
|
{
|
||||||
|
GString *buf = g_string_new ("");
|
||||||
|
guint i;
|
||||||
|
gboolean prev_was_empty = FALSE;
|
||||||
|
|
||||||
|
for (i = 0; i < lines->len; i++)
|
||||||
|
{
|
||||||
|
const char *line = lines->pdata[i];
|
||||||
|
/* Special bit to remove extraneous empty lines */
|
||||||
|
if (*line == '\0')
|
||||||
|
{
|
||||||
|
if (prev_was_empty || i == 0)
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
prev_was_empty = TRUE;
|
||||||
|
}
|
||||||
|
g_string_append (buf, line);
|
||||||
|
g_string_append_c (buf, '\n');
|
||||||
|
}
|
||||||
|
return g_string_free (buf, FALSE);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ostree-repo.h"
|
#include "ostree-repo.h"
|
||||||
|
#include "ostree-deployment.h"
|
||||||
|
#include "ostree-bootloader.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
@ -42,5 +44,34 @@ gboolean ostree_sysroot_ensure_initialized (OstreeSysroot *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ostree_sysroot_read_current_subbootversion (OstreeSysroot *self,
|
||||||
|
int bootversion,
|
||||||
|
int *out_subbootversion,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ostree_sysroot_list_deployments (OstreeSysroot *self,
|
||||||
|
int *out_bootversion,
|
||||||
|
GPtrArray **out_deployments,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
GFile *ostree_sysroot_get_deployment_directory (OstreeSysroot *self,
|
||||||
|
OstreeDeployment *deployment);
|
||||||
|
|
||||||
|
GFile * ostree_sysroot_get_deployment_origin_path (GFile *deployment_path);
|
||||||
|
|
||||||
|
gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ostree_sysroot_get_repo (OstreeSysroot *self,
|
||||||
|
OstreeRepo **out_repo,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
OstreeBootloader *ostree_sysroot_query_bootloader (OstreeSysroot *sysroot);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ ot_admin_builtin_cleanup (int argc, char **argv, OstreeSysroot *sysroot, GCancel
|
||||||
if (!g_option_context_parse (context, &argc, &argv, error))
|
if (!g_option_context_parse (context, &argc, &argv, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ot_admin_cleanup (ostree_sysroot_get_path (sysroot), cancellable, error))
|
if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,11 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancell
|
||||||
|
|
||||||
refspec = argv[1];
|
refspec = argv[1];
|
||||||
|
|
||||||
if (!ot_admin_get_repo (ostree_sysroot_get_path (sysroot), &repo, cancellable, error))
|
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion, ¤t_deployments,
|
if (!ostree_sysroot_list_deployments (sysroot, ¤t_bootversion, ¤t_deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "While listing deployments: ");
|
g_prefix_error (error, "While listing deployments: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ ot_admin_builtin_diff (int argc, char **argv, OstreeSysroot *sysroot, GCancellab
|
||||||
|
|
||||||
repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
|
repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), &bootversion, &deployments,
|
if (!ostree_sysroot_list_deployments (sysroot, &bootversion, &deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "While listing deployments: ");
|
g_prefix_error (error, "While listing deployments: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -83,7 +83,7 @@ ot_admin_builtin_diff (int argc, char **argv, OstreeSysroot *sysroot, GCancellab
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
deployment_dir = ot_admin_get_deployment_directory (ostree_sysroot_get_path (sysroot), deployment);
|
deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment);
|
||||||
|
|
||||||
orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
|
orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
|
||||||
new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
|
new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ ot_admin_builtin_status (int argc, char **argv, OstreeSysroot *sysroot, GCancell
|
||||||
if (!g_option_context_parse (context, &argc, &argv, error))
|
if (!g_option_context_parse (context, &argc, &argv, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), &bootversion, &deployments,
|
if (!ostree_sysroot_list_deployments (sysroot, &bootversion, &deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "While listing deployments: ");
|
g_prefix_error (error, "While listing deployments: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -70,7 +70,7 @@ ot_admin_builtin_status (int argc, char **argv, OstreeSysroot *sysroot, GCancell
|
||||||
{
|
{
|
||||||
int subbootversion;
|
int subbootversion;
|
||||||
|
|
||||||
if (!ot_admin_read_current_subbootversion (ostree_sysroot_get_path (sysroot), bootversion,
|
if (!ostree_sysroot_read_current_subbootversion (sysroot, bootversion,
|
||||||
&subbootversion,
|
&subbootversion,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,8 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeSysroot *sysroot, GCance
|
||||||
deploy_index_str = argv[1];
|
deploy_index_str = argv[1];
|
||||||
deploy_index = atoi (deploy_index_str);
|
deploy_index = atoi (deploy_index_str);
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion, ¤t_deployments,
|
if (!ostree_sysroot_list_deployments (sysroot, ¤t_bootversion, ¤t_deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "While listing deployments: ");
|
g_prefix_error (error, "While listing deployments: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -103,7 +103,7 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeSysroot *sysroot, GCance
|
||||||
g_print ("Deleted deployment %s.%d\n", ostree_deployment_get_csum (target_deployment),
|
g_print ("Deleted deployment %s.%d\n", ostree_deployment_get_csum (target_deployment),
|
||||||
ostree_deployment_get_deployserial (target_deployment));
|
ostree_deployment_get_deployserial (target_deployment));
|
||||||
|
|
||||||
if (!ot_admin_cleanup (ostree_sysroot_get_path (sysroot), cancellable, error))
|
if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Performing final cleanup: ");
|
g_prefix_error (error, "Performing final cleanup: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,9 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
|
||||||
if (!g_option_context_parse (context, &argc, &argv, error))
|
if (!g_option_context_parse (context, &argc, &argv, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!ot_admin_list_deployments (ostree_sysroot_get_path (sysroot), ¤t_bootversion,
|
if (!ostree_sysroot_list_deployments (sysroot, ¤t_bootversion,
|
||||||
¤t_deployments,
|
¤t_deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "While listing deployments: ");
|
g_prefix_error (error, "While listing deployments: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -88,8 +88,8 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeSysroot *sysroot, GCancel
|
||||||
merge_deployment = ot_admin_get_merge_deployment (current_deployments, opt_osname,
|
merge_deployment = ot_admin_get_merge_deployment (current_deployments, opt_osname,
|
||||||
booted_deployment);
|
booted_deployment);
|
||||||
|
|
||||||
deployment_path = ot_admin_get_deployment_directory (ostree_sysroot_get_path (sysroot), merge_deployment);
|
deployment_path = ostree_sysroot_get_deployment_directory (sysroot, merge_deployment);
|
||||||
deployment_origin_path = ot_admin_get_deployment_origin_path (deployment_path);
|
deployment_origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
|
||||||
|
|
||||||
repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
|
repo_path = g_file_resolve_relative_path (ostree_sysroot_get_path (sysroot), "ostree/repo");
|
||||||
repo = ostree_repo_new (repo_path);
|
repo = ostree_repo_new (repo_path);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include "ot-admin-functions.h"
|
#include "ot-admin-functions.h"
|
||||||
#include "ot-admin-deploy.h"
|
#include "ot-admin-deploy.h"
|
||||||
#include "ot-bootloader-syslinux.h"
|
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "ostree-core.h"
|
#include "ostree-core.h"
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
@ -247,7 +246,7 @@ checkout_deployment_tree (GFile *sysroot,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
merge_configuration (GFile *sysroot,
|
merge_configuration (OstreeSysroot *sysroot_obj,
|
||||||
OstreeDeployment *previous_deployment,
|
OstreeDeployment *previous_deployment,
|
||||||
OstreeDeployment *deployment,
|
OstreeDeployment *deployment,
|
||||||
GFile *deployment_path,
|
GFile *deployment_path,
|
||||||
|
|
@ -267,7 +266,7 @@ merge_configuration (GFile *sysroot,
|
||||||
gs_unref_object GFile *previous_path = NULL;
|
gs_unref_object GFile *previous_path = NULL;
|
||||||
OstreeBootconfigParser *previous_bootconfig;
|
OstreeBootconfigParser *previous_bootconfig;
|
||||||
|
|
||||||
previous_path = ot_admin_get_deployment_directory (sysroot, previous_deployment);
|
previous_path = ostree_sysroot_get_deployment_directory (sysroot_obj, previous_deployment);
|
||||||
source_etc_path = g_file_resolve_relative_path (previous_path, "etc");
|
source_etc_path = g_file_resolve_relative_path (previous_path, "etc");
|
||||||
source_etc_pristine_path = g_file_resolve_relative_path (previous_path, "usr/etc");
|
source_etc_pristine_path = g_file_resolve_relative_path (previous_path, "usr/etc");
|
||||||
|
|
||||||
|
|
@ -279,7 +278,7 @@ merge_configuration (GFile *sysroot,
|
||||||
* them later.
|
* them later.
|
||||||
*/
|
*/
|
||||||
ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "options",
|
ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "options",
|
||||||
previous_options);
|
previous_options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,12 +336,15 @@ write_origin_file (GFile *sysroot,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
gs_unref_object OstreeSysroot *sysroot_obj = NULL;
|
||||||
GKeyFile *origin = ostree_deployment_get_origin (deployment);
|
GKeyFile *origin = ostree_deployment_get_origin (deployment);
|
||||||
|
|
||||||
|
sysroot_obj = ostree_sysroot_new (sysroot);
|
||||||
|
|
||||||
if (origin)
|
if (origin)
|
||||||
{
|
{
|
||||||
gs_unref_object GFile *deployment_path = ot_admin_get_deployment_directory (sysroot, deployment);
|
gs_unref_object GFile *deployment_path = ostree_sysroot_get_deployment_directory (sysroot_obj, deployment);
|
||||||
gs_unref_object GFile *origin_path = ot_admin_get_deployment_origin_path (deployment_path);
|
gs_unref_object GFile *origin_path = ostree_sysroot_get_deployment_origin_path (deployment_path);
|
||||||
gs_free char *contents = NULL;
|
gs_free char *contents = NULL;
|
||||||
gsize len;
|
gsize len;
|
||||||
|
|
||||||
|
|
@ -711,7 +713,7 @@ full_system_sync (GCancellable *cancellable,
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
swap_bootlinks (GFile *sysroot,
|
swap_bootlinks (OstreeSysroot *sysroot,
|
||||||
int current_bootversion,
|
int current_bootversion,
|
||||||
GPtrArray *new_deployments,
|
GPtrArray *new_deployments,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -720,15 +722,15 @@ swap_bootlinks (GFile *sysroot,
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
guint i;
|
guint i;
|
||||||
int old_subbootversion, new_subbootversion;
|
int old_subbootversion, new_subbootversion;
|
||||||
gs_unref_object GFile *ostree_dir = g_file_get_child (sysroot, "ostree");
|
gs_unref_object GFile *ostree_dir = g_file_get_child (ostree_sysroot_get_path (sysroot), "ostree");
|
||||||
gs_free char *ostree_bootdir_name = g_strdup_printf ("boot.%d", current_bootversion);
|
gs_free char *ostree_bootdir_name = g_strdup_printf ("boot.%d", current_bootversion);
|
||||||
gs_unref_object GFile *ostree_bootdir = g_file_resolve_relative_path (ostree_dir, ostree_bootdir_name);
|
gs_unref_object GFile *ostree_bootdir = g_file_resolve_relative_path (ostree_dir, ostree_bootdir_name);
|
||||||
gs_free char *ostree_subbootdir_name = NULL;
|
gs_free char *ostree_subbootdir_name = NULL;
|
||||||
gs_unref_object GFile *ostree_subbootdir = NULL;
|
gs_unref_object GFile *ostree_subbootdir = NULL;
|
||||||
|
|
||||||
if (!ot_admin_read_current_subbootversion (sysroot, current_bootversion,
|
if (!ostree_sysroot_read_current_subbootversion (sysroot, current_bootversion,
|
||||||
&old_subbootversion,
|
&old_subbootversion,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
new_subbootversion = old_subbootversion == 0 ? 1 : 0;
|
new_subbootversion = old_subbootversion == 0 ? 1 : 0;
|
||||||
|
|
@ -818,7 +820,7 @@ parse_os_release (const char *contents,
|
||||||
* Write out an entry in /boot/loader/entries for @deployment.
|
* Write out an entry in /boot/loader/entries for @deployment.
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
install_deployment_kernel (GFile *sysroot,
|
install_deployment_kernel (OstreeSysroot *sysroot,
|
||||||
int new_bootversion,
|
int new_bootversion,
|
||||||
OstreeDeployment *deployment,
|
OstreeDeployment *deployment,
|
||||||
guint n_deployments,
|
guint n_deployments,
|
||||||
|
|
@ -856,13 +858,13 @@ install_deployment_kernel (GFile *sysroot,
|
||||||
gsize len;
|
gsize len;
|
||||||
|
|
||||||
bootconfig = ostree_deployment_get_bootconfig (deployment);
|
bootconfig = ostree_deployment_get_bootconfig (deployment);
|
||||||
deployment_dir = ot_admin_get_deployment_directory (sysroot, deployment);
|
deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment);
|
||||||
|
|
||||||
if (!get_kernel_from_tree (deployment_dir, &tree_kernel_path, &tree_initramfs_path,
|
if (!get_kernel_from_tree (deployment_dir, &tree_kernel_path, &tree_initramfs_path,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
bootdir = g_file_get_child (sysroot, "boot");
|
bootdir = g_file_get_child (ostree_sysroot_get_path (sysroot), "boot");
|
||||||
bootcsumdir = ot_gfile_resolve_path_printf (bootdir, "ostree/%s-%s",
|
bootcsumdir = ot_gfile_resolve_path_printf (bootdir, "ostree/%s-%s",
|
||||||
osname,
|
osname,
|
||||||
bootcsum);
|
bootcsum);
|
||||||
|
|
@ -996,10 +998,11 @@ ot_admin_write_deployments (GFile *sysroot,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
guint i;
|
guint i;
|
||||||
gs_unref_object OtBootloader *bootloader = ot_admin_query_bootloader (sysroot);
|
gs_unref_object OstreeSysroot *sysroot_obj = ostree_sysroot_new (sysroot);
|
||||||
|
gs_unref_object OstreeBootloader *bootloader = ostree_sysroot_query_bootloader (sysroot_obj);
|
||||||
|
|
||||||
if (bootloader)
|
if (bootloader)
|
||||||
g_print ("Detected bootloader: %s\n", ot_bootloader_get_name (bootloader));
|
g_print ("Detected bootloader: %s\n", ostree_bootloader_get_name (bootloader));
|
||||||
else
|
else
|
||||||
g_print ("Detected bootloader: (unknown)\n");
|
g_print ("Detected bootloader: (unknown)\n");
|
||||||
|
|
||||||
|
|
@ -1011,7 +1014,7 @@ ot_admin_write_deployments (GFile *sysroot,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!swap_bootlinks (sysroot, current_bootversion,
|
if (!swap_bootlinks (sysroot_obj, current_bootversion,
|
||||||
new_deployments,
|
new_deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
|
|
@ -1024,7 +1027,7 @@ ot_admin_write_deployments (GFile *sysroot,
|
||||||
for (i = 0; i < new_deployments->len; i++)
|
for (i = 0; i < new_deployments->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = new_deployments->pdata[i];
|
OstreeDeployment *deployment = new_deployments->pdata[i];
|
||||||
if (!install_deployment_kernel (sysroot, new_bootversion,
|
if (!install_deployment_kernel (sysroot_obj, new_bootversion,
|
||||||
deployment, new_deployments->len,
|
deployment, new_deployments->len,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
|
|
@ -1034,7 +1037,7 @@ ot_admin_write_deployments (GFile *sysroot,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Swap bootlinks for *new* version */
|
/* Swap bootlinks for *new* version */
|
||||||
if (!swap_bootlinks (sysroot, new_bootversion, new_deployments,
|
if (!swap_bootlinks (sysroot_obj, new_bootversion, new_deployments,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Generating new bootlinks: ");
|
g_prefix_error (error, "Generating new bootlinks: ");
|
||||||
|
|
@ -1047,8 +1050,8 @@ ot_admin_write_deployments (GFile *sysroot,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bootloader && !ot_bootloader_write_config (bootloader, new_bootversion,
|
if (bootloader && !ostree_bootloader_write_config (bootloader, new_bootversion,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Bootloader write config: ");
|
g_prefix_error (error, "Bootloader write config: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -1086,6 +1089,7 @@ ot_admin_deploy (GFile *sysroot,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
OstreeDeployment *new_deployment;
|
OstreeDeployment *new_deployment;
|
||||||
|
gs_unref_object OstreeSysroot *sysroot_obj = NULL;
|
||||||
gs_unref_object OstreeDeployment *merge_deployment = NULL;
|
gs_unref_object OstreeDeployment *merge_deployment = NULL;
|
||||||
gs_unref_object OstreeRepo *repo = NULL;
|
gs_unref_object OstreeRepo *repo = NULL;
|
||||||
gs_unref_object GFile *commit_root = NULL;
|
gs_unref_object GFile *commit_root = NULL;
|
||||||
|
|
@ -1097,7 +1101,9 @@ ot_admin_deploy (GFile *sysroot,
|
||||||
gs_unref_ptrarray GPtrArray *new_deployments = NULL;
|
gs_unref_ptrarray GPtrArray *new_deployments = NULL;
|
||||||
int new_bootversion;
|
int new_bootversion;
|
||||||
|
|
||||||
if (!ot_admin_get_repo (sysroot, &repo, cancellable, error))
|
sysroot_obj = ostree_sysroot_new (sysroot);
|
||||||
|
|
||||||
|
if (!ostree_sysroot_get_repo (sysroot_obj, &repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Here we perform cleanup of any leftover data from previous
|
/* Here we perform cleanup of any leftover data from previous
|
||||||
|
|
@ -1107,7 +1113,7 @@ ot_admin_deploy (GFile *sysroot,
|
||||||
* TODO: Add /ostree/transaction file, and only do this cleanup if
|
* TODO: Add /ostree/transaction file, and only do this cleanup if
|
||||||
* we find it.
|
* we find it.
|
||||||
*/
|
*/
|
||||||
if (!ot_admin_cleanup (sysroot, cancellable, error))
|
if (!ostree_sysroot_cleanup (sysroot_obj, cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Performing initial cleanup: ");
|
g_prefix_error (error, "Performing initial cleanup: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -1173,7 +1179,7 @@ ot_admin_deploy (GFile *sysroot,
|
||||||
bootconfig = ostree_bootconfig_parser_new ();
|
bootconfig = ostree_bootconfig_parser_new ();
|
||||||
ostree_deployment_set_bootconfig (new_deployment, bootconfig);
|
ostree_deployment_set_bootconfig (new_deployment, bootconfig);
|
||||||
|
|
||||||
if (!merge_configuration (sysroot, merge_deployment, new_deployment,
|
if (!merge_configuration (sysroot_obj, merge_deployment, new_deployment,
|
||||||
new_deployment_path,
|
new_deployment_path,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
{
|
{
|
||||||
|
|
@ -1231,7 +1237,7 @@ ot_admin_deploy (GFile *sysroot,
|
||||||
|
|
||||||
/* And finally, cleanup of any leftover data.
|
/* And finally, cleanup of any leftover data.
|
||||||
*/
|
*/
|
||||||
if (!ot_admin_cleanup (sysroot, cancellable, error))
|
if (!ostree_sysroot_cleanup (sysroot_obj, cancellable, error))
|
||||||
{
|
{
|
||||||
g_prefix_error (error, "Performing final cleanup: ");
|
g_prefix_error (error, "Performing final cleanup: ");
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <ostree.h>
|
#include <ostree.h>
|
||||||
#include "ot-bootloader.h"
|
|
||||||
#include "ot-ordered-hash.h"
|
#include "ot-ordered-hash.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ot-admin-functions.h"
|
#include "ot-admin-functions.h"
|
||||||
#include "ot-bootloader-syslinux.h"
|
|
||||||
#include "ot-bootloader-uboot.h"
|
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
#include "libgsystem.h"
|
#include "libgsystem.h"
|
||||||
|
|
@ -84,14 +82,6 @@ ot_admin_kernel_arg_string_serialize (OtOrderedHash *ohash)
|
||||||
return g_string_free (buf, FALSE);
|
return g_string_free (buf, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
match_info_cleanup (void *loc)
|
|
||||||
{
|
|
||||||
GMatchInfo **match = (GMatchInfo**)loc;
|
|
||||||
if (*match) g_match_info_unref (*match);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ot_admin_check_os (GFile *sysroot,
|
ot_admin_check_os (GFile *sysroot,
|
||||||
const char *osname,
|
const char *osname,
|
||||||
|
|
@ -114,187 +104,6 @@ ot_admin_check_os (GFile *sysroot,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_bootlink (const char *bootlink,
|
|
||||||
int *out_entry_bootversion,
|
|
||||||
char **out_osname,
|
|
||||||
char **out_bootcsum,
|
|
||||||
int *out_treebootserial,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
__attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL;
|
|
||||||
gs_free char *bootversion_str = NULL;
|
|
||||||
gs_free char *treebootserial_str = NULL;
|
|
||||||
|
|
||||||
static gsize regex_initialized;
|
|
||||||
static GRegex *regex;
|
|
||||||
|
|
||||||
if (g_once_init_enter (®ex_initialized))
|
|
||||||
{
|
|
||||||
regex = g_regex_new ("^/ostree/boot.([01])/([^/]+)/([^/]+)/([0-9]+)$", 0, 0, NULL);
|
|
||||||
g_assert (regex);
|
|
||||||
g_once_init_leave (®ex_initialized, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_regex_match (regex, bootlink, 0, &match))
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Invalid ostree= argument '%s', expected ostree=/ostree/boot.BOOTVERSION/OSNAME/BOOTCSUM/TREESERIAL", bootlink);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
bootversion_str = g_match_info_fetch (match, 1);
|
|
||||||
*out_entry_bootversion = (int)g_ascii_strtoll (bootversion_str, NULL, 10);
|
|
||||||
*out_osname = g_match_info_fetch (match, 2);
|
|
||||||
*out_bootcsum = g_match_info_fetch (match, 3);
|
|
||||||
treebootserial_str = g_match_info_fetch (match, 4);
|
|
||||||
*out_treebootserial = (int)g_ascii_strtoll (treebootserial_str, NULL, 10);
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
ot_admin_parse_deploy_path_name (const char *name,
|
|
||||||
char **out_csum,
|
|
||||||
int *out_serial,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
__attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL;
|
|
||||||
gs_free char *serial_str = NULL;
|
|
||||||
|
|
||||||
static gsize regex_initialized;
|
|
||||||
static GRegex *regex;
|
|
||||||
|
|
||||||
if (g_once_init_enter (®ex_initialized))
|
|
||||||
{
|
|
||||||
regex = g_regex_new ("^([0-9a-f]+)\\.([0-9]+)$", 0, 0, NULL);
|
|
||||||
g_assert (regex);
|
|
||||||
g_once_init_leave (®ex_initialized, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_regex_match (regex, name, 0, &match))
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Invalid deploy name '%s', expected CHECKSUM.TREESERIAL", name);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
*out_csum = g_match_info_fetch (match, 1);
|
|
||||||
serial_str = g_match_info_fetch (match, 2);
|
|
||||||
*out_serial = (int)g_ascii_strtoll (serial_str, NULL, 10);
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
GFile *
|
|
||||||
ot_admin_get_deployment_origin_path (GFile *deployment_path)
|
|
||||||
{
|
|
||||||
gs_unref_object GFile *deployment_parent = g_file_get_parent (deployment_path);
|
|
||||||
return ot_gfile_resolve_path_printf (deployment_parent,
|
|
||||||
"%s.origin",
|
|
||||||
gs_file_get_path_cached (deployment_path));
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_origin (GFile *sysroot,
|
|
||||||
GFile *deployment_path,
|
|
||||||
GKeyFile **out_origin,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
GKeyFile *ret_origin = NULL;
|
|
||||||
gs_unref_object GFile *origin_path = ot_admin_get_deployment_origin_path (deployment_path);
|
|
||||||
gs_free char *origin_contents = NULL;
|
|
||||||
|
|
||||||
if (!ot_gfile_load_contents_utf8_allow_noent (origin_path, &origin_contents,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (origin_contents)
|
|
||||||
{
|
|
||||||
ret_origin = g_key_file_new ();
|
|
||||||
if (!g_key_file_load_from_data (ret_origin, origin_contents, -1, 0, error))
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value (out_origin, &ret_origin);
|
|
||||||
out:
|
|
||||||
if (error)
|
|
||||||
g_prefix_error (error, "Parsing %s: ", gs_file_get_path_cached (origin_path));
|
|
||||||
if (ret_origin)
|
|
||||||
g_key_file_unref (ret_origin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_deployment (GFile *sysroot,
|
|
||||||
const char *boot_link,
|
|
||||||
OstreeDeployment **out_deployment,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
const char *relative_boot_link;
|
|
||||||
gs_unref_object OstreeDeployment *ret_deployment = NULL;
|
|
||||||
int entry_boot_version;
|
|
||||||
int treebootserial = -1;
|
|
||||||
int deployserial = -1;
|
|
||||||
gs_free char *osname = NULL;
|
|
||||||
gs_free char *bootcsum = NULL;
|
|
||||||
gs_free char *treecsum = NULL;
|
|
||||||
gs_unref_object GFile *treebootserial_link = NULL;
|
|
||||||
gs_unref_object GFileInfo *treebootserial_info = NULL;
|
|
||||||
gs_unref_object GFile *treebootserial_target = NULL;
|
|
||||||
GKeyFile *origin = NULL;
|
|
||||||
|
|
||||||
if (!parse_bootlink (boot_link, &entry_boot_version,
|
|
||||||
&osname, &bootcsum, &treebootserial,
|
|
||||||
error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
relative_boot_link = boot_link;
|
|
||||||
if (*relative_boot_link == '/')
|
|
||||||
relative_boot_link++;
|
|
||||||
treebootserial_link = g_file_resolve_relative_path (sysroot, relative_boot_link);
|
|
||||||
treebootserial_info = g_file_query_info (treebootserial_link, OSTREE_GIO_FAST_QUERYINFO,
|
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
||||||
cancellable, error);
|
|
||||||
if (!treebootserial_info)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ot_gfile_get_symlink_target_from_info (treebootserial_link, treebootserial_info,
|
|
||||||
&treebootserial_target, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ot_admin_parse_deploy_path_name (gs_file_get_basename_cached (treebootserial_target),
|
|
||||||
&treecsum, &deployserial, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!parse_origin (sysroot, treebootserial_target, &origin,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret_deployment = ostree_deployment_new (-1, osname, treecsum, deployserial,
|
|
||||||
bootcsum, treebootserial);
|
|
||||||
if (origin)
|
|
||||||
ostree_deployment_set_origin (ret_deployment, origin);
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value (out_deployment, &ret_deployment);
|
|
||||||
out:
|
|
||||||
if (origin)
|
|
||||||
g_key_file_unref (origin);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_kernel_commandline (OtOrderedHash **out_args,
|
parse_kernel_commandline (OtOrderedHash **out_args,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
@ -336,6 +145,7 @@ ot_admin_find_booted_deployment (GFile *target_sysroot,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_unref_object GFile *active_root = g_file_new_for_path ("/");
|
gs_unref_object GFile *active_root = g_file_new_for_path ("/");
|
||||||
|
gs_unref_object OstreeSysroot *active_deployment_root = ostree_sysroot_new_default ();
|
||||||
gs_unref_object OstreeDeployment *ret_deployment = NULL;
|
gs_unref_object OstreeDeployment *ret_deployment = NULL;
|
||||||
|
|
||||||
if (g_file_equal (active_root, target_sysroot))
|
if (g_file_equal (active_root, target_sysroot))
|
||||||
|
|
@ -359,7 +169,7 @@ ot_admin_find_booted_deployment (GFile *target_sysroot,
|
||||||
for (i = 0; i < deployments->len; i++)
|
for (i = 0; i < deployments->len; i++)
|
||||||
{
|
{
|
||||||
OstreeDeployment *deployment = deployments->pdata[i];
|
OstreeDeployment *deployment = deployments->pdata[i];
|
||||||
gs_unref_object GFile *deployment_path = ot_admin_get_deployment_directory (active_root, deployment);
|
gs_unref_object GFile *deployment_path = ostree_sysroot_get_deployment_directory (active_deployment_root, deployment);
|
||||||
guint32 device;
|
guint32 device;
|
||||||
guint64 inode;
|
guint64 inode;
|
||||||
|
|
||||||
|
|
@ -451,321 +261,6 @@ ot_admin_get_merge_deployment (GPtrArray *deployments,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
read_current_bootversion (GFile *sysroot,
|
|
||||||
int *out_bootversion,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_unref_object GFile *boot_loader_path = g_file_resolve_relative_path (sysroot, "boot/loader");
|
|
||||||
gs_unref_object GFileInfo *info = NULL;
|
|
||||||
const char *target;
|
|
||||||
int ret_bootversion;
|
|
||||||
|
|
||||||
if (!ot_gfile_query_info_allow_noent (boot_loader_path, OSTREE_GIO_FAST_QUERYINFO,
|
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
||||||
&info,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (info == NULL)
|
|
||||||
ret_bootversion = 0;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (g_file_info_get_file_type (info) != G_FILE_TYPE_SYMBOLIC_LINK)
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Not a symbolic link: %s", gs_file_get_path_cached (boot_loader_path));
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
target = g_file_info_get_symlink_target (info);
|
|
||||||
if (g_strcmp0 (target, "loader.0") == 0)
|
|
||||||
ret_bootversion = 0;
|
|
||||||
else if (g_strcmp0 (target, "loader.1") == 0)
|
|
||||||
ret_bootversion = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Invalid target '%s' in %s", target, gs_file_get_path_cached (boot_loader_path));
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
*out_bootversion = ret_bootversion;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
ot_admin_read_current_subbootversion (GFile *sysroot,
|
|
||||||
int bootversion,
|
|
||||||
int *out_subbootversion,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_unref_object GFile *ostree_dir = g_file_get_child (sysroot, "ostree");
|
|
||||||
gs_free char *ostree_bootdir_name = g_strdup_printf ("boot.%d", bootversion);
|
|
||||||
gs_unref_object GFile *ostree_bootdir = g_file_resolve_relative_path (ostree_dir, ostree_bootdir_name);
|
|
||||||
gs_unref_object GFile *ostree_subbootdir = NULL;
|
|
||||||
|
|
||||||
if (!ot_gfile_query_symlink_target_allow_noent (ostree_bootdir, &ostree_subbootdir,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (ostree_subbootdir == NULL)
|
|
||||||
{
|
|
||||||
*out_subbootversion = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const char *current_subbootdir_name = gs_file_get_basename_cached (ostree_subbootdir);
|
|
||||||
if (g_str_has_suffix (current_subbootdir_name, ".0"))
|
|
||||||
*out_subbootversion = 0;
|
|
||||||
else if (g_str_has_suffix (current_subbootdir_name, ".1"))
|
|
||||||
*out_subbootversion = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Invalid target '%s' in %s",
|
|
||||||
gs_file_get_path_cached (ostree_subbootdir),
|
|
||||||
gs_file_get_path_cached (ostree_bootdir));
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
ot_admin_read_boot_loader_configs (GFile *sysroot,
|
|
||||||
int bootversion,
|
|
||||||
GPtrArray **out_loader_configs,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_unref_object GFileEnumerator *dir_enum = NULL;
|
|
||||||
gs_unref_object GFile *loader_entries_dir = NULL;
|
|
||||||
gs_unref_ptrarray GPtrArray *ret_loader_configs = NULL;
|
|
||||||
GError *temp_error = NULL;
|
|
||||||
|
|
||||||
loader_entries_dir = ot_gfile_resolve_path_printf (sysroot, "boot/loader.%d/entries",
|
|
||||||
bootversion);
|
|
||||||
ret_loader_configs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
|
||||||
|
|
||||||
dir_enum = g_file_enumerate_children (loader_entries_dir, OSTREE_GIO_FAST_QUERYINFO,
|
|
||||||
0, NULL, &temp_error);
|
|
||||||
if (!dir_enum)
|
|
||||||
{
|
|
||||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
|
||||||
{
|
|
||||||
g_clear_error (&temp_error);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_propagate_error (error, temp_error);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (TRUE)
|
|
||||||
{
|
|
||||||
GFileInfo *file_info;
|
|
||||||
GFile *child;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
if (!gs_file_enumerator_iterate (dir_enum, &file_info, &child,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
if (file_info == NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
name = g_file_info_get_name (file_info);
|
|
||||||
|
|
||||||
if (g_str_has_prefix (name, "ostree-") &&
|
|
||||||
g_str_has_suffix (name, ".conf") &&
|
|
||||||
g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
|
|
||||||
{
|
|
||||||
gs_unref_object OstreeBootconfigParser *config = ostree_bootconfig_parser_new ();
|
|
||||||
|
|
||||||
if (!ostree_bootconfig_parser_parse (config, child, cancellable, error))
|
|
||||||
{
|
|
||||||
g_prefix_error (error, "Parsing %s: ", gs_file_get_path_cached (child));
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ptr_array_add (ret_loader_configs, g_object_ref (config));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
done:
|
|
||||||
ot_transfer_out_value (out_loader_configs, &ret_loader_configs);
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
get_ostree_kernel_arg_from_config (OstreeBootconfigParser *config)
|
|
||||||
{
|
|
||||||
const char *options;
|
|
||||||
char *ret = NULL;
|
|
||||||
char **opts, **iter;
|
|
||||||
|
|
||||||
options = ostree_bootconfig_parser_get (config, "options");
|
|
||||||
if (!options)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
opts = g_strsplit (options, " ", -1);
|
|
||||||
for (iter = opts; *iter; iter++)
|
|
||||||
{
|
|
||||||
const char *opt = *iter;
|
|
||||||
if (g_str_has_prefix (opt, "ostree="))
|
|
||||||
{
|
|
||||||
ret = g_strdup (opt + strlen ("ostree="));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_strfreev (opts);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
list_deployments_process_one_boot_entry (GFile *sysroot,
|
|
||||||
OstreeBootconfigParser *config,
|
|
||||||
GPtrArray *inout_deployments,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_free char *ostree_arg = NULL;
|
|
||||||
gs_unref_object OstreeDeployment *deployment = NULL;
|
|
||||||
|
|
||||||
ostree_arg = get_ostree_kernel_arg_from_config (config);
|
|
||||||
if (ostree_arg == NULL)
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"No ostree= kernel argument found");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parse_deployment (sysroot, ostree_arg, &deployment,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ostree_deployment_set_bootconfig (deployment, config);
|
|
||||||
|
|
||||||
g_ptr_array_add (inout_deployments, g_object_ref (deployment));
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
compare_deployments_by_boot_loader_version_reversed (gconstpointer a_pp,
|
|
||||||
gconstpointer b_pp)
|
|
||||||
{
|
|
||||||
OstreeDeployment *a = *((OstreeDeployment**)a_pp);
|
|
||||||
OstreeDeployment *b = *((OstreeDeployment**)b_pp);
|
|
||||||
OstreeBootconfigParser *a_bootconfig = ostree_deployment_get_bootconfig (a);
|
|
||||||
OstreeBootconfigParser *b_bootconfig = ostree_deployment_get_bootconfig (b);
|
|
||||||
const char *a_version = ostree_bootconfig_parser_get (a_bootconfig, "version");
|
|
||||||
const char *b_version = ostree_bootconfig_parser_get (b_bootconfig, "version");
|
|
||||||
|
|
||||||
if (a_version && b_version)
|
|
||||||
{
|
|
||||||
int r = strverscmp (a_version, b_version);
|
|
||||||
/* Reverse */
|
|
||||||
return -r;
|
|
||||||
}
|
|
||||||
else if (a_version)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
|
||||||
ot_admin_list_deployments (GFile *sysroot,
|
|
||||||
int *out_current_bootversion,
|
|
||||||
GPtrArray **out_deployments,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_unref_ptrarray GPtrArray *boot_loader_configs = NULL;
|
|
||||||
gs_unref_ptrarray GPtrArray *ret_deployments = NULL;
|
|
||||||
guint i;
|
|
||||||
int bootversion = -1;
|
|
||||||
|
|
||||||
if (!read_current_bootversion (sysroot, &bootversion, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (!ot_admin_read_boot_loader_configs (sysroot, bootversion, &boot_loader_configs,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret_deployments = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
|
||||||
|
|
||||||
for (i = 0; i < boot_loader_configs->len; i++)
|
|
||||||
{
|
|
||||||
OstreeBootconfigParser *config = boot_loader_configs->pdata[i];
|
|
||||||
|
|
||||||
if (!list_deployments_process_one_boot_entry (sysroot, config, ret_deployments,
|
|
||||||
cancellable, error))
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_ptr_array_sort (ret_deployments, compare_deployments_by_boot_loader_version_reversed);
|
|
||||||
for (i = 0; i < ret_deployments->len; i++)
|
|
||||||
{
|
|
||||||
OstreeDeployment *deployment = ret_deployments->pdata[i];
|
|
||||||
ostree_deployment_set_index (deployment, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
*out_current_bootversion = bootversion;
|
|
||||||
ot_transfer_out_value (out_deployments, &ret_deployments);
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
GFile *
|
|
||||||
ot_admin_get_deployment_directory (GFile *sysroot,
|
|
||||||
OstreeDeployment *deployment)
|
|
||||||
{
|
|
||||||
gs_free char *path = g_strdup_printf ("ostree/deploy/%s/deploy/%s.%d",
|
|
||||||
ostree_deployment_get_osname (deployment),
|
|
||||||
ostree_deployment_get_csum (deployment),
|
|
||||||
ostree_deployment_get_deployserial (deployment));
|
|
||||||
return g_file_resolve_relative_path (sysroot, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
OtBootloader *
|
|
||||||
ot_admin_query_bootloader (GFile *sysroot)
|
|
||||||
{
|
|
||||||
OtBootloaderSyslinux *syslinux;
|
|
||||||
OtBootloaderUboot *uboot;
|
|
||||||
|
|
||||||
syslinux = ot_bootloader_syslinux_new (sysroot);
|
|
||||||
if (ot_bootloader_query ((OtBootloader*)syslinux))
|
|
||||||
return (OtBootloader*) (syslinux);
|
|
||||||
|
|
||||||
uboot = ot_bootloader_uboot_new (sysroot);
|
|
||||||
if (ot_bootloader_query ((OtBootloader*)uboot))
|
|
||||||
return (OtBootloader*) (uboot);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
GKeyFile *
|
GKeyFile *
|
||||||
ot_origin_new_from_refspec (const char *refspec)
|
ot_origin_new_from_refspec (const char *refspec)
|
||||||
{
|
{
|
||||||
|
|
@ -773,23 +268,3 @@ ot_origin_new_from_refspec (const char *refspec)
|
||||||
g_key_file_set_string (ret, "origin", "refspec", refspec);
|
g_key_file_set_string (ret, "origin", "refspec", refspec);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
ot_admin_get_repo (GFile *sysroot,
|
|
||||||
OstreeRepo **out_repo,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean ret = FALSE;
|
|
||||||
gs_unref_object OstreeRepo *ret_repo = NULL;
|
|
||||||
gs_unref_object GFile *repo_path = g_file_resolve_relative_path (sysroot, "ostree/repo");
|
|
||||||
|
|
||||||
ret_repo = ostree_repo_new (repo_path);
|
|
||||||
if (!ostree_repo_open (ret_repo, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
ot_transfer_out_value (out_repo, &ret_repo);
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <ostree.h>
|
#include <ostree.h>
|
||||||
#include "ot-bootloader.h"
|
|
||||||
#include "ot-ordered-hash.h"
|
#include "ot-ordered-hash.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
@ -37,13 +36,6 @@ gboolean ot_admin_util_get_devino (GFile *path,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
char *ot_admin_join_lines (GPtrArray *lines);
|
|
||||||
|
|
||||||
gboolean ot_admin_parse_deploy_path_name (const char *name,
|
|
||||||
char **out_csum,
|
|
||||||
int *out_serial,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_ensure_initialized (GFile *ostree_dir,
|
gboolean ot_admin_ensure_initialized (GFile *ostree_dir,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
@ -56,26 +48,6 @@ gboolean ot_admin_check_os (GFile *sysroot,
|
||||||
OtOrderedHash *ot_admin_parse_kernel_args (const char *options);
|
OtOrderedHash *ot_admin_parse_kernel_args (const char *options);
|
||||||
char * ot_admin_kernel_arg_string_serialize (OtOrderedHash *ohash);
|
char * ot_admin_kernel_arg_string_serialize (OtOrderedHash *ohash);
|
||||||
|
|
||||||
OtBootloader *ot_admin_query_bootloader (GFile *sysroot);
|
|
||||||
|
|
||||||
gboolean ot_admin_read_current_subbootversion (GFile *sysroot,
|
|
||||||
int bootversion,
|
|
||||||
int *out_subbootversion,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_read_boot_loader_configs (GFile *boot_dir,
|
|
||||||
int bootversion,
|
|
||||||
GPtrArray **out_loader_configs,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_list_deployments (GFile *sysroot,
|
|
||||||
int *out_bootversion,
|
|
||||||
GPtrArray **out_deployments,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_find_booted_deployment (GFile *sysroot,
|
gboolean ot_admin_find_booted_deployment (GFile *sysroot,
|
||||||
GPtrArray *deployments,
|
GPtrArray *deployments,
|
||||||
OstreeDeployment **out_deployment,
|
OstreeDeployment **out_deployment,
|
||||||
|
|
@ -98,20 +70,6 @@ OstreeDeployment *ot_admin_get_merge_deployment (GPtrArray *deployment_l
|
||||||
const char *osname,
|
const char *osname,
|
||||||
OstreeDeployment *booted_deployment);
|
OstreeDeployment *booted_deployment);
|
||||||
|
|
||||||
GFile *ot_admin_get_deployment_origin_path (GFile *deployment_path);
|
|
||||||
|
|
||||||
GFile *ot_admin_get_deployment_directory (GFile *sysroot,
|
|
||||||
OstreeDeployment *deployment);
|
|
||||||
|
|
||||||
gboolean ot_admin_get_repo (GFile *sysroot,
|
|
||||||
OstreeRepo **out_repo,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_cleanup (GFile *sysroot,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
gboolean ot_admin_get_default_ostree_dir (GFile **out_ostree_dir,
|
gboolean ot_admin_get_default_ostree_dir (GFile **out_ostree_dir,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
|
||||||
|
|
@ -76,26 +76,3 @@ ot_admin_util_get_devino (GFile *path,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
|
||||||
ot_admin_join_lines (GPtrArray *lines)
|
|
||||||
{
|
|
||||||
GString *buf = g_string_new ("");
|
|
||||||
guint i;
|
|
||||||
gboolean prev_was_empty = FALSE;
|
|
||||||
|
|
||||||
for (i = 0; i < lines->len; i++)
|
|
||||||
{
|
|
||||||
const char *line = lines->pdata[i];
|
|
||||||
/* Special bit to remove extraneous empty lines */
|
|
||||||
if (*line == '\0')
|
|
||||||
{
|
|
||||||
if (prev_was_empty || i == 0)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
prev_was_empty = TRUE;
|
|
||||||
}
|
|
||||||
g_string_append (buf, line);
|
|
||||||
g_string_append_c (buf, '\n');
|
|
||||||
}
|
|
||||||
return g_string_free (buf, FALSE);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
||||||
*
|
|
||||||
* Copyright (C) 2013 Colin Walters <walters@verbum.org>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published
|
|
||||||
* by the Free Software Foundation; either version 2 of the licence or (at
|
|
||||||
* your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General
|
|
||||||
* Public License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gio/gio.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
#define OT_TYPE_BOOTLOADER (ot_bootloader_get_type ())
|
|
||||||
#define OT_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OT_TYPE_BOOTLOADER, OtBootloader))
|
|
||||||
#define OT_IS_BOOTLOADER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OT_TYPE_BOOTLOADER))
|
|
||||||
#define OT_BOOTLOADER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), OT_TYPE_BOOTLOADER, OtBootloaderInterface))
|
|
||||||
|
|
||||||
typedef struct _OtBootloader OtBootloader;
|
|
||||||
typedef struct _OtBootloaderInterface OtBootloaderInterface;
|
|
||||||
|
|
||||||
struct _OtBootloaderInterface
|
|
||||||
{
|
|
||||||
GTypeInterface g_iface;
|
|
||||||
|
|
||||||
/* virtual functions */
|
|
||||||
gboolean (* query) (OtBootloader *self);
|
|
||||||
const char * (* get_name) (OtBootloader *self);
|
|
||||||
gboolean (* write_config) (OtBootloader *self,
|
|
||||||
int bootversion,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
};
|
|
||||||
|
|
||||||
GType ot_bootloader_get_type (void) G_GNUC_CONST;
|
|
||||||
|
|
||||||
gboolean ot_bootloader_query (OtBootloader *self);
|
|
||||||
|
|
||||||
const char *ot_bootloader_get_name (OtBootloader *self);
|
|
||||||
|
|
||||||
gboolean ot_bootloader_write_config (OtBootloader *self,
|
|
||||||
int bootversion,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue