lib/repo: Add ostree_repo_equal() for comparing repos
authorPhilip Withnall <withnall@endlessm.com>
Fri, 15 Sep 2017 14:26:22 +0000 (15:26 +0100)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 19 Sep 2017 14:51:09 +0000 (14:51 +0000)
This will compare their root directory inodes to see if they are the
same repository on disk. A convenience method for the users of the
public API who can’t access OstreeRepo.inode.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Closes: #1179
Approved by: cgwalters

apidoc/ostree-sections.txt
src/libostree/libostree-devel.sym
src/libostree/ostree-repo.c
src/libostree/ostree-repo.h

index 5f061c00838e39a1bf79d404aabcb1ff586cff5f..547e1509b62fa89c2df9fc71826483227ee348b1 100644 (file)
@@ -287,6 +287,7 @@ ostree_repo_get_path
 ostree_repo_get_mode
 ostree_repo_get_config
 ostree_repo_get_dfd
+ostree_repo_equal
 ostree_repo_copy_config
 ostree_repo_remote_add
 ostree_repo_remote_delete
index 07f918a1126d4e194cd3b18ed54533cf775789bb..a416b7c1ac8966fff3c70f3614ca190bd93019d1 100644 (file)
@@ -19,6 +19,8 @@
 
 /* Add new symbols here.  Release commits should copy this section into -released.sym. */
 LIBOSTREE_2017.12 {
+global:
+  ostree_repo_equal;
 } LIBOSTREE_2017.11;
 
 
index 2aa8291d8788f05c81181443559e115ec35fbfe5..e6d8a747da1f024e9e72c71264f287ab56dd72bf 100644 (file)
@@ -2612,6 +2612,31 @@ ostree_repo_get_dfd (OstreeRepo  *self)
   return self->repo_dir_fd;
 }
 
+/**
+ * ostree_repo_equal:
+ * @a: an #OstreeRepo
+ * @b: an #OstreeRepo
+ *
+ * Check whether two opened repositories are the same on disk: if their root
+ * directories are the same inode. If @a or @b are not open yet (due to
+ * ostree_repo_open() not being called on them yet), %FALSE will be returned.
+ *
+ * Returns: %TRUE if @a and @b are the same repository on disk, %FALSE otherwise
+ * Since: 2017.12
+ */
+gboolean
+ostree_repo_equal (OstreeRepo *a,
+                   OstreeRepo *b)
+{
+  g_return_val_if_fail (OSTREE_IS_REPO (a), FALSE);
+  g_return_val_if_fail (OSTREE_IS_REPO (b), FALSE);
+
+  if (a->repo_dir_fd < 0 || b->repo_dir_fd < 0)
+    return FALSE;
+
+  return (a->device == b->device && a->inode == b->inode);
+}
+
 OstreeRepoMode
 ostree_repo_get_mode (OstreeRepo  *self)
 {
index 227fe597f85fb8133acdd15f27234d2bd4027e7a..682d49646ffd74d8c9dc0b683ab01c724c8efec3 100644 (file)
@@ -123,6 +123,10 @@ GFile *       ostree_repo_get_path (OstreeRepo  *self);
 _OSTREE_PUBLIC
 int           ostree_repo_get_dfd (OstreeRepo  *self);
 
+_OSTREE_PUBLIC
+gboolean      ostree_repo_equal (OstreeRepo *a,
+                                 OstreeRepo *b);
+
 _OSTREE_PUBLIC
 OstreeRepoMode ostree_repo_get_mode (OstreeRepo  *self);