lib: Add ostree_sysroot_load_if_changed() API
This will allow daemons like rpm-ostree to detect if there are any new deployments efficiently, in combination with using inotify. If there are any changes, rpm-ostree wants publish them on DBus. While we're here, add some changes to start doing unit C testing of the sysroot API.
This commit is contained in:
1 parent
ebd0370976
commit
fea786cb2d
10 files changed
+179
-24
No files matched your search
@@ -317,4 +317,5 @@ global:
|
||||
ostree_repo_get_dfd;
|
||||
ostree_repo_list_refs_ext;
|
||||
ostree_sysroot_init_osname;
|
||||
ostree_sysroot_load_if_changed;
|
||||
} LIBOSTREE_2016.3;
|
||||
@@ -49,6 +49,7 @@ struct OstreeSysroot {
|
||||
int bootversion;
|
||||
int subbootversion;
|
||||
OstreeDeployment *booted_deployment;
|
||||
struct timespec loaded_ts;
|
||||
|
||||
/* Only access through ostree_sysroot_get_repo() */
|
||||
OstreeRepo *repo;
|
||||
|
||||
@@ -793,19 +793,24 @@ gboolean
|
||||
ostree_sysroot_load (OstreeSysroot *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
return ostree_sysroot_load_if_changed (self, NULL, cancellable, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_sysroot_load_if_changed (OstreeSysroot *self,
|
||||
gboolean *out_changed,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
guint i;
|
||||
int bootversion = 0;
|
||||
int subbootversion = 0;
|
||||
struct stat stbuf;
|
||||
g_autoptr(GPtrArray) boot_loader_configs = NULL;
|
||||
g_autoptr(GPtrArray) deployments = NULL;
|
||||
|
||||
g_clear_pointer (&self->deployments, g_ptr_array_unref);
|
||||
g_clear_pointer (&self->booted_deployment, g_object_unref);
|
||||
self->bootversion = -1;
|
||||
self->subbootversion = -1;
|
||||
|
||||
if (!ensure_sysroot_fd (self, error))
|
||||
goto out;
|
||||
|
||||
@@ -816,6 +821,28 @@ ostree_sysroot_load (OstreeSysroot *self,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0) < 0)
|
||||
{
|
||||
glnx_set_error_from_errno (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (out_changed)
|
||||
{
|
||||
if (self->loaded_ts.tv_sec == stbuf.st_mtim.tv_sec &&
|
||||
self->loaded_ts.tv_nsec == stbuf.st_mtim.tv_nsec)
|
||||
{
|
||||
*out_changed = FALSE;
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
g_clear_pointer (&self->deployments, g_ptr_array_unref);
|
||||
g_clear_pointer (&self->booted_deployment, g_object_unref);
|
||||
self->bootversion = -1;
|
||||
self->subbootversion = -1;
|
||||
|
||||
if (!_ostree_sysroot_read_boot_loader_configs (self, bootversion, &boot_loader_configs,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
@@ -847,8 +874,11 @@ ostree_sysroot_load (OstreeSysroot *self,
|
||||
self->deployments = deployments;
|
||||
deployments = NULL; /* Transfer ownership */
|
||||
self->loaded = TRUE;
|
||||
self->loaded_ts = stbuf.st_mtim;
|
||||
|
||||
ret = TRUE;
|
||||
if (out_changed)
|
||||
*out_changed = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,12 @@ gboolean ostree_sysroot_load (OstreeSysroot *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
gboolean ostree_sysroot_load_if_changed (OstreeSysroot *self,
|
||||
gboolean *out_changed,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
void ostree_sysroot_unload (OstreeSysroot *self);
|
||||
|
||||
|
||||
Reference in new issue
Block a user