pub struct Config {
pub daemon: Option<DaemonConfig>,
pub monitored: MonitoredConfig,
pub logging: LoggingConfig,
pub cache: Option<CacheConfig>,
pub watchdog: Option<WatchdogConfig>,
}Expand description
Infrastructure configuration for fsmon.
The config file lives at ~/.config/fsmon/fsmon.toml.
All path resolution is based on the original user (not root’s HOME).
Daemon (running as root via sudo) uses SUDO_UID to find the right home.
CLI (running as user) uses the user’s own HOME directly.
This file is manually edited. Only infrastructure paths go here.
Monitored path entries are stored in the separate store file (see [monitored].path).
§示例
use fsmon::common::config::Config;
// 加载配置文件
let config = Config::load()?;
// 访问配置项
if let Some(daemon) = &config.daemon {
if let Some(debug) = daemon.debug {
println!("Debug mode: {}", debug);
}
}Fields§
§daemon: Option<DaemonConfig>§monitored: MonitoredConfig§logging: LoggingConfig§cache: Option<CacheConfig>§watchdog: Option<WatchdogConfig>Implementations§
Source§impl Config
impl Config
Sourcepub fn user_path() -> PathBuf
pub fn user_path() -> PathBuf
Return the user config file path: $XDG_CONFIG_HOME/fsmon/fsmon.toml
Falls back to ~/.config/fsmon/fsmon.toml.
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
Load config from file. Returns default Config if file doesn’t exist.
Also returns default if file exists but contains only comments (e.g.
a reference file created by fsmon init).
§Errors
Returns an error if:
- The config file exists but cannot be read
- The config file contains invalid TOML syntax
- The config file cannot be parsed into a
Configstruct
Sourcepub fn resolve_paths(&mut self) -> Result<()>
pub fn resolve_paths(&mut self) -> Result<()>
Expand ~ in all paths using the original user’s home directory.
Sourcepub fn ensure_monitored_dir() -> Result<()>
pub fn ensure_monitored_dir() -> Result<()>
Ensure the monitored store’s parent directory exists.
Called by fsmon add / fsmon monitored on first use.