add path for FileWatch snafu

Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
tison
2024-03-26 14:36:16 +08:00
parent 31b051650d
commit 4399a77031
4 changed files with 21 additions and 17 deletions

View File

@@ -64,8 +64,9 @@ pub enum Error {
username: String,
},
#[snafu(display("Failed to initialize a watcher for file"))]
#[snafu(display("Failed to initialize a watcher for file {}", path))]
FileWatch {
path: Option<String>,
#[snafu(source)]
error: notify::Error,
},

View File

@@ -43,13 +43,15 @@ impl WatchFileUserProvider {
};
let (tx, rx) = channel::<DebounceEventResult>();
let mut debouncer =
new_debouncer(Duration::from_secs(1), None, tx).context(FileWatchSnafu)?;
let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx)
.context(FileWatchSnafu { path: None })?;
debouncer
.watcher()
.watch(Path::new(filepath), RecursiveMode::NonRecursive)
.context(FileWatchSnafu)?;
.context(FileWatchSnafu {
path: Some(filepath),
})?;
let filepath = filepath.to_string();
std::thread::spawn(move || {
let _hold = debouncer;

View File

@@ -449,8 +449,9 @@ pub enum Error {
))]
UnexpectedPhysicalTable { location: Location },
#[snafu(display("Failed to initialize a watcher for file"))]
#[snafu(display("Failed to initialize a watcher for file {}", path))]
FileWatch {
path: Option<String>,
#[snafu(source)]
error: notify::Error,
},

View File

@@ -200,21 +200,21 @@ pub fn maybe_watch_tls_config(tls_server_config: Arc<ReloadableTlsServerConfig>)
let tls_server_config_for_watcher = tls_server_config.clone();
let (tx, rx) = channel::<notify::Result<notify::Event>>();
let mut watcher = notify::recommended_watcher(tx).context(FileWatchSnafu)?;
let mut watcher = notify::recommended_watcher(tx).context(FileWatchSnafu { path: None })?;
let cert_path = tls_server_config.get_tls_option().cert_path();
watcher
.watch(
tls_server_config.get_tls_option().cert_path(),
RecursiveMode::NonRecursive,
)
.context(FileWatchSnafu)?;
.watch(cert_path, RecursiveMode::NonRecursive)
.context(FileWatchSnafu {
path: Some(cert_path),
})?;
let key_path = tls_server_config.get_tls_option().key_path();
watcher
.watch(
tls_server_config.get_tls_option().key_path(),
RecursiveMode::NonRecursive,
)
.context(FileWatchSnafu)?;
.watch(key_path, RecursiveMode::NonRecursive)
.context(FileWatchSnafu {
path: Some(key_path),
})?;
std::thread::spawn(move || {
let _watcher = watcher;