From 981eb6c2267f076bbb278f634fda83aa9dfac2a9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 15 Sep 2017 15:26:22 +0100 Subject: [PATCH] lib/repo: Add ostree_repo_equal() for comparing repos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Closes: #1179 Approved by: cgwalters --- apidoc/ostree-sections.txt | 1 + src/libostree/libostree-devel.sym | 2 ++ src/libostree/ostree-repo.c | 25 +++++++++++++++++++++++++ src/libostree/ostree-repo.h | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index 5f061c00..547e1509 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -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 diff --git a/src/libostree/libostree-devel.sym b/src/libostree/libostree-devel.sym index 07f918a1..a416b7c1 100644 --- a/src/libostree/libostree-devel.sym +++ b/src/libostree/libostree-devel.sym @@ -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; diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index 2aa8291d..e6d8a747 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -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) { diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h index 227fe597..682d4964 100644 --- a/src/libostree/ostree-repo.h +++ b/src/libostree/ostree-repo.h @@ -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);