handle non-chunked graves from AnkiDroid

This commit is contained in:
Damien Elmes 2021-01-22 10:00:25 +10:00
parent ed7e709285
commit a77aa6b65a
5 changed files with 36 additions and 8 deletions

View file

@ -99,7 +99,11 @@ impl Backend {
self.with_sync_server(|server| { self.with_sync_server(|server| {
let mut rt = Runtime::new().unwrap(); let mut rt = Runtime::new().unwrap();
rt.block_on(server.start(input.client_usn, input.local_is_newer)) rt.block_on(server.start(
input.client_usn,
input.local_is_newer,
input.deprecated_client_graves,
))
}) })
} }

View file

@ -98,6 +98,9 @@ pub struct StartIn {
pub client_usn: Usn, pub client_usn: Usn,
#[serde(rename = "lnewer")] #[serde(rename = "lnewer")]
pub local_is_newer: bool, pub local_is_newer: bool,
/// Unfortunately AnkiDroid is still using this
#[serde(rename = "graves", default)]
pub deprecated_client_graves: Option<Graves>,
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]

View file

@ -71,10 +71,16 @@ impl SyncServer for HTTPSyncClient {
self.json_request(input).await self.json_request(input).await
} }
async fn start(&mut self, client_usn: Usn, local_is_newer: bool) -> Result<Graves> { async fn start(
&mut self,
client_usn: Usn,
local_is_newer: bool,
deprecated_client_graves: Option<Graves>,
) -> Result<Graves> {
let input = SyncRequest::Start(StartIn { let input = SyncRequest::Start(StartIn {
client_usn, client_usn,
local_is_newer, local_is_newer,
deprecated_client_graves,
}); });
self.json_request(input).await self.json_request(input).await
} }
@ -362,13 +368,13 @@ mod test {
}) })
)); ));
let _graves = syncer.start(Usn(1), true).await?; let _graves = syncer.start(Usn(1), true, None).await?;
// aborting should now work // aborting should now work
syncer.abort().await?; syncer.abort().await?;
// start again, and continue // start again, and continue
let _graves = syncer.start(Usn(1), true).await?; let _graves = syncer.start(Usn(1), true, None).await?;
syncer.apply_graves(Graves::default()).await?; syncer.apply_graves(Graves::default()).await?;

View file

@ -407,7 +407,7 @@ where
async fn start_and_process_deletions(&mut self, state: &SyncState) -> Result<()> { async fn start_and_process_deletions(&mut self, state: &SyncState) -> Result<()> {
let remote: Graves = self let remote: Graves = self
.remote .remote
.start(state.usn_at_last_sync, state.local_is_newer) .start(state.usn_at_last_sync, state.local_is_newer, None)
.await?; .await?;
debug!(self.col.log, "removed on remote"; debug!(self.col.log, "removed on remote";

View file

@ -18,7 +18,12 @@ use super::ChunkableIDs;
#[async_trait(?Send)] #[async_trait(?Send)]
pub trait SyncServer { pub trait SyncServer {
async fn meta(&self) -> Result<SyncMeta>; async fn meta(&self) -> Result<SyncMeta>;
async fn start(&mut self, client_usn: Usn, local_is_newer: bool) -> Result<Graves>; async fn start(
&mut self,
client_usn: Usn,
local_is_newer: bool,
deprecated_client_graves: Option<Graves>,
) -> Result<Graves>;
async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()>; async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()>;
async fn apply_changes(&mut self, client_changes: UnchunkedChanges) async fn apply_changes(&mut self, client_changes: UnchunkedChanges)
-> Result<UnchunkedChanges>; -> Result<UnchunkedChanges>;
@ -84,13 +89,23 @@ impl SyncServer for LocalServer {
}) })
} }
async fn start(&mut self, client_usn: Usn, client_is_newer: bool) -> Result<Graves> { async fn start(
&mut self,
client_usn: Usn,
client_is_newer: bool,
deprecated_client_graves: Option<Graves>,
) -> Result<Graves> {
self.server_usn = self.col.usn()?; self.server_usn = self.col.usn()?;
self.client_usn = client_usn; self.client_usn = client_usn;
self.client_is_newer = client_is_newer; self.client_is_newer = client_is_newer;
self.col.storage.begin_rust_trx()?; self.col.storage.begin_rust_trx()?;
self.col.storage.pending_graves(client_usn) let server_graves = self.col.storage.pending_graves(client_usn)?;
// Handle AnkiDroid using old protocol
if let Some(graves) = deprecated_client_graves {
self.col.apply_graves(graves, self.server_usn)?;
}
Ok(server_graves)
} }
async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()> { async fn apply_graves(&mut self, client_chunk: Graves) -> Result<()> {