diff options
Diffstat (limited to 'azalea-auth/src')
| -rw-r--r-- | azalea-auth/src/auth.rs | 2 | ||||
| -rw-r--r-- | azalea-auth/src/cache.rs | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/azalea-auth/src/auth.rs b/azalea-auth/src/auth.rs index 0cc36fcf..ec20d31e 100644 --- a/azalea-auth/src/auth.rs +++ b/azalea-auth/src/auth.rs @@ -130,7 +130,7 @@ pub async fn auth(email: &str, opts: AuthOpts) -> Result<AuthResult, AuthError> }, ) .await { - log::warn!("Error while caching auth data: {}", e); + log::error!("{}", e); } } } diff --git a/azalea-auth/src/cache.rs b/azalea-auth/src/cache.rs index e84c60fd..404b05ff 100644 --- a/azalea-auth/src/cache.rs +++ b/azalea-auth/src/cache.rs @@ -13,6 +13,8 @@ pub enum CacheError { Read(std::io::Error), #[error("Failed to write cache file: {0}")] Write(std::io::Error), + #[error("Failed to create cache file directory: {0}")] + MkDir(std::io::Error), #[error("Failed to parse cache file: {0}")] Parse(serde_json::Error), } @@ -73,6 +75,16 @@ async fn get_entire_cache(cache_file: &Path) -> Result<Vec<CachedAccount>, Cache async fn set_entire_cache(cache_file: &Path, cache: Vec<CachedAccount>) -> Result<(), CacheError> { log::trace!("saving cache: {:?}", cache); + if !cache_file.exists() { + let cache_file_parent = cache_file + .parent() + .expect("Cache file is root directory and also doesn't exist."); + log::debug!( + "Making cache file parent directory at {}", + cache_file_parent.to_string_lossy() + ); + std::fs::create_dir_all(cache_file_parent).map_err(CacheError::MkDir)?; + } let mut cache_file = File::create(cache_file).await.map_err(CacheError::Write)?; let cache = serde_json::to_string_pretty(&cache).map_err(CacheError::Parse)?; cache_file |
