mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-15 13:39:54 -04:00
remote-ls: Allow a URI instead of remote name
This fixes the ability of the remote-ls command to take a file:// URI instead of a remote name, which is especially useful for repos on USB drives (created via `ostree create-usb`) which are temporary and don't warrant being added to the repo config. This commit also updates relevant documentation, adds a unit test, and updates a few variable names to improve readability. I can't find a commit in the history where this was working, but it's working on the Endless fork of flatpak so I think there was agreement at some point that it's desired behavior. Fixes https://github.com/flatpak/flatpak/issues/1588 Closes: #1587 Approved by: mwleeds
This commit is contained in:
committed by
Atomic Bot
parent
79907f4236
commit
9afca51507
@@ -117,9 +117,16 @@ flatpak_builtin_ls_remote (int argc, char **argv, GCancellable *cancellable, GEr
|
||||
g_autoptr(GHashTable) refs = NULL;
|
||||
RemoteDirPair *remote_dir_pair = NULL;
|
||||
g_autoptr(FlatpakRemoteState) state = NULL;
|
||||
gboolean is_local = FALSE;
|
||||
|
||||
if (!flatpak_resolve_duplicate_remotes (dirs, argv[1], &preferred_dir, cancellable, error))
|
||||
return FALSE;
|
||||
is_local = g_str_has_prefix (argv[1], "file:");
|
||||
if (is_local)
|
||||
preferred_dir = flatpak_dir_get_system_default ();
|
||||
else
|
||||
{
|
||||
if (!flatpak_resolve_duplicate_remotes (dirs, argv[1], &preferred_dir, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
state = flatpak_dir_get_remote_state (preferred_dir, argv[1], cancellable, error);
|
||||
if (state == NULL)
|
||||
|
||||
@@ -8079,7 +8079,7 @@ flatpak_dir_remote_make_oci_summary (FlatpakDir *self,
|
||||
|
||||
static gboolean
|
||||
flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
const char *name,
|
||||
const char *name_or_uri,
|
||||
GBytes **out_summary,
|
||||
GBytes **out_summary_sig,
|
||||
GCancellable *cancellable,
|
||||
@@ -8091,13 +8091,13 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
g_autoptr(GBytes) summary = NULL;
|
||||
g_autoptr(GBytes) summary_sig = NULL;
|
||||
|
||||
if (!ostree_repo_remote_get_url (self->repo, name, &url, error))
|
||||
if (!ostree_repo_remote_get_url (self->repo, name_or_uri, &url, error))
|
||||
return FALSE;
|
||||
|
||||
if (*url == '\0')
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
|
||||
"Can't fetch summary from disabled remote ‘%s’", name);
|
||||
"Can't fetch summary from disabled remote ‘%s’", name_or_uri);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -8106,7 +8106,7 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
/* No caching for local files */
|
||||
if (!is_local)
|
||||
{
|
||||
if (flatpak_dir_lookup_cached_summary (self, out_summary, out_summary_sig, name, url))
|
||||
if (flatpak_dir_lookup_cached_summary (self, out_summary, out_summary_sig, name_or_uri, url))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -8114,9 +8114,9 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
if (error == NULL)
|
||||
error = &local_error;
|
||||
|
||||
if (flatpak_dir_get_remote_oci (self, name))
|
||||
if (flatpak_dir_get_remote_oci (self, name_or_uri))
|
||||
{
|
||||
if (!flatpak_dir_remote_make_oci_summary (self, name,
|
||||
if (!flatpak_dir_remote_make_oci_summary (self, name_or_uri,
|
||||
&summary,
|
||||
cancellable,
|
||||
error))
|
||||
@@ -8124,8 +8124,8 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
}
|
||||
else
|
||||
{
|
||||
g_debug ("Fetching summary file for remote ‘%s’", name);
|
||||
if (!ostree_repo_remote_fetch_summary (self->repo, name,
|
||||
g_debug ("Fetching summary file for remote ‘%s’", name_or_uri);
|
||||
if (!ostree_repo_remote_fetch_summary (self->repo, name_or_uri,
|
||||
&summary, &summary_sig,
|
||||
cancellable,
|
||||
error))
|
||||
@@ -8134,10 +8134,10 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
|
||||
if (summary == NULL)
|
||||
return flatpak_fail (error, "Remote listing for %s not available; server has no summary file\n" \
|
||||
"Check the URL passed to remote-add was valid\n", name);
|
||||
"Check the URL passed to remote-add was valid\n", name_or_uri);
|
||||
|
||||
if (!is_local)
|
||||
flatpak_dir_cache_summary (self, summary, summary_sig, name, url);
|
||||
flatpak_dir_cache_summary (self, summary, summary_sig, name_or_uri, url);
|
||||
|
||||
*out_summary = g_steal_pointer (&summary);
|
||||
if (out_summary_sig)
|
||||
@@ -8148,7 +8148,7 @@ flatpak_dir_remote_fetch_summary (FlatpakDir *self,
|
||||
|
||||
static FlatpakRemoteState *
|
||||
_flatpak_dir_get_remote_state (FlatpakDir *self,
|
||||
const char *remote,
|
||||
const char *remote_or_uri,
|
||||
gboolean optional,
|
||||
GBytes *opt_summary,
|
||||
GBytes *opt_summary_sig,
|
||||
@@ -8157,6 +8157,7 @@ _flatpak_dir_get_remote_state (FlatpakDir *self,
|
||||
{
|
||||
g_autoptr(FlatpakRemoteState) state = flatpak_remote_state_new ();
|
||||
g_autoptr(GError) my_error = NULL;
|
||||
gboolean is_local;
|
||||
|
||||
if (error == NULL)
|
||||
error = &my_error;
|
||||
@@ -8164,8 +8165,9 @@ _flatpak_dir_get_remote_state (FlatpakDir *self,
|
||||
if (!flatpak_dir_ensure_repo (self, cancellable, error))
|
||||
return NULL;
|
||||
|
||||
state->remote_name = g_strdup (remote);
|
||||
if (!repo_get_remote_collection_id (self->repo, remote, &state->collection_id, error))
|
||||
state->remote_name = g_strdup (remote_or_uri);
|
||||
is_local = g_str_has_prefix (remote_or_uri, "file:");
|
||||
if (!is_local && !repo_get_remote_collection_id (self->repo, remote_or_uri, &state->collection_id, error))
|
||||
return NULL;
|
||||
|
||||
if (opt_summary)
|
||||
@@ -8194,7 +8196,7 @@ _flatpak_dir_get_remote_state (FlatpakDir *self,
|
||||
g_autoptr(GBytes) summary_bytes = NULL;
|
||||
g_autoptr(GBytes) summary_sig_bytes = NULL;
|
||||
|
||||
if (flatpak_dir_remote_fetch_summary (self, remote, &summary_bytes, &summary_sig_bytes,
|
||||
if (flatpak_dir_remote_fetch_summary (self, remote_or_uri, &summary_bytes, &summary_sig_bytes,
|
||||
cancellable, &local_error))
|
||||
{
|
||||
state->summary_sig_bytes = g_steal_pointer (&summary_sig_bytes);
|
||||
@@ -8245,7 +8247,7 @@ _flatpak_dir_get_remote_state (FlatpakDir *self,
|
||||
else
|
||||
{
|
||||
/* Look up the commit containing the latest repository metadata. */
|
||||
latest_rev = flatpak_dir_read_latest (self, remote, OSTREE_REPO_METADATA_REF,
|
||||
latest_rev = flatpak_dir_read_latest (self, remote_or_uri, OSTREE_REPO_METADATA_REF,
|
||||
NULL, cancellable, error);
|
||||
if (latest_rev == NULL)
|
||||
return NULL;
|
||||
|
||||
@@ -45,6 +45,10 @@
|
||||
or all remotes if one isn't specified. You can find all configured
|
||||
remote repositories with <citerefentry><refentrytitle>flatpak-remotes</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
|
||||
</para>
|
||||
<para>
|
||||
<arg choice="plain">REMOTE</arg> can be a file:// URI pointing to a
|
||||
local repository instead of a remote name.
|
||||
</para>
|
||||
<para>
|
||||
Unless overridden with the --system, --user, or --installation options,
|
||||
this command uses either the default system-wide installation or the
|
||||
@@ -182,8 +186,17 @@
|
||||
<command>$ flatpak --user remote-ls --app testrepo</command>
|
||||
</para>
|
||||
<programlisting>
|
||||
Ref
|
||||
org.gnome.Builder
|
||||
org.freedesktop.glxgears
|
||||
</programlisting>
|
||||
|
||||
<para>
|
||||
<command>$ flatpak remote-ls file:///run/media/mwleeds/d4d37026-cde2-4e5e-8bcc-d23ebbf231f9/.ostree/repo</command>
|
||||
</para>
|
||||
<programlisting>
|
||||
Ref
|
||||
org.kde.Khangman
|
||||
</programlisting>
|
||||
|
||||
</refsect1>
|
||||
|
||||
@@ -28,7 +28,7 @@ if [ x${USE_COLLECTIONS_IN_CLIENT-} == xyes ] || [ x${USE_COLLECTIONS_IN_SERVER-
|
||||
skip_without_p2p
|
||||
fi
|
||||
|
||||
echo "1..15"
|
||||
echo "1..16"
|
||||
|
||||
#Regular repo
|
||||
setup_repo
|
||||
@@ -246,6 +246,13 @@ fi
|
||||
|
||||
echo "ok remote-ls"
|
||||
|
||||
# Test that remote-ls can take a file:// URI
|
||||
ostree --repo=repos/test summary -u
|
||||
${FLATPAK} remote-ls file://`pwd`/repos/test > repo-list
|
||||
assert_file_has_content repo-list "org.test.Hello"
|
||||
|
||||
echo "ok remote-ls URI"
|
||||
|
||||
# Test that remote-modify works in all of the following cases:
|
||||
# * system remote, and --system is used
|
||||
# * system remote, and --system is omitted
|
||||
|
||||
Reference in New Issue
Block a user