[ostree] Add an API to set/unset a deployment tree's mutability



commit 42744628b3bce512e6024ca79804e50275bf1a04
Author: Colin Walters <walters verbum org>
Date:   Thu Feb 12 09:13:30 2015 -0500

    Add an API to set/unset a deployment tree's mutability
    
    This will be used by rpm-ostree to unset the immutable bit temporarily
    in order to do package layering.  We could add an API to deploy a tree
    without the immutable bit, but this is simpler.

 src/libostree/ostree-sysroot-deploy.c |   40 +++++++++++++++++++++++++++++++-
 src/libostree/ostree-sysroot.h        |    6 +++++
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
index 4d59a03..142a9fc 100644
--- a/src/libostree/ostree-sysroot-deploy.c
+++ b/src/libostree/ostree-sysroot-deploy.c
@@ -1829,8 +1829,8 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
                                       cancellable, error))
     goto out;
 
-  if (!_ostree_linuxfs_alter_immutable_flag (new_deployment_path, TRUE,
-                                             cancellable, error))
+  if (!ostree_sysroot_deployment_set_mutable (self, new_deployment, FALSE,
+                                              cancellable, error))
     goto out;
 
   { ostree_cleanup_sepolicy_fscreatecon gpointer dummy = NULL;
@@ -1927,3 +1927,39 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot     *self,
  out:
   return ret;
 }
+
+/**
+ * ostree_sysroot_deployment_set_mutable:
+ * @self: Sysroot
+ * @deployment: A deployment
+ * @mutable: Whether or not deployment's files can be changed
+ * @error: Error
+ *
+ * By default, deployment directories are not mutable.  This function
+ * will allow making them temporarily mutable, for example to allow
+ * layering additional non-OSTree content.
+ */
+gboolean
+ostree_sysroot_deployment_set_mutable (OstreeSysroot     *self,
+                                       OstreeDeployment  *deployment,
+                                       gboolean           mutable,
+                                       GCancellable      *cancellable,
+                                       GError           **error)
+{
+  gboolean ret = FALSE;
+  g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment);
+  glnx_fd_close int fd = -1;
+
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
+  if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &fd, error))
+    goto out;
+
+  if (!_ostree_linuxfs_fd_alter_immutable_flag (fd, !mutable, cancellable, error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
+}
diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h
index 54203f1..4342470 100644
--- a/src/libostree/ostree-sysroot.h
+++ b/src/libostree/ostree-sysroot.h
@@ -96,6 +96,12 @@ gboolean ostree_sysroot_deploy_tree (OstreeSysroot     *self,
                                      GCancellable      *cancellable,
                                      GError           **error);
 
+gboolean ostree_sysroot_deployment_set_mutable (OstreeSysroot     *self,
+                                                OstreeDeployment  *deployment,
+                                                gboolean           mutable,
+                                                GCancellable      *cancellable,
+                                                GError           **error);
+
 OstreeDeployment *ostree_sysroot_get_merge_deployment (OstreeSysroot     *self,
                                                        const char        *osname);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]