chore(rust): update lockfile and format sources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-20 15:59:28 +09:00
co-authored by Copilot
parent 723017a11c
commit d05bd8a08d
25 changed files with 390 additions and 177 deletions
+21 -11
View File
@@ -4,8 +4,8 @@ pub mod types;
pub use digest::compute_digest;
pub use types::{Cache, CacheLaboratory, CacheLabsWrapper, CacheUser};
use anyhow::{anyhow, bail};
use crate::connection::MDRSConnection;
use anyhow::{anyhow, bail};
use std::collections::HashMap;
use std::fs;
use std::sync::{Arc, LazyLock, Mutex};
@@ -43,10 +43,21 @@ fn cache_file_path(remote: &str) -> std::path::PathBuf {
pub fn load_cache(remote: &str) -> Result<Cache, anyhow::Error> {
let cache_path = cache_file_path(remote);
if !cache_path.exists() {
bail!("Not logged in to `{}`. Run `mdrs login {}` first.", remote, remote);
bail!(
"Not logged in to `{}`. Run `mdrs login {}` first.",
remote,
remote
);
}
let data = fs::read_to_string(&cache_path)?;
serde_json::from_str::<Cache>(&data).map_err(|e| anyhow!("Cache for `{}` is invalid or outdated ({}). Run `mdrs login {}` to refresh it.", remote, e, remote))
serde_json::from_str::<Cache>(&data).map_err(|e| {
anyhow!(
"Cache for `{}` is invalid or outdated ({}). Run `mdrs login {}` to refresh it.",
remote,
e,
remote
)
})
}
// ---------------------------------------------------------------------------
@@ -61,9 +72,7 @@ pub fn load_cache(remote: &str) -> Result<Cache, anyhow::Error> {
/// - `flock(LOCK_EX)` on a dedicated `cache/{remote}.lock` file serializes
/// the entire read-check-refresh-write cycle across separate processes on
/// the same host.
pub async fn load_cache_with_token_refresh(
remote: &str,
) -> Result<Cache, anyhow::Error> {
pub async fn load_cache_with_token_refresh(remote: &str) -> Result<Cache, anyhow::Error> {
let lock = get_remote_lock(remote);
let _guard = lock.lock().await;
@@ -81,7 +90,11 @@ pub async fn load_cache_with_token_refresh(
let mut cache = load_cache(remote)?;
if crate::token::is_expired(&cache.token.refresh) {
bail!("Session for `{}` has expired. Please run `mdrs login {}` again.", remote, remote);
bail!(
"Session for `{}` has expired. Please run `mdrs login {}` again.",
remote,
remote
);
}
if crate::token::is_refresh_required(&cache.token.access, &cache.token.refresh) {
@@ -99,10 +112,7 @@ pub async fn load_cache_with_token_refresh(
/// Call the token-refresh endpoint and write the new access token back to the
/// cache file. The caller must already hold the per-remote async mutex.
async fn refresh_and_persist(
remote: &str,
cache: &Cache,
) -> Result<String, anyhow::Error> {
async fn refresh_and_persist(remote: &str, cache: &Cache) -> Result<String, anyhow::Error> {
let url = crate::commands::config::get_remote_url(remote)?
.ok_or_else(|| anyhow!("Remote `{}` is not configured.", remote))?;
let conn = MDRSConnection::new(&url);