@@ -2,11 +2,7 @@ cfg_core! {
22 use crate :: EncryptionConfig ;
33}
44
5- use std:: sync:: Arc ;
6-
7- use tracing:: Instrument as _;
8-
9- use crate :: { sync:: DropAbort , Database , Result } ;
5+ use crate :: { Database , Result } ;
106
117use super :: DbType ;
128
@@ -600,6 +596,8 @@ cfg_sync! {
600596
601597 /// Build a connection to a local database that can be synced to remote server.
602598 pub async fn build( self ) -> Result <Database > {
599+ use tracing:: Instrument as _;
600+
603601 let SyncedDatabase {
604602 path,
605603 flags,
@@ -645,7 +643,7 @@ cfg_sync! {
645643 db. sync_ctx. as_ref( ) . unwrap( ) . lock( ) . await . set_push_batch_size( push_batch_size) ;
646644 }
647645
648- let mut bg_abort: Option <Arc <DropAbort >> = None ;
646+ let mut bg_abort: Option <std :: sync :: Arc <crate :: sync :: DropAbort >> = None ;
649647 let conn = db. connect( ) ?;
650648
651649 let sync_ctx = db. sync_ctx. as_ref( ) . unwrap( ) . clone( ) ;
@@ -656,17 +654,22 @@ cfg_sync! {
656654 loop {
657655 tracing:: trace!( "trying to sync" ) ;
658656 let mut ctx = sync_ctx. lock( ) . await ;
659- if let Err ( e) = crate :: sync:: try_pull( & mut ctx, & conn) . await {
660- tracing:: error!( "sync error: {}" , e) ;
657+ if remote_writes {
658+ if let Err ( e) = crate :: sync:: try_pull( & mut ctx, & conn) . await {
659+ tracing:: error!( "sync error: {}" , e) ;
660+ }
661+ } else {
662+ if let Err ( e) = crate :: sync:: sync_offline( & mut ctx, & conn) . await {
663+ tracing:: error!( "sync error: {}" , e) ;
664+ }
661665 }
662-
663666 tokio:: time:: sleep( sync_interval) . await ;
664667 }
665668 }
666669 . instrument( tracing:: info_span!( "sync_interval" ) ) ,
667670 ) ;
668671
669- bg_abort. replace( Arc :: new( DropAbort ( jh. abort_handle( ) ) ) ) ;
672+ bg_abort. replace( std :: sync :: Arc :: new( crate :: sync :: DropAbort ( jh. abort_handle( ) ) ) ) ;
670673 }
671674
672675 Ok ( Database {
0 commit comments