diff rust/hg-core/src/vfs.rs @ 48417:5734b03ecf3e

rhg: Initial repository locking Initial Rust implementation of locking based on the `.hg/wlock` symlink (or file), with lock breaking when the recorded pid and hostname show that a lock was left by a local process that is not running anymore (as it might have been killed). Differential Revision: https://phab.mercurial-scm.org/D11835
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 22 Mar 2021 09:07:10 +0100
parents d5a91701f7dc
children abeae090ce67
line wrap: on
line diff
--- a/rust/hg-core/src/vfs.rs	Mon Nov 29 17:37:08 2021 +0100
+++ b/rust/hg-core/src/vfs.rs	Mon Mar 22 09:07:10 2021 +0100
@@ -87,6 +87,26 @@
         std::fs::rename(&from, &to)
             .with_context(|| IoErrorContext::RenamingFile { from, to })
     }
+
+    pub fn remove_file(
+        &self,
+        relative_path: impl AsRef<Path>,
+    ) -> Result<(), HgError> {
+        let path = self.join(relative_path);
+        std::fs::remove_file(&path)
+            .with_context(|| IoErrorContext::RemovingFile(path))
+    }
+
+    #[cfg(unix)]
+    pub fn create_symlink(
+        &self,
+        relative_link_path: impl AsRef<Path>,
+        target_path: impl AsRef<Path>,
+    ) -> Result<(), HgError> {
+        let link_path = self.join(relative_link_path);
+        std::os::unix::fs::symlink(target_path, &link_path)
+            .with_context(|| IoErrorContext::WritingFile(link_path))
+    }
 }
 
 fn fs_metadata(