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