mirror of
https://git.neonteam.dev/amizing/robinsr.git
synced 2025-03-12 03:28:30 -04:00
fix: modify file listener to ensure the file is modified
This commit is contained in:
parent
6d9bf58a85
commit
c034f8a2f9
@ -6,7 +6,7 @@ use std::{
|
|||||||
Arc,
|
Arc,
|
||||||
atomic::{AtomicU32, Ordering},
|
atomic::{AtomicU32, Ordering},
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::{Duration, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
@ -113,6 +113,11 @@ impl Gateway {
|
|||||||
tracing::info!("watching freesr-data.json changes");
|
tracing::info!("watching freesr-data.json changes");
|
||||||
|
|
||||||
let mut shutdown_rx = session.read().await.shutdown_rx.clone();
|
let mut shutdown_rx = session.read().await.shutdown_rx.clone();
|
||||||
|
|
||||||
|
let mut last_modified = std::fs::metadata(path)
|
||||||
|
.and_then(|meta| meta.modified())
|
||||||
|
.unwrap_or(SystemTime::UNIX_EPOCH);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
res = rx.recv() => {
|
res = rx.recv() => {
|
||||||
@ -122,17 +127,25 @@ impl Gateway {
|
|||||||
match res {
|
match res {
|
||||||
Ok(events) => {
|
Ok(events) => {
|
||||||
if events
|
if events
|
||||||
.iter()
|
.iter()
|
||||||
.any(|p| p.path.file_name() == path.file_name())
|
.any(|p| p.path.file_name() == path.file_name())
|
||||||
{
|
{
|
||||||
let mut session = session.write().await;
|
if let Ok(metadata) = std::fs::metadata(path) {
|
||||||
if let Some(json) = session.json_data.get_mut() {
|
if let Ok(modified) = metadata.modified() {
|
||||||
let _ = json.update().await;
|
if modified > last_modified {
|
||||||
session.sync_player().await;
|
last_modified = modified;
|
||||||
tracing::info!("json updated")
|
|
||||||
|
let mut session = session.write().await;
|
||||||
|
if let Some(json) = session.json_data.get_mut() {
|
||||||
|
let _ = json.update().await;
|
||||||
|
session.sync_player().await;
|
||||||
|
tracing::info!("json updated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Err(e) => eprintln!("json watcher error: {:?}", e),
|
Err(e) => eprintln!("json watcher error: {:?}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user