From bddd67fb9317c03fcf17e384ee4785050885136a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Mon, 13 Apr 2015 11:48:42 +0200 Subject: [PATCH] oc: Enforce the folder creation mapping when the FID exists We believe the folder ID OpenChange is sending us is new and we keep the indexing database properly updated. Although the solution is not elegant, this could avoid inconsistencies between what the client stores and the relation in the MAPIStore backend. --- OpenChange/MAPIStoreFolder.m | 10 ++++++++-- OpenChange/MAPIStoreMapping.h | 2 ++ OpenChange/MAPIStoreMapping.m | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/OpenChange/MAPIStoreFolder.m b/OpenChange/MAPIStoreFolder.m index 0d862b85e..824c15578 100644 --- a/OpenChange/MAPIStoreFolder.m +++ b/OpenChange/MAPIStoreFolder.m @@ -402,7 +402,8 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe withRow: (struct SRow *) aRow andFID: (uint64_t) fid { - int rc = MAPISTORE_SUCCESS; + BOOL mapped; + enum mapistore_error rc = MAPISTORE_SUCCESS; MAPIStoreMapping *mapping; NSString *baseURL, *childURL, *folderKey; MAPIStoreFolder *childFolder; @@ -430,7 +431,12 @@ Class NSExceptionK, MAPIStoreFAIMessageK, MAPIStoreMessageTableK, MAPIStoreFAIMe childURL = [NSString stringWithFormat: @"%@%@/", baseURL, [folderKey stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; - [mapping registerURL: childURL withID: fid]; + + mapped = [mapping registerURL: childURL withID: fid]; + if (!mapped) + /* Enforce the creation if the backend does know the fid */ + [mapping updateURL: childURL withID: fid]; + childFolder = [self lookupFolder: folderKey]; if (childFolder) { diff --git a/OpenChange/MAPIStoreMapping.h b/OpenChange/MAPIStoreMapping.h index 827cddf38..55c2e944a 100644 --- a/OpenChange/MAPIStoreMapping.h +++ b/OpenChange/MAPIStoreMapping.h @@ -60,6 +60,8 @@ andFlags: (uint8_t) flags; - (void) updateID: (uint64_t) idNbr withURL: (NSString *) urlString; +- (BOOL) updateURL: (NSString *) urlString + withID: (uint64_t) idNbr; @end diff --git a/OpenChange/MAPIStoreMapping.m b/OpenChange/MAPIStoreMapping.m index 6a910ea4c..b7d303ed6 100644 --- a/OpenChange/MAPIStoreMapping.m +++ b/OpenChange/MAPIStoreMapping.m @@ -227,12 +227,32 @@ MAPIStoreMappingKeyFromId (uint64_t idNbr) } } +- (BOOL) updateURL: (NSString *) urlString + withID: (uint64_t) idNbr +{ + BOOL rc = NO; + uint64_t oldIDNbr; + + oldIDNbr = [self idFromURL: urlString]; + if (oldIDNbr) + { + [self logWithFormat: @"Updating URL: %@ with id %.16"PRIx64" from old id %.16"PRIx64, + urlString, idNbr, oldIDNbr]; + [self unregisterURLWithID: oldIDNbr]; + [self registerURL: urlString + withID: idNbr]; + rc = YES; + } + + return rc; +} + - (BOOL) registerURL: (NSString *) urlString withID: (uint64_t) idNbr { NSString *oldURL; uint64_t oldIdNbr; - bool rc, softDeleted; + bool softDeleted; oldURL = [self urlFromID: idNbr]; if (oldURL != NULL) @@ -257,7 +277,6 @@ MAPIStoreMappingKeyFromId (uint64_t idNbr) } else { - rc = YES; // [self logWithFormat: @"registered url '%@' with id %lld (0x%.16"PRIx64")", // urlString, idNbr, idNbr]; @@ -266,7 +285,7 @@ MAPIStoreMappingKeyFromId (uint64_t idNbr) idNbr, [urlString UTF8String]); } - return rc; + return YES; } - (void) registerURLs: (NSArray *) urlStrings