From: Colin Walters Date: Tue, 26 Apr 2022 23:30:01 +0000 (-0400) Subject: Add a `repo()` accessor to `TransactionGuard` X-Git-Tag: archive/raspbian/2022.4-1+rpi1^2~9^2^2~20^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a5ef4cd5cc4c68deaca3a8414a8ce727b755731e;p=ostree.git Add a `repo()` accessor to `TransactionGuard` 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. --- diff --git a/rust-bindings/src/repo.rs b/rust-bindings/src/repo.rs index 35a15248..5d34f98b 100644 --- a/rust-bindings/src/repo.rs +++ b/rust-bindings/src/repo.rs @@ -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>( mut self, diff --git a/rust-bindings/tests/util/mod.rs b/rust-bindings/tests/util/mod.rs index 472bf455..28cca926 100644 --- a/rust-bindings/tests/util/mod.rs +++ b/rust-bindings/tests/util/mod.rs @@ -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::()