aboutsummaryrefslogtreecommitdiff
path: root/azalea-auth/src
diff options
context:
space:
mode:
authorUbuntu <github@matdoes.dev>2022-10-18 19:31:27 +0000
committerUbuntu <github@matdoes.dev>2022-10-18 19:31:27 +0000
commitc0338cac35db6849a0a82a451db0e62d1fc24a0f (patch)
treeb6310972b1100ca72e289a76515b87fe7554e561 /azalea-auth/src
parent4c9de35cc2185b5ee8f844f907a50fa9a46b0bf2 (diff)
downloadazalea-drasl-c0338cac35db6849a0a82a451db0e62d1fc24a0f.tar.xz
Create cache file directory if it doesn't exist
Diffstat (limited to 'azalea-auth/src')
-rw-r--r--azalea-auth/src/auth.rs2
-rw-r--r--azalea-auth/src/cache.rs12
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