diff rust/hg-core/src/lock.rs @ 51906:db7dbe6f7bb2

rust: add Vfs trait This will allow for the use of multiple vfs like in the Python implementation, as well as hiding the details of the upcoming Python vfs wrapper to hg-core.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 19 Jun 2024 14:49:35 +0200
parents e98fd81bb151
children 7be39c5110c9
line wrap: on
line diff
--- a/rust/hg-core/src/lock.rs	Wed Jun 19 12:49:26 2024 +0200
+++ b/rust/hg-core/src/lock.rs	Wed Jun 19 14:49:35 2024 +0200
@@ -2,7 +2,7 @@
 
 use crate::errors::HgError;
 use crate::errors::HgResultExt;
-use crate::vfs::Vfs;
+use crate::vfs::VfsImpl;
 use std::io;
 use std::io::ErrorKind;
 
@@ -21,7 +21,7 @@
 /// The return value of `f` is dropped in that case. If all is successful, the
 /// return value of `f` is forwarded.
 pub fn try_with_lock_no_wait<R>(
-    hg_vfs: Vfs,
+    hg_vfs: &VfsImpl,
     lock_filename: &str,
     f: impl FnOnce() -> R,
 ) -> Result<R, LockError> {
@@ -57,7 +57,7 @@
     Err(LockError::AlreadyHeld)
 }
 
-fn break_lock(hg_vfs: Vfs, lock_filename: &str) -> Result<(), LockError> {
+fn break_lock(hg_vfs: &VfsImpl, lock_filename: &str) -> Result<(), LockError> {
     try_with_lock_no_wait(hg_vfs, &format!("{}.break", lock_filename), || {
         // Check again in case some other process broke and
         // acquired the lock in the meantime
@@ -71,7 +71,7 @@
 
 #[cfg(unix)]
 fn make_lock(
-    hg_vfs: Vfs,
+    hg_vfs: &VfsImpl,
     lock_filename: &str,
     data: &str,
 ) -> Result<(), HgError> {
@@ -82,7 +82,7 @@
 }
 
 fn read_lock(
-    hg_vfs: Vfs,
+    hg_vfs: &VfsImpl,
     lock_filename: &str,
 ) -> Result<Option<String>, HgError> {
     let link_target =
@@ -98,7 +98,7 @@
     }
 }
 
-fn unlock(hg_vfs: Vfs, lock_filename: &str) -> Result<(), HgError> {
+fn unlock(hg_vfs: &VfsImpl, lock_filename: &str) -> Result<(), HgError> {
     hg_vfs.remove_file(lock_filename)
 }