From 7941189dfde3795fb649aba41e207f0072dfcd86 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 16 Jan 2015 10:04:18 -0500 Subject: [PATCH] Add ostree_ensure_repo_writable() Commands that need to write files within the repo directory can call this early to ensure the directory is writable for the current user. If not, it fails with a helpful "You need to be root to perform this command" message. --- src/ostree/ot-main.c | 14 ++++++++++++++ src/ostree/ot-main.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index c48a03c5..94d29ca6 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -360,3 +360,17 @@ ostree_admin_option_context_parse (GOptionContext *context, out: return success; } + +gboolean +ostree_ensure_repo_writable (OstreeRepo *repo, + GError **error) +{ + gboolean ret; + + ret = ostree_repo_is_writable (repo, error); + + g_prefix_error (error, "Cannot write to repository: "); + + return ret; +} + diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h index 5f31b240..659727f3 100644 --- a/src/ostree/ot-main.h +++ b/src/ostree/ot-main.h @@ -51,3 +51,5 @@ gboolean ostree_admin_option_context_parse (GOptionContext *context, int *argc, char ***argv, OstreeSysroot **out_sysroot, GCancellable *cancellable, GError **error); + +gboolean ostree_ensure_repo_writable (OstreeRepo *repo, GError **error);