Style: Automatische Formatierung & Clippy-Fixes
TruffleHog Secret Scan / TruffleHog (push) Successful in 16s
Security Scans / Trivy & OSV-Scanner (push) Successful in 27s
Code Quality (Auto-Format & Clippy-Fix) / Formatierung & Clippy automatisch beheben (push) Successful in 29s

This commit is contained in:
2026-09-12 22:32:35 +00:00
parent 4edf7e8a46
commit 29e41e8ea2
2 changed files with 24 additions and 31 deletions
+13 -20
View File
@@ -33,8 +33,8 @@ use std::sync::{OnceLock, RwLock};
pub use confy::ConfyError;
use program_ctdra::try_program_name;
use serde::de::DeserializeOwned;
use serde::Serialize;
use serde::de::DeserializeOwned;
use sudo_ctdra::is_run_as_root;
/// Optionaler benutzerdefinierter Konfigurationsdateiname (Standard: "config").
@@ -72,13 +72,11 @@ pub fn set_config_name(name: impl Into<String>) {
/// Liefert den konfigurierten Namen der Konfigurationsdatei (Standard: `"config"`).
pub fn get_config_name() -> String {
if let Some(lock) = CONFIG_NAME.get() {
if let Ok(guard) = lock.read() {
if let Some(name) = guard.as_ref() {
if let Some(lock) = CONFIG_NAME.get()
&& let Ok(guard) = lock.read()
&& let Some(name) = guard.as_ref() {
return name.clone();
}
}
}
DEFAULT_CONFIG_NAME.to_string()
}
@@ -100,11 +98,10 @@ pub fn clear_custom_dir() {
/// Liefert das aktuell gesetzte benutzerdefinierte Konfigurationsverzeichnis, falls vorhanden.
pub fn get_custom_dir() -> Option<PathBuf> {
if let Some(lock) = CUSTOM_CONFIG_DIR.get() {
if let Ok(guard) = lock.read() {
if let Some(lock) = CUSTOM_CONFIG_DIR.get()
&& let Ok(guard) = lock.read() {
return guard.clone();
}
}
None
}
@@ -126,11 +123,10 @@ pub fn clear_custom_path() {
/// Liefert den aktuell gesetzten expliziten Pfad zur Konfigurationsdatei, falls vorhanden.
pub fn get_custom_path() -> Option<PathBuf> {
if let Some(lock) = CUSTOM_CONFIG_PATH.get() {
if let Ok(guard) = lock.read() {
if let Some(lock) = CUSTOM_CONFIG_PATH.get()
&& let Ok(guard) = lock.read() {
return guard.clone();
}
}
None
}
@@ -263,20 +259,17 @@ where
{
let map_lock = GLOBAL_CONFIGS.get_or_init(|| RwLock::new(HashMap::new()));
if let Ok(guard) = map_lock.read() {
if let Some(entry) = guard.get(&TypeId::of::<T>()) {
if let Some(val) = entry.downcast_ref::<T>() {
if let Ok(guard) = map_lock.read()
&& let Some(entry) = guard.get(&TypeId::of::<T>())
&& let Some(val) = entry.downcast_ref::<T>() {
return val;
}
}
}
let mut guard = map_lock.write().unwrap();
if let Some(entry) = guard.get(&TypeId::of::<T>()) {
if let Some(val) = entry.downcast_ref::<T>() {
if let Some(entry) = guard.get(&TypeId::of::<T>())
&& let Some(val) = entry.downcast_ref::<T>() {
return val;
}
}
let loaded: T = load_config::<T>();
let boxed: &'static T = Box::leak(Box::new(loaded));
+11 -11
View File
@@ -1,7 +1,7 @@
use config_ctdra::{
clear_custom_dir, clear_custom_path, get_config, get_config_name, get_config_path,
ConfyError, clear_custom_dir, clear_custom_path, get_config, get_config_name, get_config_path,
get_custom_dir, get_custom_path, get_program_name, load, load_config, modify, modify_config,
save_config, set_config_name, set_custom_dir, set_custom_path, store, ConfyError,
save_config, set_config_name, set_custom_dir, set_custom_path, store,
};
use serde::{Deserialize, Serialize};
use std::env;
@@ -17,17 +17,11 @@ fn lock_test() -> std::sync::MutexGuard<'static, ()> {
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Default)]
struct DummyAppConfig {
general: DummyGeneral,
}
impl Default for DummyAppConfig {
fn default() -> Self {
Self {
general: DummyGeneral::default(),
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
struct DummyGeneral {
@@ -199,7 +193,10 @@ fn test_load_config_fallback_and_invalid_toml() {
// load::<T>() sollte bei ungültigem TOML fehlschlagen
let res: Result<CustomServerConfig, ConfyError> = load();
assert!(res.is_err(), "Laden von korruptem TOML sollte mit ConfyError fehlschlagen");
assert!(
res.is_err(),
"Laden von korruptem TOML sollte mit ConfyError fehlschlagen"
);
// load_config::<T>() fällt im Fehlerfall auf Default zurück
let loaded_default: CustomServerConfig = load_config();
@@ -346,7 +343,10 @@ fn test_get_config_singleton_cache() {
// Zweiter Aufruf: liefert dieselbe statische Referenz
let ref2: &'static DatabaseConfig = get_config();
assert!(std::ptr::eq(ref1, ref2), "get_config muss dieselbe Referenz zurückgeben");
assert!(
std::ptr::eq(ref1, ref2),
"get_config muss dieselbe Referenz zurückgeben"
);
cleanup_temp_file(&temp_file);
clear_custom_path();