Debian Codegraph @

src/libostree/ostree-repo-finder-mount.c

raw symbols SCIP
1 /*
2 * Copyright © 2017 Endless Mobile, Inc.
3 *
4 * SPDX-License-Identifier: LGPL-2.0+
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors:
20 * - Philip Withnall <[email protected]>
21 */
22
23 #include "config.h"
24
25 #include <gio/gio.h>
26 #include <gio/gunixmounts.h>
27 #include <glib-object.h>
28 #include <glib.h>
29 #include <libglnx.h>
30 #include <stdlib.h>
31
32 #include "ostree-autocleanups.h"
33 #include "ostree-remote-private.h"
34 #include "ostree-repo-finder-mount.h"
35 #include "ostree-repo-finder.h"
36 #include "ostree-repo-private.h"
37
38 /**
39 * SECTION:ostree-repo-finder-mount
40 * @title: OstreeRepoFinderMount
41 * @short_description: Finds remote repositories from ref names by looking at
42 * mounted removable volumes
43 * @stability: Unstable
44 * @include: libostree/ostree-repo-finder-mount.h
45 *
46 * #OstreeRepoFinderMount is an implementation of #OstreeRepoFinder which looks
47 * refs up in well-known locations on any mounted removable volumes.
48 *
49 * For each mounted removable volume, the directory `.ostree/repos.d` will be
50 * enumerated, and all OSTree repositories below it will be searched, in lexical
51 * order, for the requested #OstreeCollectionRefs. The names of the directories
52 * below `.ostree/repos.d` are irrelevant, apart from their lexical ordering.
53 * The directories `.ostree/repo`, `ostree/repo` and `var/lib/flatpak/repo`
54 * will be searched after the others, if they exist.
55 * Non-removable volumes are ignored.
56 *
57 * For each repository which is found, a result will be returned for the
58 * intersection of the refs being searched for, and the refs in `refs/heads` and
59 * `refs/mirrors` in the repository on the removable volume.
60 *
61 * Symlinks are followed when listing the repositories, so a volume might
62 * contain a single OSTree at some arbitrary path, with a symlink from
63 * `.ostree/repos.d`. Any symlink which points outside the volume’s file
64 * system will be ignored. Repositories are deduplicated in the results.
65 *
66 * The volume monitor used to find mounted volumes can be overridden by setting
67 * #OstreeRepoFinderMount:monitor. By default, g_volume_monitor_get() is used.
68 *
69 * Since: 2018.6
70 */
71
72 typedef GList /*<owned GObject>*/ ObjectList;
73
74 static void
75 object_list_free (ObjectList *list)
76 {
77 g_list_free_full (list, g_object_unref);
78 }
79
80 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ObjectList, object_list_free)
81
82 static void ostree_repo_finder_mount_iface_init (OstreeRepoFinderInterface *iface);
83
84 struct _OstreeRepoFinderMount
85 {
86 GObject parent_instance;
87
88 GVolumeMonitor *monitor; /* owned */
89 };
90
91 G_DEFINE_TYPE_WITH_CODE (OstreeRepoFinderMount, ostree_repo_finder_mount, G_TYPE_OBJECT,
92 G_IMPLEMENT_INTERFACE (OSTREE_TYPE_REPO_FINDER,
93 ostree_repo_finder_mount_iface_init))
94
95 typedef struct
96 {
97 gchar *uri;
98 OstreeRemote *keyring_remote; /* (owned) */
99 } UriAndKeyring;
100
101 static void
102 uri_and_keyring_free (UriAndKeyring *data)
103 {
104 g_free (data->uri);
105 ostree_remote_unref (data->keyring_remote);
106 g_free (data);
107 }
108
109 G_DEFINE_AUTOPTR_CLEANUP_FUNC (UriAndKeyring, uri_and_keyring_free)
110
111 static UriAndKeyring *
112 uri_and_keyring_new (const gchar *uri, OstreeRemote *keyring_remote)
113 {
114 g_autoptr (UriAndKeyring) data = NULL;
115
116 data = g_new0 (UriAndKeyring, 1);
117 data->uri = g_strdup (uri);
118 data->keyring_remote = ostree_remote_ref (keyring_remote);
119
120 return g_steal_pointer (&data);
121 }
122
123 static guint
124 uri_and_keyring_hash (gconstpointer key)
125 {
126 const UriAndKeyring *_key = key;
127
128 return g_str_hash (_key->uri) ^ g_str_hash (_key->keyring_remote->keyring);
129 }
130
131 static gboolean
132 uri_and_keyring_equal (gconstpointer a, gconstpointer b)
133 {
134 const UriAndKeyring *_a = a, *_b = b;
135
136 return (g_str_equal (_a->uri, _b->uri)
137 && g_str_equal (_a->keyring_remote->keyring, _b->keyring_remote->keyring));
138 }
139
140 /* This must return a valid remote name (suitable for use in a refspec). */
141 static gchar *
142 uri_and_keyring_to_name (UriAndKeyring *data)
143 {
144 g_autofree gchar *escaped_uri = g_uri_escape_string (data->uri, NULL, FALSE);
145 g_autofree gchar *escaped_keyring
146 = g_uri_escape_string (data->keyring_remote->keyring, NULL, FALSE);
147
148 /* FIXME: Need a better separator than `_`, since it’s not escaped in the input. */
149 g_autofree gchar *out = g_strdup_printf ("%s_%s", escaped_uri, escaped_keyring);
150
151 for (gsize i = 0; out[i] != '\0'; i++)
152 {
153 if (out[i] == '%')
154 out[i] = '_';
155 }
156
157 g_return_val_if_fail (ostree_validate_remote_name (out, NULL), NULL);
158
159 return g_steal_pointer (&out);
160 }
161
162 static gint
163 results_compare_cb (gconstpointer a, gconstpointer b)
164 {
165 const OstreeRepoFinderResult *result_a = *((const OstreeRepoFinderResult **)a);
166 const OstreeRepoFinderResult *result_b = *((const OstreeRepoFinderResult **)b);
167
168 return ostree_repo_finder_result_compare (result_a, result_b);
169 }
170
171 typedef struct
172 {
173 char *ordering_name; /* (owned) */
174 OstreeRepo *repo; /* (owned) */
175 GHashTable *refs; /* (owned) (element-type OstreeCollectionRef utf8) */
176 } RepoAndRefs;
177
178 static void
179 repo_and_refs_clear (RepoAndRefs *data)
180 {
181 g_hash_table_unref (data->refs);
182 g_object_unref (data->repo);
183 g_free (data->ordering_name);
184 }
185
186 static gint
187 repo_and_refs_compare (gconstpointer a, gconstpointer b)
188 {
189 const RepoAndRefs *_a = a;
190 const RepoAndRefs *_b = b;
191
192 return strcmp (_a->ordering_name, _b->ordering_name);
193 }
194
195 /* Check whether the repo at @dfd/@path is within the given mount, is not equal
196 * to the @parent_repo, and can be opened. If so, return it as @out_repo and
197 * all its collection–refs as @out_refs, to be added into the results. */
198 static gboolean
199 scan_repo (int dfd, const char *path, const char *mount_name, const struct stat *mount_root_stbuf,
200 OstreeRepo *parent_repo, OstreeRepo **out_repo, GHashTable **out_refs,
201 GCancellable *cancellable, GError **error)
202 {
203 g_autoptr (GError) local_error = NULL;
204
205 g_autoptr (OstreeRepo) repo = ostree_repo_open_at (dfd, path, cancellable, &local_error);
206 if (repo == NULL)
207 {
208 g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it could not be opened: %s", path,
209 mount_name, local_error->message);
210 g_propagate_error (error, g_steal_pointer (&local_error));
211 return FALSE;
212 }
213
214 int repo_dfd = ostree_repo_get_dfd (repo);
215 struct stat stbuf;
216
217 if (!glnx_fstat (repo_dfd, &stbuf, &local_error))
218 {
219 g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as querying its info failed: %s", path,
220 mount_name, local_error->message);
221 g_propagate_error (error, g_steal_pointer (&local_error));
222 return FALSE;
223 }
224
225 /* Check the resolved repository path is below the mount point. Do not
226 * allow ref symlinks to point somewhere outside of the mounted volume. */
227 if (stbuf.st_dev != mount_root_stbuf->st_dev)
228 {
229 g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as it’s on a different file system from "
230 "the mount",
231 path, mount_name);
232 return glnx_throw (error, "Repository is on a different file system from the mount");
233 }
234
235 /* Exclude repositories which resolve to @parent_repo. */
236 if (stbuf.st_dev == parent_repo->device && stbuf.st_ino == parent_repo->inode)
237 {
238 g_debug (
239 "Ignoring repository ‘%s’ on mount ‘%s’ as it is the same as the one we are resolving",
240 path, mount_name);
241 return glnx_throw (error, "Repository is the same as the one we are resolving");
242 }
243
244 /* List the repo’s refs and return them. */
245 g_autoptr (GHashTable) repo_refs = NULL; /* (element-type OstreeCollectionRef utf8) */
246
247 if (!ostree_repo_list_collection_refs (repo, NULL, &repo_refs,
248 OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES, cancellable,
249 &local_error))
250 {
251 g_debug ("Ignoring repository ‘%s’ on mount ‘%s’ as its refs could not be listed: %s", path,
252 mount_name, local_error->message);
253 g_propagate_error (error, g_steal_pointer (&local_error));
254 return FALSE;
255 }
256
257 if (out_repo != NULL)
258 *out_repo = g_steal_pointer (&repo);
259 if (out_refs != NULL)
260 *out_refs = g_steal_pointer (&repo_refs);
261
262 return TRUE;
263 }
264
265 static void
266 scan_and_add_repo (int dfd, const char *path, gboolean sortable, const char *mount_name,
267 const struct stat *mount_root_stbuf, OstreeRepo *parent_repo,
268 GArray *inout_repos_refs, GCancellable *cancellable)
269 {
270 g_autoptr (GHashTable) repo_refs = NULL;
271 g_autoptr (OstreeRepo) repo = NULL;
272
273 if (scan_repo (dfd, path, mount_name, mount_root_stbuf, parent_repo, &repo, &repo_refs,
274 cancellable, NULL))
275 {
276 RepoAndRefs val = { sortable ? g_strdup (path) : NULL, g_steal_pointer (&repo),
277 g_steal_pointer (&repo_refs) };
278 g_array_append_val (inout_repos_refs, val);
279
280 g_debug ("%s: Adding repo ‘%s’ on mount ‘%s’ (%ssortable)", G_STRFUNC, path, mount_name,
281 sortable ? "" : "not ");
282 }
283 }
284
285 static void
286 ostree_repo_finder_mount_resolve_async (OstreeRepoFinder *finder,
287 const OstreeCollectionRef *const *refs,
288 OstreeRepo *parent_repo, GCancellable *cancellable,
289 GAsyncReadyCallback callback, gpointer user_data)
290 {
291 OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (finder);
292 g_autoptr (GTask) task = NULL;
293 g_autoptr (ObjectList) mounts = NULL;
294 g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */
295 GList *l;
296 const gint priority = 50; /* arbitrarily chosen */
297
298 task = g_task_new (finder, cancellable, callback, user_data);
299 g_task_set_source_tag (task, ostree_repo_finder_mount_resolve_async);
300
301 mounts = g_volume_monitor_get_mounts (self->monitor);
302 results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free);
303
304 g_debug ("%s: Found %u mounts", G_STRFUNC, g_list_length (mounts));
305
306 for (l = mounts; l != NULL; l = l->next)
307 {
308 GMount *mount = G_MOUNT (l->data);
309 g_autofree gchar *mount_name = NULL;
310 g_autoptr (GFile) mount_root = NULL;
311 g_autofree gchar *mount_root_path = NULL;
312 glnx_autofd int mount_root_dfd = -1;
313 struct stat mount_root_stbuf;
314 glnx_autofd int repos_dfd = -1;
315 gsize i;
316 g_autoptr (GHashTable) repo_to_refs = NULL; /* (element-type UriAndKeyring GHashTable) */
317 GHashTable *supported_ref_to_checksum; /* (element-type OstreeCollectionRef utf8) */
318 GHashTableIter iter;
319 g_autoptr (GError) local_error = NULL;
320
321 mount_name = g_mount_get_name (mount);
322
323 /* Check the mount’s general properties. */
324 if (g_mount_is_shadowed (mount))
325 {
326 g_debug ("Ignoring mount ‘%s’ as it’s shadowed.", mount_name);
327 continue;
328 }
329
330 mount_root = g_mount_get_root (mount);
331 mount_root_path = g_file_get_path (mount_root);
332
333 if (!glnx_opendirat (AT_FDCWD, mount_root_path, TRUE, &mount_root_dfd, &local_error))
334 {
335 g_debug ("Ignoring mount ‘%s’ as ‘%s’ directory can’t be opened: %s", mount_name,
336 mount_root_path, local_error->message);
337 continue;
338 }
339
340 #if GLIB_CHECK_VERSION(2, 55, 0)
341 G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* remove once GLIB_VERSION_MAX_ALLOWED ≥ 2.56 */
342 g_autoptr (GUnixMountEntry) mount_entry
343 = g_unix_mount_at (mount_root_path, NULL);
344
345 if (mount_entry != NULL
346 && (g_unix_is_system_fs_type (g_unix_mount_get_fs_type (mount_entry))
347 || g_unix_is_system_device_path (g_unix_mount_get_device_path (mount_entry))))
348 {
349 g_debug ("Ignoring mount ‘%s’ as its file system type (%s) or device "
350 "path (%s) indicate it’s a system mount.",
351 mount_name, g_unix_mount_get_fs_type (mount_entry),
352 g_unix_mount_get_device_path (mount_entry));
353 continue;
354 }
355 G_GNUC_END_IGNORE_DEPRECATIONS
356 #endif /* GLib 2.56.0 */
357
358 /* stat() the mount root so we can later check whether the resolved
359 * repositories for individual refs are on the same device (to avoid the
360 * symlinks for them pointing outside the mount root). */
361 if (!glnx_fstat (mount_root_dfd, &mount_root_stbuf, &local_error))
362 {
363 g_debug ("Ignoring mount ‘%s’ as querying info of ‘%s’ failed: %s", mount_name,
364 mount_root_path, local_error->message);
365 continue;
366 }
367
368 /* Check if it contains a .ostree/repos.d directory. If not, move on and
369 * try the other well-known subdirectories. */
370 if (!glnx_opendirat (mount_root_dfd, ".ostree/repos.d", TRUE, &repos_dfd, NULL))
371 repos_dfd = -1;
372
373 /* List all the repositories in the repos.d directory. */
374 /* (element-type GHashTable (element-type OstreeCollectionRef utf8)) */
375 g_autoptr (GArray) repos_refs = g_array_new (FALSE, TRUE, sizeof (RepoAndRefs));
376 g_array_set_clear_func (repos_refs, (GDestroyNotify)repo_and_refs_clear);
377
378 GLnxDirFdIterator repos_iter;
379
380 if (repos_dfd >= 0
381 && !glnx_dirfd_iterator_init_at (repos_dfd, ".", TRUE, &repos_iter, &local_error))
382 {
383 g_debug ("Error iterating over ‘%s/.ostree/repos.d’ directory in mount ‘%s’: %s",
384 mount_root_path, mount_name, local_error->message);
385 g_clear_error (&local_error);
386 /* don’t skip this mount as there’s still the ostree/repo directory to try */
387 }
388 else if (repos_dfd >= 0)
389 {
390 while (TRUE)
391 {
392 struct dirent *repo_dent;
393
394 if (!glnx_dirfd_iterator_next_dent (&repos_iter, &repo_dent, cancellable,
395 &local_error))
396 {
397 g_debug ("Error iterating over ‘%s/.ostree/repos.d’ directory in mount ‘%s’: %s",
398 mount_root_path, mount_name, local_error->message);
399 g_clear_error (&local_error);
400 /* don’t skip this mount as there’s still the ostree/repo directory to try */
401 break;
402 }
403
404 if (repo_dent == NULL)
405 break;
406
407 /* Grab the set of collection–refs from the repo if we can open it. */
408 scan_and_add_repo (repos_dfd, repo_dent->d_name, TRUE, mount_name, &mount_root_stbuf,
409 parent_repo, repos_refs, cancellable);
410 }
411 }
412
413 /* Sort the repos lexically. */
414 g_array_sort (repos_refs, repo_and_refs_compare);
415
416 /* Also check the well-known special-case directories in the mount.
417 * Add them after sorting, so they’re always last.
418 * NOTE: If you change these, update the man page. */
419 const gchar *const well_known_repos[] = {
420 ".ostree/repo",
421 "ostree/repo",
422 "var/lib/flatpak/repo",
423 };
424
425 for (i = 0; i < G_N_ELEMENTS (well_known_repos); i++)
426 scan_and_add_repo (mount_root_dfd, well_known_repos[i], FALSE, mount_name,
427 &mount_root_stbuf, parent_repo, repos_refs, cancellable);
428
429 /* Check whether a subdirectory exists for any of the @refs we’re looking
430 * for. If so, and it’s a symbolic link, dereference it so multiple links
431 * to the same repository (containing multiple refs) are coalesced.
432 * Otherwise, include it as a result by itself. */
433 repo_to_refs = g_hash_table_new_full (uri_and_keyring_hash, uri_and_keyring_equal,
434 (GDestroyNotify)uri_and_keyring_free,
435 (GDestroyNotify)g_hash_table_unref);
436
437 for (i = 0; refs[i] != NULL; i++)
438 {
439 const OstreeCollectionRef *ref = refs[i];
440 g_autofree gchar *resolved_repo_uri = NULL;
441
442 for (gsize j = 0; j < repos_refs->len; j++)
443 {
444 const RepoAndRefs *repo_and_refs = &g_array_index (repos_refs, RepoAndRefs, j);
445 OstreeRepo *repo = repo_and_refs->repo;
446 GHashTable *repo_refs = repo_and_refs->refs;
447 g_autofree char *repo_path = g_file_get_path (ostree_repo_get_path (repo));
448 g_autoptr (OstreeRemote) keyring_remote = NULL;
449
450 const gchar *checksum = g_hash_table_lookup (repo_refs, ref);
451
452 if (checksum == NULL)
453 {
454 g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ "
455 "as it doesn’t contain the ref.",
456 repo_path, ref->collection_id, ref->ref_name, mount_name);
457 g_clear_error (&local_error);
458 continue;
459 }
460
461 /* Finally, look up the GPG keyring for this ref. */
462 keyring_remote = ostree_repo_resolve_keyring_for_collection (
463 parent_repo, ref->collection_id, cancellable, &local_error);
464
465 if (keyring_remote == NULL)
466 {
467 g_debug ("Ignoring repository ‘%s’ when looking for ref (%s, %s) on mount ‘%s’ "
468 "due to missing keyring: %s",
469 repo_path, ref->collection_id, ref->ref_name, mount_name,
470 local_error->message);
471 g_clear_error (&local_error);
472 continue;
473 }
474
475 /* There is a valid repo at (or pointed to by)
476 * $mount_root/.ostree/repos.d/$something.
477 * Add it to the results, keyed by the canonicalised repository URI
478 * to deduplicate the results. */
479 g_autofree char *canonical_repo_path = realpath (repo_path, NULL);
480 resolved_repo_uri = g_strconcat ("file://", canonical_repo_path, NULL);
481 g_debug ("Resolved ref (%s, %s) on mount ‘%s’ to repo URI ‘%s’ with keyring ‘%s’ "
482 "from remote ‘%s’.",
483 ref->collection_id, ref->ref_name, mount_name, resolved_repo_uri,
484 keyring_remote->keyring, keyring_remote->name);
485
486 g_autoptr (UriAndKeyring) resolved_repo
487 = uri_and_keyring_new (resolved_repo_uri, keyring_remote);
488
489 supported_ref_to_checksum = g_hash_table_lookup (repo_to_refs, resolved_repo);
490
491 if (supported_ref_to_checksum == NULL)
492 {
493 supported_ref_to_checksum = g_hash_table_new_full (
494 ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, g_free);
495 g_hash_table_insert (repo_to_refs, g_steal_pointer (&resolved_repo),
496 supported_ref_to_checksum /* transfer */);
497 }
498
499 g_hash_table_insert (supported_ref_to_checksum, (gpointer)ref, g_strdup (checksum));
500
501 /* We’ve found a result for this collection–ref. No point in checking
502 * the other repos on the mount, since pulling in parallel from them won’t help. */
503 break;
504 }
505 }
506
507 /* Aggregate the results. */
508 g_hash_table_iter_init (&iter, repo_to_refs);
509
510 UriAndKeyring *repo;
511 while (
512 g_hash_table_iter_next (&iter, (gpointer *)&repo, (gpointer *)&supported_ref_to_checksum))
513 {
514 g_autoptr (OstreeRemote) remote = NULL;
515
516 /* Build an #OstreeRemote. Use the escaped URI, since remote->name
517 * is used in file paths, so needs to not contain special characters. */
518 g_autofree gchar *name = uri_and_keyring_to_name (repo);
519 remote = ostree_remote_new_dynamic (name, repo->keyring_remote->name);
520
521 g_clear_pointer (&remote->keyring, g_free);
522 remote->keyring = g_strdup (repo->keyring_remote->keyring);
523
524 /* gpg-verify-summary is false since we use the unsigned summary file support. */
525 g_key_file_set_string (remote->options, remote->group, "url", repo->uri);
526 g_key_file_set_boolean (remote->options, remote->group, "gpg-verify", TRUE);
527 g_key_file_set_boolean (remote->options, remote->group, "gpg-verify-summary", FALSE);
528
529 /* Set the timestamp in the #OstreeRepoFinderResult to 0 because
530 * the code in ostree_repo_pull_from_remotes_async() will be able to
531 * check it just as quickly as we can here; so don’t duplicate the
532 * code. */
533 g_ptr_array_add (results,
534 ostree_repo_finder_result_new (remote, finder, priority,
535 supported_ref_to_checksum, NULL, 0));
536 }
537 }
538
539 g_ptr_array_sort (results, results_compare_cb);
540
541 g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref);
542 }
543
544 static GPtrArray *
545 ostree_repo_finder_mount_resolve_finish (OstreeRepoFinder *self, GAsyncResult *result,
546 GError **error)
547 {
548 g_return_val_if_fail (g_task_is_valid (result, self), NULL);
549 return g_task_propagate_pointer (G_TASK (result), error);
550 }
551
552 static void
553 ostree_repo_finder_mount_init (OstreeRepoFinderMount *self)
554 {
555 /* Nothing to see here. */
556 }
557
558 static void
559 ostree_repo_finder_mount_constructed (GObject *object)
560 {
561 OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
562
563 G_OBJECT_CLASS (ostree_repo_finder_mount_parent_class)->constructed (object);
564
565 if (self->monitor == NULL)
566 self->monitor = g_volume_monitor_get ();
567 }
568
569 typedef enum
570 {
571 PROP_MONITOR = 1,
572 } OstreeRepoFinderMountProperty;
573
574 static void
575 ostree_repo_finder_mount_get_property (GObject *object, guint property_id, GValue *value,
576 GParamSpec *pspec)
577 {
578 OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
579
580 switch ((OstreeRepoFinderMountProperty)property_id)
581 {
582 case PROP_MONITOR:
583 g_value_set_object (value, self->monitor);
584 break;
585 default:
586 g_assert_not_reached ();
587 }
588 }
589
590 static void
591 ostree_repo_finder_mount_set_property (GObject *object, guint property_id, const GValue *value,
592 GParamSpec *pspec)
593 {
594 OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
595
596 switch ((OstreeRepoFinderMountProperty)property_id)
597 {
598 case PROP_MONITOR:
599 /* Construct-only. */
600 g_assert (self->monitor == NULL);
601 self->monitor = g_value_dup_object (value);
602 break;
603 default:
604 g_assert_not_reached ();
605 }
606 }
607
608 static void
609 ostree_repo_finder_mount_dispose (GObject *object)
610 {
611 OstreeRepoFinderMount *self = OSTREE_REPO_FINDER_MOUNT (object);
612
613 g_clear_object (&self->monitor);
614
615 G_OBJECT_CLASS (ostree_repo_finder_mount_parent_class)->dispose (object);
616 }
617
618 static void
619 ostree_repo_finder_mount_class_init (OstreeRepoFinderMountClass *klass)
620 {
621 GObjectClass *object_class = G_OBJECT_CLASS (klass);
622
623 object_class->get_property = ostree_repo_finder_mount_get_property;
624 object_class->set_property = ostree_repo_finder_mount_set_property;
625 object_class->constructed = ostree_repo_finder_mount_constructed;
626 object_class->dispose = ostree_repo_finder_mount_dispose;
627
628 /**
629 * OstreeRepoFinderMount:monitor:
630 *
631 * Volume monitor to use to look up mounted volumes when queried.
632 *
633 * Since: 2018.6
634 */
635 g_object_class_install_property (
636 object_class, PROP_MONITOR,
637 g_param_spec_object ("monitor", "Volume Monitor",
638 "Volume monitor to use "
639 "to look up mounted "
640 "volumes when queried.",
641 G_TYPE_VOLUME_MONITOR,
642 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
643 }
644
645 static void
646 ostree_repo_finder_mount_iface_init (OstreeRepoFinderInterface *iface)
647 {
648 iface->resolve_async = ostree_repo_finder_mount_resolve_async;
649 iface->resolve_finish = ostree_repo_finder_mount_resolve_finish;
650 }
651
652 /**
653 * ostree_repo_finder_mount_new:
654 * @monitor: (nullable) (transfer none): volume monitor to use, or %NULL to use
655 * the system default
656 *
657 * Create a new #OstreeRepoFinderMount, using the given @monitor to look up
658 * volumes. If @monitor is %NULL, the monitor from g_volume_monitor_get() will
659 * be used.
660 *
661 * Returns: (transfer full): a new #OstreeRepoFinderMount
662 * Since: 2018.6
663 */
664 OstreeRepoFinderMount *
665 ostree_repo_finder_mount_new (GVolumeMonitor *monitor)
666 {
667 g_return_val_if_fail (monitor == NULL || G_IS_VOLUME_MONITOR (monitor), NULL);
668
669 return g_object_new (OSTREE_TYPE_REPO_FINDER_MOUNT, "monitor", monitor, NULL);
670 }