lib/repo: Add ostree_repo_equal() for comparing repos

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
This commit is contained in:
Philip Withnall 2017-09-15 15:26:22 +01:00 committed by Atomic Bot
parent 1036cc8084
commit 981eb6c226
4 changed files with 32 additions and 0 deletions

View 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

View 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;

View 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)
{

View 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);