Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/logging.rs @ 52297:7be39c5110c9
hg-core: add a complete VFS
This will be used from Python in a later change.
More changes are needed in hg-core and rhg to properly clean up the APIs
of the old VFS implementation but it can be done when the dust settles
and we start adding more functionality to the pure Rust VFS.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 29 Jul 2024 20:47:43 +0200 |
parents | db7dbe6f7bb2 |
children |
line wrap: on
line diff
--- a/rust/hg-core/src/logging.rs Mon Jul 29 20:28:42 2024 +0200 +++ b/rust/hg-core/src/logging.rs Mon Jul 29 20:47:43 2024 +0200 @@ -1,6 +1,7 @@ use crate::errors::{HgError, HgResultExt, IoErrorContext, IoResultExt}; -use crate::vfs::VfsImpl; +use crate::vfs::{Vfs, VfsImpl}; use std::io::Write; +use std::path::Path; /// An utility to append to a log file with the given name, and optionally /// rotate it after it reaches a certain maximum size. @@ -64,15 +65,20 @@ for i in (1..self.max_files).rev() { self.vfs .rename( - format!("{}.{}", self.name, i), - format!("{}.{}", self.name, i + 1), + Path::new(&format!("{}.{}", self.name, i)), + Path::new(&format!("{}.{}", self.name, i + 1)), + false, ) .io_not_found_as_none()?; } // Then rename `{name}` to `{name}.1`. This is the // previously-opened `file`. self.vfs - .rename(self.name, format!("{}.1", self.name)) + .rename( + Path::new(&self.name), + Path::new(&format!("{}.1", self.name)), + false, + ) .io_not_found_as_none()?; // Finally, create a new `{name}` file and replace our `file` // handle. @@ -87,9 +93,7 @@ #[test] fn test_rotation() { let temp = tempfile::tempdir().unwrap(); - let vfs = VfsImpl { - base: temp.path().to_owned(), - }; + let vfs = VfsImpl::new(temp.path().to_owned(), false); let logger = LogFile::new(vfs.clone(), "log") .max_size(Some(3)) .max_files(2);