summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Leeds <matthew.leeds@endlessm.com>2020-06-19 12:24:36 -0700
committerAlexander Larsson <alexander.larsson@gmail.com>2020-06-23 09:37:10 +0200
commite84b75629dd5c7a121cc4cb04968feca05c7a59f (patch)
treed595fd8f4deec4372104af7c9e7038b672d0e2b2
parent1bdd3810075e7ea89e4ddbaa973bbed55684cc62 (diff)
downloadflatpak-e84b75629dd5c7a121cc4cb04968feca05c7a59f.tar.gz
Allow sideload-repos to link to the root of a USB
Currently we only support links in /var/lib/flatpak/sideload-repos, /run/flatpak/sideload-repos, etc. to be actual ostree repos, but this commit makes it so you can also link to the root directory of a USB, and Flatpak will check the subpaths "ostree/repo", ".ostree/repo", and ".ostree/repos.d" for compatibility with "flatpak create-usb". This will allow the logic in the following commit to be much simpler, where we're linking to hot-plugged drives in a script run by systemd. Note that we still only allow actual repos in the other places where a sideload path can be specified, such as the --sideload-repo CLI option.
-rw-r--r--common/flatpak-dir.c38
-rw-r--r--doc/flatpak.xml4
2 files changed, 37 insertions, 5 deletions
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index 36690c64..bfbf994b 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -11885,7 +11885,8 @@ flatpak_dir_list_remote_config_keys (FlatpakDir *self,
static void
add_subdirs (GPtrArray *res,
- GFile *parent)
+ GFile *parent,
+ gboolean recurse)
{
g_autoptr(GFileEnumerator) dir_enum = NULL;
@@ -11906,8 +11907,37 @@ add_subdirs (GPtrArray *res,
info == NULL)
break;
+ /* Here we support either a plain repo or, if @recurse is TRUE, the root
+ * directory of a USB created with "flatpak create-usb"
+ */
if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
- g_ptr_array_add (res, g_object_ref (path));
+ {
+ g_autoptr(OstreeRepo) repo = ostree_repo_new (path);
+
+ if (ostree_repo_open (repo, NULL, NULL))
+ g_ptr_array_add (res, g_object_ref (path));
+ else if (recurse)
+ {
+ g_autoptr(GFile) ostree_repo_subpath = NULL;
+ g_autoptr(GFile) dot_ostree_repo_subpath = NULL;
+ g_autoptr(GFile) dot_ostree_repo_d_subpath = NULL;
+ g_autoptr(OstreeRepo) ostree_repo_subpath_repo = NULL;
+ g_autoptr(OstreeRepo) dot_ostree_repo_subpath_repo = NULL;
+
+ ostree_repo_subpath = g_file_resolve_relative_path (path, "ostree/repo");
+ ostree_repo_subpath_repo = ostree_repo_new (ostree_repo_subpath);
+ if (ostree_repo_open (ostree_repo_subpath_repo, NULL, NULL))
+ g_ptr_array_add (res, g_object_ref (ostree_repo_subpath));
+
+ dot_ostree_repo_subpath = g_file_resolve_relative_path (path, ".ostree/repo");
+ dot_ostree_repo_subpath_repo = ostree_repo_new (dot_ostree_repo_subpath);
+ if (ostree_repo_open (dot_ostree_repo_subpath_repo, NULL, NULL))
+ g_ptr_array_add (res, g_object_ref (dot_ostree_repo_subpath));
+
+ dot_ostree_repo_d_subpath = g_file_resolve_relative_path (path, ".ostree/repos.d");
+ add_subdirs (res, dot_ostree_repo_d_subpath, FALSE);
+ }
+ }
}
}
@@ -11918,8 +11948,8 @@ flatpak_dir_get_sideload_repo_paths (FlatpakDir *self)
g_autoptr(GFile) runtime_sideload_repos_dir = flatpak_dir_get_runtime_sideload_repos_dir (self);
g_autoptr(GPtrArray) res = g_ptr_array_new_with_free_func (g_object_unref);
- add_subdirs (res, sideload_repos_dir);
- add_subdirs (res, runtime_sideload_repos_dir);
+ add_subdirs (res, sideload_repos_dir, TRUE);
+ add_subdirs (res, runtime_sideload_repos_dir, TRUE);
return g_steal_pointer (&res);
}
diff --git a/doc/flatpak.xml b/doc/flatpak.xml
index fb4f3fec..e0af8724 100644
--- a/doc/flatpak.xml
+++ b/doc/flatpak.xml
@@ -97,7 +97,9 @@
<filename>/var/lib/flatpak/sideload-repos</filename>). Additionally
symlinks can be created in <filename>/run/flatpak/sideload-repos</filename>
(overridable by <envar>FLATPAK_RUN_DIR</envar>) which is a better location
- for non-persistent sources (as it is cleared on reboot).
+ for non-persistent sources (as it is cleared on reboot). These symlinks can point to either the
+ directory given to <command>flatpak create-usb</command> which by default writes to the subpath
+ <filename>.ostree/repo</filename>, or directly to an ostree repo.
</para>
</refsect1>