Skip to content

Commit e297046

Browse files
committed
inotify: check filename before reloading meta file
1 parent afa884d commit e297046

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::OsString;
12
use std::future::IntoFuture;
23
use std::io::Cursor;
34
use std::path::{Path, PathBuf};
@@ -81,6 +82,12 @@ async fn main() -> anyhow::Result<()> {
8182

8283
let inotify = {
8384
let meta = std::path::absolute(&args.meta)?;
85+
let meta_name: OsString = match meta.file_name() {
86+
Some(parent) => parent.into(),
87+
None => {
88+
anyhow::bail!("Failed to watch for meta file changes. Filename could not be deteminated.")
89+
}
90+
};
8491
let meta_parent = match meta.parent() {
8592
Some(parent) => parent.to_path_buf(),
8693
None => anyhow::bail!(
@@ -96,7 +103,15 @@ async fn main() -> anyhow::Result<()> {
96103
let mut buf = [0; 1024];
97104
let mut stream = inotify.into_event_stream(&mut buf)?;
98105

99-
while stream.next().await.transpose()?.is_some() {
106+
while let Some(event) = stream.next().await.transpose()? {
107+
let name = match event.name {
108+
Some(name) => name,
109+
None => continue,
110+
};
111+
112+
if name != meta_name {
113+
continue;
114+
}
100115
meta_update_tx.send(()).await.unwrap()
101116
}
102117

0 commit comments

Comments
 (0)