diff options
| -rw-r--r-- | clippy.toml | 1 | ||||
| -rw-r--r-- | crates/arti/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/fs-mistrust/src/dir.rs | 4 | ||||
| -rw-r--r-- | crates/fslock-guard/src/lib.rs | 8 | ||||
| -rw-r--r-- | crates/tor-dirmgr/src/storage/sqlite.rs | 2 | ||||
| -rw-r--r-- | crates/tor-keymgr/src/keystore/arti.rs | 13 |
6 files changed, 19 insertions, 11 deletions
diff --git a/clippy.toml b/clippy.toml index 070dab1bb..a0bd042f1 100644 --- a/clippy.toml +++ b/clippy.toml @@ -7,4 +7,5 @@ disallowed-methods = [ { path = "futures::channel::oneshot::channel", reason = "Use tor_async_utils::oneshot to avoid bug with select macro" }, { path = "std::path::Path::display", reason = "See tor_basic_utils::PathExt::display_lossy" }, # { path = "std::time::SystemTime::now", reason = "prefer using SleepProvider::wallclock instead when possible" }, + { path = "std::path::Path::exists", reason = "Prefer using std::Path::try_exists or std::fs::exists" }, ] diff --git a/crates/arti/src/lib.rs b/crates/arti/src/lib.rs index f977f32d3..945cfef5b 100644 --- a/crates/arti/src/lib.rs +++ b/crates/arti/src/lib.rs @@ -203,7 +203,7 @@ async fn run<R: Runtime>( .make_secure_dir(parent)?; // It's just a unix thing; if we leave this sitting around, binding to it won't // work right. There is probably a better solution. - if path.exists() { + if path.try_exists()? { std::fs::remove_file(&path)?; } diff --git a/crates/fs-mistrust/src/dir.rs b/crates/fs-mistrust/src/dir.rs index bd94afd4d..5cebd8d41 100644 --- a/crates/fs-mistrust/src/dir.rs +++ b/crates/fs-mistrust/src/dir.rs @@ -431,14 +431,14 @@ mod test { .unwrap() .write_all("be the other guy".as_bytes()) .unwrap(); - assert!(checked.join("bar.tmp").unwrap().exists()); + assert!(checked.join("bar.tmp").unwrap().try_exists().unwrap()); checked .write_and_replace("bar.txt", "its hard and nobody understands") .unwrap(); // Temp file should be gone. - assert!(!checked.join("bar.tmp").unwrap().exists()); + assert!(!checked.join("bar.tmp").unwrap().try_exists().unwrap()); let s4 = checked.read_to_string("bar.txt").unwrap(); assert_eq!(s4, "its hard and nobody understands"); } diff --git a/crates/fslock-guard/src/lib.rs b/crates/fslock-guard/src/lib.rs index f69b37048..5a40c04ad 100644 --- a/crates/fslock-guard/src/lib.rs +++ b/crates/fslock-guard/src/lib.rs @@ -316,9 +316,9 @@ mod tests { test_temp_dir!().used_by(|dir| { let file = dir.join("file"); let flock_guard = LockFileGuard::lock(&file).unwrap(); - assert!(file.exists()); + assert!(file.try_exists().unwrap()); drop(flock_guard); - assert!(file.exists()); + assert!(file.try_exists().unwrap()); }); } @@ -327,9 +327,9 @@ mod tests { test_temp_dir!().used_by(|dir| { let file = dir.join("file"); let flock_guard = LockFileGuard::lock(&file).unwrap(); - assert!(file.exists()); + assert!(file.try_exists().unwrap()); assert!(flock_guard.delete_lock_file(&file).is_ok()); - assert!(!file.exists()); + assert!(!file.try_exists().unwrap()); }); } } diff --git a/crates/tor-dirmgr/src/storage/sqlite.rs b/crates/tor-dirmgr/src/storage/sqlite.rs index 3ea4dc098..c58ac9953 100644 --- a/crates/tor-dirmgr/src/storage/sqlite.rs +++ b/crates/tor-dirmgr/src/storage/sqlite.rs @@ -1413,7 +1413,7 @@ pub(crate) mod test { // Nothing there: can't open read-only let r = SqliteStore::from_path_and_mistrust(tmp.path(), &mistrust, true); assert!(r.is_err()); - assert!(!tmp.path().join("dir_blobs").exists()); + assert!(!tmp.path().join("dir_blobs").try_exists().unwrap()); // Opening it read-write will crate the files { diff --git a/crates/tor-keymgr/src/keystore/arti.rs b/crates/tor-keymgr/src/keystore/arti.rs index ab57a5e3a..cd850aaa0 100644 --- a/crates/tor-keymgr/src/keystore/arti.rs +++ b/crates/tor-keymgr/src/keystore/arti.rs @@ -9,6 +9,7 @@ use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; use std::result::Result as StdResult; use std::str::FromStr; +use std::sync::Arc; use crate::keystore::{EncodableKey, ErasedKey, KeySpecifier, Keystore}; use crate::{arti_path, ArtiPath, ArtiPathUnavailableError, KeyPath, KeyType, KeystoreId, Result}; @@ -125,7 +126,13 @@ impl Keystore for ArtiNativeKeystore { err: err.into(), })?; - Ok(abs_path.exists()) + Ok(abs_path + .try_exists() + .map_err(|e| ArtiNativeKeystoreError::Filesystem { + action: FilesystemAction::Read, + path: self.keystore_dir.as_path().into(), + err: Arc::new(e), + })?) } fn get(&self, key_spec: &dyn KeySpecifier, key_type: &KeyType) -> Result<Option<ErasedKey>> { @@ -508,10 +515,10 @@ mod tests { .join(key_store.rel_path(&key_spec, ed_key_type).unwrap()); // The key and its parent directories don't exist yet. - assert!(!path.parent().unwrap().exists()); + assert!(!path.parent().unwrap().try_exists().unwrap()); assert!(key_store.insert(&*key, &key_spec, ed_key_type).is_ok()); // insert() is supposed to create the missing directories - assert!(path.parent().unwrap().exists()); + assert!(path.parent().unwrap().try_exists().unwrap()); // Found! assert_found!( |
