[ostree] Add ostree_repo_is_writable()
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] Add ostree_repo_is_writable()
- Date: Wed, 25 Mar 2015 21:25:18 +0000 (UTC)
commit a25c7fab129779483012c4b52c1d0ef54878cc69
Author: Matthew Barnes <mbarnes redhat com>
Date: Sun Jan 18 20:27:53 2015 -0500
Add ostree_repo_is_writable()
doc/ostree-sections.txt | 1 +
src/libostree/ostree-repo-private.h | 1 +
src/libostree/ostree-repo.c | 28 ++++++++++++++++++++++++++++
src/libostree/ostree-repo.h | 3 +++
4 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/doc/ostree-sections.txt b/doc/ostree-sections.txt
index 37888c2..3452ce9 100644
--- a/doc/ostree-sections.txt
+++ b/doc/ostree-sections.txt
@@ -217,6 +217,7 @@ ostree_repo_new_default
ostree_repo_open
ostree_repo_set_disable_fsync
ostree_repo_is_system
+ostree_repo_is_writable
ostree_repo_create
ostree_repo_get_path
ostree_repo_get_mode
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h
index 6e299e2..8b07254 100644
--- a/src/libostree/ostree-repo-private.h
+++ b/src/libostree/ostree-repo-private.h
@@ -65,6 +65,7 @@ struct OstreeRepo {
gboolean inited;
gboolean writable;
+ GError *writable_error;
gboolean in_transaction;
gboolean disable_fsync;
GHashTable *loose_object_devino_hash;
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index aca7003..072ae76 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -381,6 +381,7 @@ ostree_repo_finalize (GObject *object)
g_clear_pointer (&self->txn_refs, g_hash_table_destroy);
g_clear_pointer (&self->cached_meta_indexes, (GDestroyNotify) g_ptr_array_unref);
g_clear_pointer (&self->cached_content_indexes, (GDestroyNotify) g_ptr_array_unref);
+ g_clear_error (&self->writable_error);
g_clear_pointer (&self->object_sizes, (GDestroyNotify) g_hash_table_unref);
g_mutex_clear (&self->cache_lock);
g_mutex_clear (&self->txn_stats_lock);
@@ -552,6 +553,28 @@ ostree_repo_is_system (OstreeRepo *repo)
}
/**
+ * ostree_repo_is_writable:
+ * @self: Repo
+ * @error: a #GError
+ *
+ * Returns whether the repository is writable by the current user.
+ * If the repository is not writable, the @error indicates why.
+ *
+ * Returns: %TRUE if this repository is writable
+ */
+gboolean
+ostree_repo_is_writable (OstreeRepo *self,
+ GError **error)
+{
+ g_return_val_if_fail (self->inited, FALSE);
+
+ if (error != NULL && self->writable_error != NULL)
+ *error = g_error_copy (self->writable_error);
+
+ return self->writable;
+}
+
+/**
* ostree_repo_get_config:
* @self:
*
@@ -1339,6 +1362,11 @@ ostree_repo_open (OstreeRepo *self,
}
self->writable = faccessat (self->objects_dir_fd, ".", W_OK, 0) == 0;
+ if (!self->writable)
+ {
+ /* This is returned through ostree_repo_is_writable(). */
+ gs_set_error_from_errno (&self->writable_error, errno);
+ }
if (fstat (self->objects_dir_fd, &stbuf) != 0)
{
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index 96c3536..e775b54 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -55,6 +55,9 @@ void ostree_repo_set_disable_fsync (OstreeRepo *self,
gboolean ostree_repo_is_system (OstreeRepo *repo);
+gboolean ostree_repo_is_writable (OstreeRepo *self,
+ GError **error);
+
gboolean ostree_repo_create (OstreeRepo *self,
OstreeRepoMode mode,
GCancellable *cancellable,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]