1616
1717use async_trait:: async_trait;
1818use reqwest:: { Body , Client , Request , Response } ;
19- use tokio:: time:: sleep;
2019use std:: io:: prelude:: * ;
20+ use std:: sync:: { LazyLock , Mutex } ;
2121use std:: time:: Duration ;
22+ use tokio:: time:: sleep;
2223use url:: Url ;
23- use std:: sync:: { LazyLock , Mutex } ;
2424
2525use http:: { Method , StatusCode } ;
2626use log:: * ;
@@ -35,7 +35,7 @@ use crate::errors::RustKeylockError;
3535use crate :: SystemConfiguration ;
3636use crate :: { errors, file_handler} ;
3737
38- static STOP_SYNCHRONIZATION : LazyLock < Mutex < bool > > = LazyLock :: new ( || { Mutex :: new ( false ) } ) ;
38+ static STOP_SYNCHRONIZATION : LazyLock < Mutex < bool > > = LazyLock :: new ( || Mutex :: new ( false ) ) ;
3939
4040/// A (Next/Own)cloud synchronizer
4141#[ derive( Clone ) ]
@@ -90,7 +90,7 @@ impl Synchronizer {
9090 let s = STOP_SYNCHRONIZATION . lock ( ) ?;
9191 Ok ( * s)
9292 }
93-
93+
9494 fn stop_synchronization ( & self ) -> errors:: Result < ( ) > {
9595 if !self . never_stop_synchronization {
9696 let mut stop_sync = STOP_SYNCHRONIZATION . lock ( ) ?;
@@ -532,11 +532,26 @@ impl Synchronizer {
532532
533533 res
534534 }
535+
536+ fn mark_stop_synchronization ( ) -> errors:: Result < ( ) > {
537+ let mut s = STOP_SYNCHRONIZATION . lock ( ) ?;
538+ * s = true ;
539+ Ok ( ( ) )
540+ }
541+
542+ fn mark_start_synchronization ( ) -> errors:: Result < ( ) > {
543+ let mut s = STOP_SYNCHRONIZATION . lock ( ) ?;
544+ * s = false ;
545+ Ok ( ( ) )
546+ }
535547}
536548
537549#[ async_trait]
538550impl super :: AsyncTask for Synchronizer {
539- async fn init ( & mut self ) { }
551+ async fn init ( & mut self ) -> errors:: Result < ( ) > {
552+ Self :: mark_start_synchronization ( ) ?;
553+ Ok ( ( ) )
554+ }
540555
541556 async fn execute ( & self ) -> errors:: Result < SyncStatus > {
542557 if self . conf . is_filled ( ) {
@@ -572,6 +587,10 @@ impl super::AsyncTask for Synchronizer {
572587 return Ok ( SyncStatus :: None ) ;
573588 }
574589 }
590+
591+ fn stop ( & mut self ) -> errors:: Result < ( ) > {
592+ return Self :: mark_stop_synchronization ( ) ;
593+ }
575594}
576595
577596/// The configuration that is retrieved from the rust-keylock encrypted file
@@ -794,7 +813,8 @@ mod nextcloud_tests {
794813 use super :: super :: super :: { errors, file_handler, SystemConfiguration } ;
795814 use super :: super :: AsyncTask ;
796815
797- static TXMAP : LazyLock < Mutex < HashMap < String , SyncSender < bool > > > > = LazyLock :: new ( || { Mutex :: new ( HashMap :: new ( ) ) } ) ;
816+ static TXMAP : LazyLock < Mutex < HashMap < String , SyncSender < bool > > > > =
817+ LazyLock :: new ( || Mutex :: new ( HashMap :: new ( ) ) ) ;
798818
799819 fn get_tx_for ( command : & str ) -> SyncSender < bool > {
800820 let map = TXMAP . lock ( ) . unwrap ( ) ;
@@ -817,8 +837,8 @@ mod nextcloud_tests {
817837 false ,
818838 )
819839 . unwrap ( ) ;
820- let nc =
821- super :: Synchronizer :: new2 ( & ncc , & SystemConfiguration :: default ( ) , "filename" , true ) . unwrap ( ) ;
840+ let nc = super :: Synchronizer :: new2 ( & ncc , & SystemConfiguration :: default ( ) , "filename" , true )
841+ . unwrap ( ) ;
822842
823843 assert ! ( nc. conf. decrypted_password( ) . unwrap( ) . as_str( ) == password)
824844 }
@@ -980,7 +1000,8 @@ mod nextcloud_tests {
9801000 thread:: spawn ( move || {
9811001 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
9821002 let nc =
983- super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true ) . unwrap ( ) ;
1003+ super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true )
1004+ . unwrap ( ) ;
9841005 let res = rt. block_on ( nc. execute ( ) ) ;
9851006 let _ = tx. send ( res) ;
9861007 } ) ;
@@ -1036,7 +1057,8 @@ mod nextcloud_tests {
10361057 thread:: spawn ( move || {
10371058 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
10381059 let nc =
1039- super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true ) . unwrap ( ) ;
1060+ super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true )
1061+ . unwrap ( ) ;
10401062 let res = rt. block_on ( nc. execute ( ) ) ;
10411063 let _ = tx. send ( res) ;
10421064 } ) ;
@@ -1185,7 +1207,8 @@ mod nextcloud_tests {
11851207 thread:: spawn ( move || {
11861208 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
11871209 let nc =
1188- super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true ) . unwrap ( ) ;
1210+ super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true )
1211+ . unwrap ( ) ;
11891212 let res = rt. block_on ( nc. execute ( ) ) ;
11901213 let _ = tx. send ( res) ;
11911214 } ) ;
@@ -1226,7 +1249,8 @@ mod nextcloud_tests {
12261249 thread:: spawn ( move || {
12271250 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
12281251 let nc =
1229- super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true ) . unwrap ( ) ;
1252+ super :: Synchronizer :: new2 ( & ncc, & SystemConfiguration :: default ( ) , filename, true )
1253+ . unwrap ( ) ;
12301254 let res = rt. block_on ( nc. execute ( ) ) ;
12311255 let _ = tx. send ( res) ;
12321256 } ) ;
0 commit comments