Skip to content

Commit

Permalink
Add a repo() accessor to TransactionGuard
Browse files Browse the repository at this point in the history
I want to write APIs that *require* the caller to have set up
an ostree transaction.  It's natural to require passing a guard
to do so.  But then we want an accessor for the repo.
  • Loading branch information
cgwalters committed Apr 26, 2022
1 parent 31bf2af commit b42b0ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ pub struct TransactionGuard<'a> {
}

impl<'a> TransactionGuard<'a> {
/// Returns a reference to the repository.
pub fn repo(&self) -> &Repo {
// SAFETY: This is only set to None in `commit`, which consumes self
self.repo.unwrap()
}

/// Commit this transaction.
pub fn commit<P: IsA<gio::Cancellable>>(
mut self,
Expand Down
3 changes: 2 additions & 1 deletion tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub fn commit(repo: &ostree::Repo, mtree: &ostree::MutableTree, ref_: &str) -> G
let txn = repo
.auto_transaction(NONE_CANCELLABLE)
.expect("prepare transaction");
let repo_file = repo
let repo_file = txn
.repo()
.write_mtree(mtree, NONE_CANCELLABLE)
.expect("write mtree")
.downcast::<ostree::RepoFile>()
Expand Down

0 comments on commit b42b0ad

Please sign in to comment.