tuwunel_service/storage/provider/
local.rs1use std::{fs, sync::Arc};
2
3use object_store::local::LocalFileSystem;
4use tuwunel_core::{
5 Result,
6 config::{StorageProvider, StorageProviderLocal},
7 debug, debug_info, error, trace,
8};
9
10use super::Provider;
11
12#[tracing::instrument(name = "new", level = "info", skip_all, err)]
13pub(in super::super) fn new(
14 args: &crate::Args<'_>,
15 name: &str,
16 config: &StorageProviderLocal,
17) -> Result<Option<(String, Arc<Provider>)>> {
18 if config.base_path.is_empty() {
20 debug!(?name, "'base_path' is not set. This configuration will be skipped");
21 return Ok(None);
22 }
23
24 if config.create_if_missing {
25 trace!(
26 %name,
27 path = ?config.base_path,
28 "Creating directory on local filesystem if missing...",
29 );
30
31 fs::create_dir_all(&config.base_path)?;
32 }
33
34 trace!(?name, ?config, "Initializing LocalFS...");
35
36 let provider = LocalFileSystem::new_with_prefix(config.base_path.clone())
37 .inspect_err(|e| error!("Failed to configure LocalFS storage client: {e}"))?
38 .with_automatic_cleanup(config.delete_empty_directories);
39
40 debug_info!(
41 name = %name,
42 path = ?config.base_path,
43 "Started Local FS storage client.",
44 );
45
46 let provider = Provider {
47 name: name.to_owned(),
48 base_path: None, config: StorageProvider::local(config.clone()),
50 startup_check: config.startup_check,
51 services: args.services.clone(),
52 provider: Box::new(provider),
53 };
54
55 Ok(Some((name.to_owned(), Arc::new(provider))))
56}