From 3aefd53c3cb719f25654a1499c623d6a42e6977e Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 16 Nov 2023 13:44:05 +0100 Subject: [PATCH] @PascalinDe suggestions --- src/client.rs | 5 ++++- tests/client.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index ab2ed9d..81f2693 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,7 +3,7 @@ use std::io::Write; use std::time::SystemTime; use std::{convert::TryFrom, fs, io, path::Path, sync::Arc}; -use anyhow::{bail, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use arti_client::{DataStream, TorClient, TorClientConfig}; use http::{Request, Response}; use time::OffsetDateTime; @@ -126,6 +126,9 @@ impl Client { // This will probably fail for the first minutes of the day, when the churn is not yet // available in the new version. fn get_cache_state(cache_path: &Path) -> Result { + if !cache_path.is_dir() { + return Err(anyhow!("Corrupt cache: cache-directory doesn't exist")); + } if check_directory(cache_path).is_err() { return Ok(UpdateNeeded::All); } diff --git a/tests/client.rs b/tests/client.rs index b8ae24a..72abddf 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -131,7 +131,7 @@ async fn test_directory_not_existing() { let root_cause = error.root_cause(); assert_eq!( format!("{}", root_cause), - "No such file or directory (os error 2)" + "Corrupt cache: cache-directory doesn't exist" ); }