@@ -3,7 +3,8 @@ extern crate tracing;
33
44use std:: {
55 env:: Args ,
6- fs:: File ,
6+ ffi:: OsStr ,
7+ fs:: { create_dir_all, File } ,
78 io:: { BufRead , BufReader , Error } ,
89 path:: { Path , PathBuf } ,
910 process:: { Command , Stdio } ,
@@ -60,13 +61,18 @@ pub async fn check_for_updates() -> reqwest::Result<bool> {
6061/// # Errors
6162/// Will return `Err` if `PollWatcher::watch` errors
6263pub fn watch < P : AsRef < Path > > ( tx : Sender < PathBuf > , path : P ) -> notify:: Result < PollWatcher > {
64+ let path = path. as_ref ( ) ;
65+ debug ! ( "Watching {path:?}" ) ;
66+
6367 let tx_clone = tx. clone ( ) ;
6468 let mut watcher = PollWatcher :: with_initial_scan (
6569 move |watch_event : notify:: Result < Event > | {
6670 if let Ok ( event) = watch_event {
6771 for path in event. paths {
68- if !path. ends_with ( ".log" ) {
69- let _ = tx. send ( path) ;
72+ if let Some ( extension) = path. extension ( ) . and_then ( OsStr :: to_str) {
73+ if [ "log" , "txt" ] . contains ( & extension) {
74+ let _ = tx. send ( path) ;
75+ }
7076 }
7177 }
7278 }
@@ -76,14 +82,16 @@ pub fn watch<P: AsRef<Path>>(tx: Sender<PathBuf>, path: P) -> notify::Result<Pol
7682 . with_poll_interval ( Duration :: from_secs ( 1 ) ) ,
7783 move |scan_event : notify:: Result < PathBuf > | {
7884 if let Ok ( path) = scan_event {
79- if !path. ends_with ( ".log" ) {
80- let _ = tx_clone. send ( path) ;
85+ if let Some ( extension) = path. extension ( ) . and_then ( OsStr :: to_str) {
86+ if [ "log" , "txt" ] . contains ( & extension) {
87+ let _ = tx_clone. send ( path) ;
88+ }
8189 }
8290 }
8391 } ,
8492 ) ?;
8593
86- watcher. watch ( path. as_ref ( ) , RecursiveMode :: NonRecursive ) ?;
94+ watcher. watch ( path, RecursiveMode :: NonRecursive ) ?;
8795
8896 Ok ( watcher)
8997}
@@ -195,7 +203,15 @@ pub fn parse_path_env(path: &str) -> Result<PathBuf, Error> {
195203 std:: env:: var( env) . unwrap_or_else( |_| panic!( "Environment Variable not found: {env}" ) )
196204 } ) ;
197205
198- std:: fs:: canonicalize ( path. as_ref ( ) )
206+ let path = Path :: new ( path. as_ref ( ) ) ;
207+ if !path. exists ( ) {
208+ if let Some ( parent) = path. parent ( ) {
209+ create_dir_all ( parent) ?;
210+ }
211+ File :: create ( path) ?;
212+ }
213+
214+ std:: fs:: canonicalize ( path)
199215}
200216
201217#[ must_use]
0 commit comments