diff --git a/furumi-client-core/src/client.rs b/furumi-client-core/src/client.rs index 68b0473..28e4301 100644 --- a/furumi-client-core/src/client.rs +++ b/furumi-client-core/src/client.rs @@ -193,14 +193,13 @@ impl FurumiClient { .time_to_live(Duration::from_secs(30)) .build(); - let this = Self { client, attr_cache, dir_cache }; - this.start_background_sync(); - Ok(this) + Ok(Self { client, attr_cache, dir_cache }) } /// Spawns background tasks that pre-warm the cache with a server snapshot and then /// subscribe to live change events to keep it up to date. - fn start_background_sync(&self) { + /// Must be called after a successful authentication check. + pub fn start_background_sync(&self) { let this = self.clone(); tokio::spawn(async move { match this.load_snapshot("/", 3).await { diff --git a/furumi-mount-linux/src/main.rs b/furumi-mount-linux/src/main.rs index d3c844c..efc4614 100644 --- a/furumi-mount-linux/src/main.rs +++ b/furumi-mount-linux/src/main.rs @@ -63,7 +63,10 @@ fn main() -> Result<(), Box> { if let Err(e) = c.get_attr("/").await { return Err(format!("Failed to authenticate or connect to server: {}", e).into()); } - + + // Auth verified — start background snapshot + watch sync + c.start_background_sync(); + Ok::<_, Box>(c) })?; diff --git a/furumi-mount-macos/src/main.rs b/furumi-mount-macos/src/main.rs index f9bd086..a26bd92 100644 --- a/furumi-mount-macos/src/main.rs +++ b/furumi-mount-macos/src/main.rs @@ -58,7 +58,11 @@ fn main() -> Result<(), Box> { format!("https://{}", args.server) }; - let client = rt.block_on(async { FurumiClient::connect(&full_addr, &args.token).await })?; + let client = rt.block_on(async { + let c = FurumiClient::connect(&full_addr, &args.token).await?; + c.start_background_sync(); + Ok::<_, Box>(c) + })?; let furumi_nfs = nfs::FurumiNfs::new(client);