Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bitfireAT/davx5-ose.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicki Hirner <hirner@bitfire.at>2022-10-21 14:39:49 +0300
committerRicki Hirner <hirner@bitfire.at>2022-10-21 14:41:21 +0300
commit951c29e66a8a62e0f7cfaee9bc673e244dbd484f (patch)
tree87d99678f3a4e29541f78ff1ad797b1f535a2c36
parent0f124cf5b5aae71aec1006aa096c7582a0b5a1e2 (diff)
Force sync after resetting read-only contacts (bitfireAT/davx5#154)
* Force sync after resetting read-only contacts * Rename variable for clarity
-rw-r--r--app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.kt14
-rw-r--r--app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.kt22
2 files changed, 26 insertions, 10 deletions
diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.kt b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.kt
index 2401a0a0..09c3abb0 100644
--- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.kt
+++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.kt
@@ -166,31 +166,38 @@ class ContactsSyncManager(
override fun processLocallyDeleted() =
if (readOnly) {
+ var modified = false
for (group in localCollection.findDeletedGroups()) {
Logger.log.warning("Restoring locally deleted group (read-only address book!)")
localExceptionContext(group) { it.resetDeleted() }
+ modified = true
}
for (contact in localCollection.findDeletedContacts()) {
Logger.log.warning("Restoring locally deleted contact (read-only address book!)")
localExceptionContext(contact) { it.resetDeleted() }
+ modified = true
}
- false
+ modified
} else
// mirror deletions to remote collection (DELETE)
super.processLocallyDeleted()
override fun uploadDirty(): Boolean {
+ var modified = false
+
if (readOnly) {
for (group in localCollection.findDirtyGroups()) {
Logger.log.warning("Resetting locally modified group to ETag=null (read-only address book!)")
localExceptionContext(group) { it.clearDirty(null, null) }
+ modified = true
}
for (contact in localCollection.findDirtyContacts()) {
Logger.log.warning("Resetting locally modified contact to ETag=null (read-only address book!)")
localExceptionContext(contact) { it.clearDirty(null, null) }
+ modified = true
}
} else
@@ -198,7 +205,10 @@ class ContactsSyncManager(
groupStrategy.beforeUploadDirty()
// generate UID/file name for newly created contacts
- return super.uploadDirty()
+ var superModified = super.uploadDirty()
+
+ // return true when any operation returned true
+ return modified or superModified
}
override fun generateUpload(resource: LocalAddress): RequestBody =
diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.kt b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.kt
index 443f75ba..41c07d4c 100644
--- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.kt
+++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.kt
@@ -155,8 +155,8 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
Logger.log.info("Querying server capabilities")
var remoteSyncState = queryCapabilities()
- Logger.log.info("Sending local deletes/updates to server")
- val modificationsSent = processLocallyDeleted() || uploadDirty()
+ Logger.log.info("Processing local deletes/updates")
+ val modificationsPresent = processLocallyDeleted() || uploadDirty()
if (extras.containsKey(SyncAdapterService.SYNC_EXTRAS_FULL_RESYNC)) {
Logger.log.info("Forcing re-synchronization of all entries")
@@ -169,14 +169,14 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
localCollection.forgetETags()
}
- if (modificationsSent || syncRequired(remoteSyncState))
+ if (modificationsPresent || syncRequired(remoteSyncState))
when (syncAlgorithm()) {
SyncAlgorithm.PROPFIND_REPORT -> {
Logger.log.info("Sync algorithm: full listing as one result (PROPFIND/REPORT)")
resetPresentRemotely()
// get current sync state
- if (modificationsSent)
+ if (modificationsPresent)
remoteSyncState = querySyncState()
// list and process all entries at current sync state (which may be the same as or newer than remoteSyncState)
@@ -305,9 +305,12 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
protected abstract fun queryCapabilities(): SyncState?
/**
- * Processes locally deleted entries and forwards them to the server (HTTP `DELETE`).
+ * Processes locally deleted entries. This can mean:
*
- * @return whether resources have been deleted from the server
+ * - forwarding them to the server (HTTP `DELETE`)
+ * - resetting their local state so that they will be downloaded again because they're read-only
+ *
+ * @return whether local resources have been processed so that a synchronization is always necessary
*/
protected open fun processLocallyDeleted(): Boolean {
var numDeleted = 0
@@ -342,9 +345,12 @@ abstract class SyncManager<ResourceType: LocalResource<*>, out CollectionType: L
}
/**
- * Uploads locally modified resources to the server.
+ * Processes locally modified resources to the server. This can mean:
+ *
+ * - uploading them to the server (HTTP `PUT`)
+ * - resetting their local state so that they will be downloaded again because they're read-only
*
- * @return whether resources have been uploaded
+ * @return whether local resources have been processed so that a synchronization is always necessary
*/
protected open fun uploadDirty(): Boolean {
var numUploaded = 0