sysroot: Add an unload() API
authorColin Walters <walters@verbum.org>
Thu, 13 Aug 2015 16:43:14 +0000 (12:43 -0400)
committerColin Walters <walters@verbum.org>
Thu, 13 Aug 2015 16:43:14 +0000 (12:43 -0400)
This will be used by gnome-continuous at least to drop the reference
to the fd so that unmounting can proceed.  See
https://git.gnome.org/browse/gnome-continuous/commit/?id=95e9910ea288d302509ca667e0d190dd89377dd5

src/libostree/ostree-sysroot.c
src/libostree/ostree-sysroot.h

index c7b3e474fa8e9b241f0ebb9a2e657643cd086920..7a4686d8e3fb9a0dcc3e6474d856990d4c10d1d5 100644 (file)
@@ -72,8 +72,7 @@ ostree_sysroot_finalize (GObject *object)
 
   glnx_release_lock_file (&self->lock);
 
-  if (self->sysroot_fd != -1)
-    (void) close (self->sysroot_fd);
+  (void) ostree_sysroot_unload (self);
 
   G_OBJECT_CLASS (ostree_sysroot_parent_class)->finalize (object);
 }
@@ -223,6 +222,24 @@ ostree_sysroot_get_fd (OstreeSysroot *self)
   return self->sysroot_fd;
 }
 
+/**
+ * ostree_sysroot_unload:
+ * @self: Sysroot
+ *
+ * Release any resources such as file descriptors referring to the
+ * root directory of this sysroot.  Normally, those resources are
+ * cleared by finalization, but in garbage collected languages that
+ * may not be predictable.
+ *
+ * This undoes the effect of `ostree_sysroot_load()`.
+ */
+void
+ostree_sysroot_unload (OstreeSysroot  *self)
+{
+  if (self->sysroot_fd != -1)
+    (void) close (self->sysroot_fd);
+}
+
 /**
  * ostree_sysroot_ensure_initialized:
  * @self: Sysroot
index ce128bbafeea126c78091558fb9b95ad5b048f7b..2fbc23b37cee9ab068911d5643f05a003e513965 100644 (file)
@@ -45,6 +45,8 @@ gboolean ostree_sysroot_load (OstreeSysroot  *self,
                               GCancellable   *cancellable,
                               GError        **error);
 
+void ostree_sysroot_unload (OstreeSysroot  *self);
+
 gboolean ostree_sysroot_ensure_initialized (OstreeSysroot  *self,
                                             GCancellable   *cancellable,
                                             GError        **error);