Compare commits

..

No commits in common. "886ae6308bab05fd95e032b60cedada2279c7e6c" and "011c479550087251e01f34f94097436320749a34" have entirely different histories.

5 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "noxis-cli" name = "noxis-cli"
version = "0.2.7" version = "0.2.4"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "noxis-rs" name = "noxis-rs"
version = "0.11.26" version = "0.11.10"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -1,7 +1,8 @@
use log::{error, info}; use log::{error, info, warn};
use tokio::net::{ UnixStream, UnixListener }; use tokio::net::{ UnixStream, UnixListener };
use anyhow::Result as DynResult;
use tokio::time::{sleep, Duration}; use tokio::time::{sleep, Duration};
use std::fs; use std::{fs, io::{Read, Write}, os::fd::AsFd, path::Path};
use tokio::io::{ AsyncWriteExt, AsyncReadExt}; use tokio::io::{ AsyncWriteExt, AsyncReadExt};
use noxis_cli::Cli; use noxis_cli::Cli;
@ -18,7 +19,7 @@ use noxis_cli::Cli;
/// ///
/// *depends on* : - /// *depends on* : -
/// ///
pub async fn init_cli_pipeline() -> anyhow::Result<()> { pub async fn init_cli_pipeline() -> DynResult<()> {
let socket_path = "noxis.sock"; let socket_path = "noxis.sock";
let _ = fs::remove_file(socket_path); let _ = fs::remove_file(socket_path);

View File

@ -22,7 +22,7 @@ type SendersVec = Arc<Vec<Arc<mpsc::Sender<u8>>>>;
/// ///
/// *depends on* : Sig, Signals /// *depends on* : Sig, Signals
/// ///
pub async fn set_valid_destructor(senders: SendersVec) -> anyhow::Result<()> { pub async fn set_valid_destructor(senders: SendersVec) -> Result<(), CustomError> {
let (mut int, mut term, mut stop) = ( let (mut int, mut term, mut stop) = (
Sig::new(Signals::Sigint, senders.clone()), Sig::new(Signals::Sigint, senders.clone()),
Sig::new(Signals::Sigterm, senders.clone()), Sig::new(Signals::Sigterm, senders.clone()),

View File

@ -20,7 +20,7 @@ use tokio::time::Duration;
/// ///
/// *depends on* : - /// *depends on* : -
/// ///
pub async fn create_watcher(filename: &str, path: &str) -> anyhow::Result<Inotify> { pub async fn create_watcher(filename: &str, path: &str) -> Result<Inotify, std::io::Error> {
let src = format!("{}{}", path, filename); let src = format!("{}{}", path, filename);
let inotify: Inotify = Inotify::init()?; let inotify: Inotify = Inotify::init()?;
inotify.watches().add(&src, WatchMask::ALL_EVENTS)?; inotify.watches().add(&src, WatchMask::ALL_EVENTS)?;
@ -45,12 +45,12 @@ pub async fn file_handler(
files: &[Files], files: &[Files],
tx: Arc<mpsc::Sender<u8>>, tx: Arc<mpsc::Sender<u8>>,
watchers: Arc<tokio::sync::Mutex<Vec<Inotify>>>, watchers: Arc<tokio::sync::Mutex<Vec<Inotify>>>,
) -> anyhow::Result<()> { ) -> Result<(), CustomError> {
for (i, file) in files.iter().enumerate() { for (i, file) in files.iter().enumerate() {
// let src = format!("{}{}", file.src, file.filename); // let src = format!("{}{}", file.src, file.filename);
if check_file(&file.filename, &file.src).await.is_err() { if check_file(&file.filename, &file.src).await.is_err() {
if !is_active(name).await || is_frozen(name).await { if !is_active(name).await || is_frozen(name).await {
return Err(anyhow::Error::msg("Process is frozen or stopped")); return Err(CustomError::Fatal);
} }
match file.triggers.on_delete.as_str() { match file.triggers.on_delete.as_str() {
"stay" => { "stay" => {
@ -61,18 +61,18 @@ pub async fn file_handler(
if is_active(name).await { if is_active(name).await {
tx.send(1).await.unwrap(); tx.send(1).await.unwrap();
} }
return Err(anyhow::Error::msg("Process was stopped")); return Err(CustomError::Fatal);
} }
"hold" => { "hold" => {
if is_active(name).await { if is_active(name).await {
tx.send(2).await.unwrap(); tx.send(2).await.unwrap();
return Err(anyhow::Error::msg("Process was frozen")); return Err(CustomError::Fatal);
} }
} }
_ => { _ => {
tokio::time::sleep(Duration::from_millis(50)).await; tokio::time::sleep(Duration::from_millis(50)).await;
tx.send(101).await.unwrap(); tx.send(101).await.unwrap();
return Err(anyhow::Error::msg("Impermissible character or word in file trigger")); return Err(CustomError::Fatal);
} }
} }
} else if is_active(name).await && !is_frozen(name).await { } else if is_active(name).await && !is_frozen(name).await {