From e84b75629dd5c7a121cc4cb04968feca05c7a59f Mon Sep 17 00:00:00 2001 From: Matthew Leeds Date: Fri, 19 Jun 2020 12:24:36 -0700 Subject: 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. --- common/flatpak-dir.c | 38 ++++++++++++++++++++++++++++++++++---- doc/flatpak.xml | 4 +++- 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 @@ /var/lib/flatpak/sideload-repos). Additionally symlinks can be created in /run/flatpak/sideload-repos (overridable by FLATPAK_RUN_DIR) 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 flatpak create-usb which by default writes to the subpath + .ostree/repo, or directly to an ostree repo. -- cgit v1.2.1