[ostree] Check repo permission prior to attempting to modify it



commit 1d5e2682fdb493d6f2ed0dc695ed08586db1d227
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Jan 16 13:28:36 2015 -0500

    Check repo permission prior to attempting to modify it
    
    Fail early with a helpful message if the user does not have sufficient
    permission to modify an OSTree repository.

 src/ostree/ot-builtin-commit.c       |    3 +++
 src/ostree/ot-builtin-prune.c        |    3 +++
 src/ostree/ot-builtin-pull-local.c   |    3 +++
 src/ostree/ot-builtin-pull.c         |    3 +++
 src/ostree/ot-builtin-reset.c        |    3 +++
 src/ostree/ot-builtin-static-delta.c |    6 ++++++
 src/ostree/ot-builtin-summary.c      |    3 +++
 7 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index cd9e9a9..db17f53 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -313,6 +313,9 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (opt_statoverride_file)
     {
       if (!parse_statoverride_file (&mode_adds, cancellable, error))
diff --git a/src/ostree/ot-builtin-prune.c b/src/ostree/ot-builtin-prune.c
index cd05b2f..89ad2e5 100644
--- a/src/ostree/ot-builtin-prune.c
+++ b/src/ostree/ot-builtin-prune.c
@@ -55,6 +55,9 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
+  if (!opt_no_prune && !ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (opt_refs_only)
     pruneflags |= OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
   if (opt_no_prune)
diff --git a/src/ostree/ot-builtin-pull-local.c b/src/ostree/ot-builtin-pull-local.c
index 4588ccb..2b7bf67 100644
--- a/src/ostree/ot-builtin-pull-local.c
+++ b/src/ostree/ot-builtin-pull-local.c
@@ -58,6 +58,9 @@ ostree_builtin_pull_local (int argc, char **argv, GCancellable *cancellable, GEr
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 2)
     {
       gchar *help = g_option_context_get_help (context, TRUE, NULL);
diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c
index 0846605..91db17d 100644
--- a/src/ostree/ot-builtin-pull.c
+++ b/src/ostree/ot-builtin-pull.c
@@ -57,6 +57,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 2)
     {
       ot_util_usage_error (context, "REMOTE must be specified", error);
diff --git a/src/ostree/ot-builtin-reset.c b/src/ostree/ot-builtin-reset.c
index 0a72846..a09e9a4 100644
--- a/src/ostree/ot-builtin-reset.c
+++ b/src/ostree/ot-builtin-reset.c
@@ -100,6 +100,9 @@ ostree_builtin_reset (int           argc,
   if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, 
cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc <= 2)
     {
       ot_util_usage_error (context, "A ref and commit argument is required", error);
diff --git a/src/ostree/ot-builtin-static-delta.c b/src/ostree/ot-builtin-static-delta.c
index eba852f..9eece84 100644
--- a/src/ostree/ot-builtin-static-delta.c
+++ b/src/ostree/ot-builtin-static-delta.c
@@ -140,6 +140,9 @@ ot_static_delta_builtin_generate (int argc, char **argv, GCancellable *cancellab
   if (!ostree_option_context_parse (context, generate_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, 
&repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc >= 3 && opt_to_rev == NULL)
     opt_to_rev = argv[2];
 
@@ -248,6 +251,9 @@ ot_static_delta_builtin_apply_offline (int argc, char **argv, GCancellable *canc
   if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, 
&repo, cancellable, error))
     goto out;
 
+  if (!ostree_ensure_repo_writable (repo, error))
+    goto out;
+
   if (argc < 3)
     {
       g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c
index d7bed44..8156689 100644
--- a/src/ostree/ot-builtin-summary.c
+++ b/src/ostree/ot-builtin-summary.c
@@ -46,6 +46,9 @@ ostree_builtin_summary (int argc, char **argv, GCancellable *cancellable, GError
 
   if (opt_update)
     {
+      if (!ostree_ensure_repo_writable (repo, error))
+        goto out;
+
       if (!ostree_repo_regenerate_summary (repo, NULL, cancellable, error))
         goto out;
     }


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