migrate to notify 6.0

This commit is contained in:
jb-alvarado 2023-06-16 15:25:57 +02:00
parent 290a928836
commit 08dc748b5f
4 changed files with 184 additions and 51 deletions

130
Cargo.lock generated
View File

@ -955,7 +955,7 @@ dependencies = [
[[package]]
name = "ffplayout"
version = "0.18.2"
version = "0.19.0"
dependencies = [
"chrono",
"clap",
@ -963,7 +963,8 @@ dependencies = [
"ffplayout-lib",
"futures",
"jsonrpc-http-server",
"notify",
"notify 6.0.1",
"notify-debouncer-full",
"openssl",
"regex",
"reqwest",
@ -975,7 +976,7 @@ dependencies = [
[[package]]
name = "ffplayout-api"
version = "0.18.2"
version = "0.19.0"
dependencies = [
"actix-files",
"actix-multipart",
@ -1008,7 +1009,7 @@ dependencies = [
[[package]]
name = "ffplayout-lib"
version = "0.18.2"
version = "0.19.0"
dependencies = [
"chrono",
"crossbeam-channel",
@ -1017,7 +1018,7 @@ dependencies = [
"jsonrpc-http-server",
"lettre",
"log",
"notify",
"notify 4.0.17",
"openssl",
"rand",
"regex",
@ -1042,6 +1043,15 @@ dependencies = [
"serde_json",
]
[[package]]
name = "file-id"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13be71e6ca82e91bc0cb862bebaac0b2d1924a5a1d970c822b2f98b63fda8c3"
dependencies = [
"winapi-util",
]
[[package]]
name = "file-rotate"
version = "0.7.5"
@ -1123,7 +1133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6"
dependencies = [
"bitflags",
"fsevent-sys",
"fsevent-sys 2.0.1",
]
[[package]]
@ -1135,6 +1145,15 @@ dependencies = [
"libc",
]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [
"libc",
]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
@ -1546,6 +1565,17 @@ dependencies = [
"libc",
]
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.5"
@ -1696,6 +1726,26 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "kqueue"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c8fc60ba15bf51257aa9807a48a61013db043fcf3a78cb0d916e8e396dcad98"
dependencies = [
"kqueue-sys",
"libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8367585489f01bc55dd27404dcf56b95e6da061a256a666ab23be9ba96a2e587"
dependencies = [
"bitflags",
"libc",
]
[[package]]
name = "kv-log-macro"
version = "1.0.7"
@ -1961,8 +2011,8 @@ dependencies = [
"bitflags",
"filetime",
"fsevent",
"fsevent-sys",
"inotify",
"fsevent-sys 2.0.1",
"inotify 0.7.1",
"libc",
"mio 0.6.23",
"mio-extras",
@ -1970,6 +2020,36 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "notify"
version = "6.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5738a2795d57ea20abec2d6d76c6081186709c0024187cd5977265eda6598b51"
dependencies = [
"bitflags",
"crossbeam-channel",
"filetime",
"fsevent-sys 4.1.0",
"inotify 0.9.6",
"kqueue",
"libc",
"mio 0.8.8",
"walkdir",
"windows-sys 0.45.0",
]
[[package]]
name = "notify-debouncer-full"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "416969970ec751a5d702a88c6cd19ac1332abe997fce43f96db0418550426241"
dependencies = [
"file-id",
"notify 6.0.1",
"parking_lot 0.12.1",
"walkdir",
]
[[package]]
name = "num-bigint"
version = "0.4.3"
@ -2142,7 +2222,7 @@ dependencies = [
"libc",
"redox_syscall 0.3.5",
"smallvec",
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
@ -2891,7 +2971,7 @@ dependencies = [
[[package]]
name = "tests"
version = "0.18.2"
version = "0.19.0"
dependencies = [
"chrono",
"crossbeam-channel",
@ -2902,7 +2982,7 @@ dependencies = [
"jsonrpc-http-server",
"lettre",
"log",
"notify",
"notify 4.0.17",
"rand",
"regex",
"reqwest",
@ -3400,7 +3480,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
@ -3418,13 +3498,37 @@ dependencies = [
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
"windows-targets 0.48.0",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]

View File

@ -3,7 +3,7 @@ members = ["ffplayout-api", "ffplayout-engine", "lib", "tests"]
default-members = ["ffplayout-api", "ffplayout-engine", "tests"]
[workspace.package]
version = "0.18.2"
version = "0.19.0"
license = "GPL-3.0"
repository = "https://github.com/ffplayout/ffplayout"
authors = ["Jonathan Baecker <jonbae77@gmail.com>"]

View File

@ -17,7 +17,8 @@ clap = { version = "3.2", features = ["derive"] }
crossbeam-channel = "0.5"
futures = "0.3"
jsonrpc-http-server = "18.0"
notify = "4.0"
notify = "6.0"
notify-debouncer-full = { version = "*", default-features = false }
regex = "1"
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }

View File

@ -10,9 +10,11 @@ use std::{
};
use notify::{
DebouncedEvent::{Create, Remove, Rename},
{watcher, RecursiveMode, Watcher},
event::{CreateKind, ModifyKind, RemoveKind, RenameMode},
EventKind::{Create, Modify, Remove},
RecursiveMode, Watcher,
};
use notify_debouncer_full::new_debouncer;
use simplelog::*;
use ffplayout_lib::utils::{include_file, Media, PlayoutConfig};
@ -25,56 +27,82 @@ pub fn watchman(
is_terminated: Arc<AtomicBool>,
sources: Arc<Mutex<Vec<Media>>>,
) {
let (tx, rx) = channel();
let path = Path::new(&config.storage.path);
let path = config.storage.path.clone();
if !Path::new(&path).exists() {
error!("Folder path not exists: '{path}'");
panic!("Folder path not exists: '{path}'");
if !path.exists() {
error!("Folder path not exists: '{path:?}'");
panic!("Folder path not exists: '{path:?}'");
}
let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap();
watcher.watch(path, RecursiveMode::Recursive).unwrap();
// let (tx, rx) = channel();
let (tx, rx) = channel();
let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx).unwrap();
debouncer
.watcher()
.watch(path, RecursiveMode::Recursive)
.unwrap();
debouncer.cache().add_root(path, RecursiveMode::Recursive);
while !is_terminated.load(Ordering::SeqCst) {
if let Ok(res) = rx.try_recv() {
match res {
Create(new_path) => {
let index = sources.lock().unwrap().len();
let media = Media::new(index, &new_path.to_string_lossy(), false);
if let Ok(result) = rx.try_recv() {
match result {
Ok(events) => events.iter().for_each(|event| match event.kind {
Create(CreateKind::File) => {
let new_path = &event.paths[0];
let index = sources.lock().unwrap().len();
let media = Media::new(index, &new_path.to_string_lossy(), false);
if include_file(config.clone(), &new_path) {
sources.lock().unwrap().push(media);
info!("Create new file: <b><magenta>{new_path:?}</></b>");
if include_file(config.clone(), new_path) {
sources.lock().unwrap().push(media);
info!("Create new file: <b><magenta>{new_path:?}</></b>");
}
}
}
Remove(old_path) => {
if include_file(config.clone(), &old_path) {
sources
.lock()
.unwrap()
.retain(|x| x.source != old_path.display().to_string());
info!("Remove file: <b><magenta>{old_path:?}</></b>");
}
}
Rename(old_path, new_path) => {
let index = sources
Modify(ModifyKind::Name(RenameMode::Both)) => {
let old_path = &event.paths[0];
let new_path = &event.paths[1];
let index = sources
.lock()
.unwrap()
.iter()
.position(|x| *x.source == old_path.display().to_string())
.unwrap();
let media = Media::new(index, &new_path.to_string_lossy(), false);
sources.lock().unwrap()[index] = media;
let media = Media::new(index, &new_path.to_string_lossy(), false);
sources.lock().unwrap()[index] = media;
info!("Rename file: <b><magenta>{old_path:?}</></b> to <b><magenta>{new_path:?}</></b>");
}
_ => (),
info!("Move file: <b><magenta>{old_path:?}</></b> to <b><magenta>{new_path:?}</></b>");
}
Modify(ModifyKind::Name(RenameMode::From)) => {
let old_path = &event.paths[0];
if !old_path.is_file() && include_file(config.clone(), old_path) {
sources
.lock()
.unwrap()
.retain(|x| x.source != old_path.to_string_lossy());
info!("Remove file: <b><magenta>{old_path:?}</></b>");
}
}
Remove(RemoveKind::File) => {
let old_path = &event.paths[0];
if include_file(config.clone(), old_path) {
sources
.lock()
.unwrap()
.retain(|x| x.source != old_path.to_string_lossy());
info!("Remove file: <b><magenta>{old_path:?}</></b>");
}
}
_ => (),
}),
Err(errors) => errors.iter().for_each(|error| error!("{error:?}")),
}
}
sleep(Duration::from_secs(5));
sleep(Duration::from_secs(3));
}
}