find-remotes: Don't require write access to repo unless pulling
authorlzwind <liuzheng@uniontech.com>
Wed, 5 Aug 2026 00:59:56 +0000 (08:59 +0800)
committerlzwind <liuzheng@uniontech.com>
Wed, 5 Aug 2026 00:59:56 +0000 (08:59 +0800)
ostree find-remotes is a read-only operation that searches for remotes
which have a given collection-ref. It should not require write access
to the repository. Only when --pull is used does the command actually
write to the repo.

Move the ostree_ensure_repo_writable() check to just before the pull
phase so that read-only find-remotes works on read-only repositories.

Closes #3585

src/ostree/ot-builtin-find-remotes.c

index 7475aaa618517fb362db62459f02f0d445a1931d..600f37695a76a2edac2e114a62dfb3f6552f6ad0 100644 (file)
@@ -190,9 +190,6 @@ ostree_builtin_find_remotes (int argc, char **argv, OstreeCommandInvocation *inv
                                     error))
     return FALSE;
 
-  if (!ostree_ensure_repo_writable (repo, error))
-    return FALSE;
-
   if (argc < 3)
     {
       ot_util_usage_error (context, "At least one COLLECTION-ID REF pair must be specified", error);
@@ -363,6 +360,10 @@ ostree_builtin_find_remotes (int argc, char **argv, OstreeCommandInvocation *inv
   if (!opt_pull)
     return TRUE;
 
+  /* Pulling requires write access to the repository. */
+  if (!ostree_ensure_repo_writable (repo, error))
+    return FALSE;
+
   {
     GVariantBuilder builder;
     g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));