From 72d87e84a51adfa896f29310bb48ff2b47b7650a Mon Sep 17 00:00:00 2001 From: Artemis Meursault Gerrard Date: Fri, 29 Nov 2024 22:47:10 +0000 Subject: [PATCH] Fix #239 (Google Drive crash on sync) The issue occurs when the remote timestamp in the DB is more recent than the next (i.e. time has gone backwards). It's not possible to know which is "really" more recent here, so the safest thing to do is to report an error and skip that file. --- src/launch.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/launch.rs b/src/launch.rs index eb41772..054bd8e 100644 --- a/src/launch.rs +++ b/src/launch.rs @@ -2413,6 +2413,28 @@ pub fn launch(app: &Application, background: bool) { util::await_future(active_model.update(db)).unwrap(); }; + // Google Drive can enter a strange state where timestamps go backwards + // leading to scenarios where: + // + // db_model.last_local_timestamp + // == db_model.last_remote_timestamp + // == l_timestamp + // + // but... + // remote_timestamp < db_model.last_remote_timestamp + // + // The db is no longer making sense in this scenario, + // so the most reasonable cause of action is to delete its entry. + if remote_timestamp < db_model.last_remote_timestamp as i64 + { + add_error(SyncError::General( + remote_path_string.clone(), + "New remote timestamp is older than previous".into(), + )); + delete_db_entry(); + continue; + } + // Both items are more recent. if let Some(l_timestamp) = local_timestamp && l_timestamp > db_model.last_local_timestamp as u64