1
0
mirror of https://github.com/etesync/android synced 2024-12-23 07:08:16 +00:00

SyncManager: correctly set the item's UID in the metadata.

We were only populating the uid after setting it in the metadata so
we were always setting null in the metadata which was causing
errors.
This commit is contained in:
Tom Hacohen 2020-09-06 10:16:01 +03:00
parent 6459d71ab6
commit 00a1a223d0
6 changed files with 53 additions and 11 deletions

View File

@ -107,7 +107,7 @@ class LocalContact : AndroidContact, LocalAddress {
this.eTag = eTag
}
override fun prepareForUpload(fileName_: String?) {
override fun legacyPrepareForUpload(fileName_: String?) {
val uid = UUID.randomUUID().toString()
val values = ContentValues(2)
@ -119,6 +119,16 @@ class LocalContact : AndroidContact, LocalAddress {
this.fileName = fileName
}
override fun prepareForUpload(fileName: String, uid: String) {
val values = ContentValues(2)
values.put(AndroidContact.COLUMN_FILENAME, fileName)
values.put(AndroidContact.COLUMN_UID, uid)
addressBook.provider?.update(rawContactSyncURI(), values, null, null)
contact?.uid = uid
this.fileName = fileName
}
override fun populateData(mimeType: String, row: ContentValues) {
when (mimeType) {
CachedGroupMembership.CONTENT_ITEM_TYPE -> cachedGroupMemberships.add(row.getAsLong(CachedGroupMembership.GROUP_ID))

View File

@ -133,7 +133,7 @@ class LocalEvent : AndroidEvent, LocalResource<Event> {
/* custom queries */
override fun prepareForUpload(fileName_: String?) {
override fun legacyPrepareForUpload(fileName_: String?) {
var uid: String? = null
val c = calendar.provider.query(eventSyncURI(), arrayOf(COLUMN_UID), null, null, null)
if (c.moveToNext())
@ -156,6 +156,16 @@ class LocalEvent : AndroidEvent, LocalResource<Event> {
event.uid = uid
}
override fun prepareForUpload(fileName: String, uid: String) {
val values = ContentValues(2)
values.put(Events._SYNC_ID, fileName)
values.put(COLUMN_UID, uid)
calendar.provider.update(eventSyncURI(), values, null, null)
event?.uid = uid
this.fileName = fileName
}
override fun resetDeleted() {
val values = ContentValues(1)
values.put(CalendarContract.Events.DELETED, 0)

View File

@ -156,7 +156,7 @@ class LocalGroup : AndroidGroup, LocalAddress {
batch.commit()
}
override fun prepareForUpload(fileName_: String?) {
override fun legacyPrepareForUpload(fileName_: String?) {
val uid = UUID.randomUUID().toString()
val values = ContentValues(2)
@ -168,6 +168,16 @@ class LocalGroup : AndroidGroup, LocalAddress {
this.fileName = fileName
}
override fun prepareForUpload(fileName: String, uid: String) {
val values = ContentValues(2)
values.put(AndroidGroup.COLUMN_FILENAME, fileName)
values.put(AndroidGroup.COLUMN_UID, uid)
addressBook.provider?.update(groupSyncUri(), values, null, null)
contact?.uid = uid
this.fileName = fileName
}
override fun resetDeleted() {
val values = ContentValues(1)
values.put(Groups.DELETED, 0)

View File

@ -20,8 +20,9 @@ interface LocalResource<in TData: Any> {
fun delete(): Int
// FIXME: The null is for legacy
fun prepareForUpload(fileName: String?)
fun legacyPrepareForUpload(fileName: String?)
fun prepareForUpload(fileName: String, uid: String)
fun clearDirty(eTag: String?)

View File

@ -96,7 +96,7 @@ class LocalTask : AndroidTask, LocalResource<Task> {
/* custom queries */
override fun prepareForUpload(fileName_: String?) {
override fun legacyPrepareForUpload(fileName_: String?) {
var uid: String? = null
val c = taskList.provider.client.query(taskSyncURI(), arrayOf(COLUMN_UID), null, null, null)
if (c.moveToNext())
@ -118,6 +118,16 @@ class LocalTask : AndroidTask, LocalResource<Task> {
task.uid = uid
}
override fun prepareForUpload(fileName: String, uid: String) {
val values = ContentValues(2)
values.put(TaskContract.Tasks._SYNC_ID, fileName)
values.put(COLUMN_UID, uid)
taskList.provider.client.update(taskSyncURI(), values, null, null)
task?.uid = uid
this.fileName = fileName
}
override fun resetDeleted() {
val values = ContentValues(1)
values.put(TaskContract.Tasks._DELETED, 0)

View File

@ -651,12 +651,13 @@ constructor(protected val context: Context, protected val account: Account, prot
item = cacheItem.item
itemUpdateMtime(item)
} else {
val uid = UUID.randomUUID().toString()
val meta = ItemMetadata()
meta.name = local.uuid!!
meta.setMtime(System.currentTimeMillis())
meta.name = uid
meta.mtime = System.currentTimeMillis()
item = itemMgr.create(meta, "")
local.prepareForUpload(item.uid)
local.prepareForUpload(item.uid, uid)
}
try {
@ -773,7 +774,7 @@ constructor(protected val context: Context, protected val account: Account, prot
if (isLegacy) {
// It's done later for non-legacy
Logger.log.fine("Entry deleted before ever syncing - genarting a UUID")
local.prepareForUpload(null)
local.legacyPrepareForUpload(null)
}
}
@ -812,7 +813,7 @@ constructor(protected val context: Context, protected val account: Account, prot
}
Logger.log.fine("Found local record without file name; generating file name/UID if necessary")
local.prepareForUpload(null)
local.legacyPrepareForUpload(null)
}
}
}