summaryrefslogtreecommitdiff
path: root/crates/tor-persist/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-persist/src')
-rw-r--r--crates/tor-persist/src/fs.rs8
-rw-r--r--crates/tor-persist/src/fs/clean.rs13
-rw-r--r--crates/tor-persist/src/slug/timestamp.rs2
-rw-r--r--crates/tor-persist/src/state_dir.rs11
4 files changed, 18 insertions, 16 deletions
diff --git a/crates/tor-persist/src/fs.rs b/crates/tor-persist/src/fs.rs
index 1e46abda2..c70cff429 100644
--- a/crates/tor-persist/src/fs.rs
+++ b/crates/tor-persist/src/fs.rs
@@ -14,9 +14,9 @@ use oneshot_fused_workaround as oneshot;
use serde::{Serialize, de::DeserializeOwned};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
-use std::time::SystemTime;
use tor_error::warn_report;
use tracing::info;
+use web_time_compat::{SystemTime, SystemTimeExt};
/// Implementation of StateMgr that stores state as JSON files on disk.
///
@@ -223,7 +223,7 @@ impl StateMgr for FsStateMgr {
.try_lock()
.map_err(|e| Error::new(e, Action::Locking, self.err_resource_lock()))?
{
- self.clean(SystemTime::now());
+ self.clean(SystemTime::get());
Ok(LockStatus::NewlyAcquired)
} else {
Ok(LockStatus::NoLock)
@@ -341,7 +341,7 @@ mod test {
assert_eq!(count, 3); // two files, one lock.
// Now we can make sure that "clean" actually removes the right file.
- store.clean(SystemTime::now() + Duration::from_secs(365 * 86400));
+ store.clean(SystemTime::get() + Duration::from_secs(365 * 86400));
let lst: Vec<_> = statedir.read_dir().unwrap().collect();
assert_eq!(lst.len(), 2); // one file, one lock.
assert!(
@@ -374,7 +374,7 @@ mod test {
// Make the store directory read-only and make sure that we can't delete from it.
std::fs::set_permissions(&statedir, ro_dir).unwrap();
- store.clean(SystemTime::now() + Duration::from_secs(365 * 86400));
+ store.clean(SystemTime::get() + Duration::from_secs(365 * 86400));
let lst: Vec<_> = statedir.read_dir().unwrap().collect();
if lst.len() == 2 {
// We must be root. Don't do any more tests here.
diff --git a/crates/tor-persist/src/fs/clean.rs b/crates/tor-persist/src/fs/clean.rs
index 887cb1dc3..103a07261 100644
--- a/crates/tor-persist/src/fs/clean.rs
+++ b/crates/tor-persist/src/fs/clean.rs
@@ -1,14 +1,12 @@
//! Code to remove obsolete and extraneous files from a filesystem-based state
//! directory.
-use std::{
- path::{Path, PathBuf},
- time::{Duration, SystemTime},
-};
+use std::path::{Path, PathBuf};
use tor_basic_utils::PathExt as _;
use tor_error::warn_report;
use tracing::warn;
+use web_time_compat::{Duration, SystemTime};
/// Return true if `path` looks like a filename we'd like to remove from our
/// state directory.
@@ -114,6 +112,7 @@ mod test {
#![allow(clippy::needless_pass_by_value)]
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
use super::*;
+ use web_time_compat::SystemTimeExt;
#[test]
fn fnames() {
@@ -135,7 +134,7 @@ mod test {
let dir = tempfile::TempDir::new().unwrap();
let fname1 = dir.path().join("quokka");
- let now = SystemTime::now();
+ let now = SystemTime::get();
std::fs::write(fname1, "hello world").unwrap();
let mut r = std::fs::read_dir(dir.path()).unwrap();
@@ -147,7 +146,7 @@ mod test {
#[test]
fn list() {
let dir = tempfile::TempDir::new().unwrap();
- let now = SystemTime::now();
+ let now = SystemTime::get();
let fname1 = dir.path().join("quokka.toml");
std::fs::write(fname1, "hello world").unwrap();
@@ -171,7 +170,7 @@ mod test {
fn absent() {
let dir = tempfile::TempDir::new().unwrap();
let dir2 = dir.path().join("subdir_that_doesnt_exist");
- let r = files_to_delete(&dir2, SystemTime::now());
+ let r = files_to_delete(&dir2, SystemTime::get());
assert!(r.is_empty());
}
}
diff --git a/crates/tor-persist/src/slug/timestamp.rs b/crates/tor-persist/src/slug/timestamp.rs
index 502efade0..079d3e79f 100644
--- a/crates/tor-persist/src/slug/timestamp.rs
+++ b/crates/tor-persist/src/slug/timestamp.rs
@@ -4,7 +4,6 @@ use crate::slug::{BadSlug, Slug};
use std::fmt;
use std::str::FromStr;
-use std::time::SystemTime;
use derive_more::{From, Into};
use thiserror::Error;
@@ -12,6 +11,7 @@ use time::format_description::FormatItem;
use time::macros::format_description;
use time::{OffsetDateTime, PrimitiveDateTime};
use tor_error::{Bug, into_internal};
+use web_time_compat::SystemTime;
/// A UTC timestamp that can be encoded in ISO 8601 format,
/// and that can be used as a `Slug`.
diff --git a/crates/tor-persist/src/state_dir.rs b/crates/tor-persist/src/state_dir.rs
index 5fa099655..61069fb4c 100644
--- a/crates/tor-persist/src/state_dir.rs
+++ b/crates/tor-persist/src/state_dir.rs
@@ -70,6 +70,7 @@
//! use tor_persist::state_dir;
//! use state_dir::{InstanceIdentity, InstancePurgeHandler};
//! use state_dir::{InstancePurgeInfo, InstanceStateHandle, StateDirectory, StorageHandle};
+//! use web_time_compat::SystemTimeExt;
//! #
//! # // fake up some things; we do this rather than using real ones
//! # // since this example will move, with the module, to a lower level crate.
@@ -134,7 +135,7 @@
//! retain_for: Duration,
//! ) -> Result<(), Error> {
//! state_dir.purge_instances(
-//! SystemTime::now(),
+//! SystemTime::get(),
//! &mut PurgeHandler(currently_configured_nicks, retain_for),
//! )?;
//! Ok(())
@@ -174,7 +175,7 @@ use std::io;
use std::marker::PhantomData;
use std::path::Path;
use std::sync::Arc;
-use std::time::{Duration, SystemTime};
+use web_time_compat::{Duration, SystemTime, SystemTimeExt};
use derive_deftly::{Deftly, define_derive_deftly};
use derive_more::{AsRef, Deref};
@@ -1013,7 +1014,8 @@ fn touch_instance_dir(dir: &CheckedDir) -> Result<()> {
let dir = dir.as_path();
let resource = || Resource::Directory { dir: dir.into() };
- filetime::set_file_mtime(dir, filetime::FileTime::now())
+ let mtime = filetime::FileTime::from_system_time(SystemTime::get());
+ filetime::set_file_mtime(dir, mtime)
.map_err(|source| Error::new(source, Action::Initializing, resource()))
}
@@ -1137,6 +1139,7 @@ mod test {
use tor_basic_utils::PathExt as _;
use tor_error::HasKind as _;
use tracing_test::traced_test;
+ use web_time_compat::SystemTimeExt;
use tor_error::ErrorKind as TEK;
@@ -1147,7 +1150,7 @@ mod test {
}
fn now() -> SystemTime {
- SystemTime::now()
+ SystemTime::get()
}
struct Garlic(Slug);