From 1f724aced5da60db51a13ce463bbd4ddd34f92ac Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Fri, 11 Jul 2025 13:08:43 +0200 Subject: [PATCH] Create cache dir if it doens't exist Signed-off-by: Lee Smet --- mycelium/src/cdn.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mycelium/src/cdn.rs b/mycelium/src/cdn.rs index e3f3e1f..75ccf7b 100644 --- a/mycelium/src/cdn.rs +++ b/mycelium/src/cdn.rs @@ -12,7 +12,7 @@ use futures::{stream::FuturesUnordered, StreamExt}; use reqwest::header::CONTENT_TYPE; use tokio::net::TcpListener; use tokio_util::sync::CancellationToken; -use tracing::{debug, error, warn}; +use tracing::{debug, error, info, warn}; /// Cdn functionality. Urls of specific format lead to donwnlaoding of metadata from the registry, /// and serving of chunks. @@ -41,6 +41,16 @@ impl Cdn { let state = Cache { base: self.cache.clone(), }; + + if !self.cache.exists() { + info!(dir = %self.cache.display(), "Creating cache dir"); + std::fs::create_dir(&self.cache)?; + } + + if !self.cache.is_dir() { + return Err("Cache dir is not a directory".into()); + } + let router = Router::new().route("/", get(cdn)).with_state(state); let cancel_token = self.cancel_token.clone();