mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-04-03 20:38:50 +00:00
Monotone-Parent: 8d4ca03b16c54609dce23f43fc358a43d7e96d99
Monotone-Revision: 047b040e318a98223980da2af8241b7eb6d75341 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-08-13T03:55:48 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
@@ -204,6 +204,90 @@ MAPIStoreMappingTDBTraverse (TDB_CONTEXT *ctx, TDB_DATA data1, TDB_DATA data2,
|
||||
return idNbr;
|
||||
}
|
||||
|
||||
- (void) _updateFolderWithURL: (NSString *) oldURL
|
||||
withURL: (NSString *) urlString
|
||||
{
|
||||
NSArray *allKeys;
|
||||
NSUInteger count, max;
|
||||
NSString *currentKey, *keyEnd, *newKey;
|
||||
NSUInteger oldURLLength;
|
||||
NSNumber *idKey;
|
||||
TDB_DATA key, dbuf;
|
||||
|
||||
oldURLLength = [oldURL length];
|
||||
|
||||
allKeys = [reverseMapping allKeys];
|
||||
max = [allKeys count];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
currentKey = [allKeys objectAtIndex: count];
|
||||
if ([currentKey hasPrefix: oldURL])
|
||||
{
|
||||
keyEnd = [currentKey substringFromIndex: oldURLLength];
|
||||
newKey = [NSString stringWithFormat: @"%@%@", urlString, keyEnd];
|
||||
|
||||
idKey = [reverseMapping objectForKey: currentKey];
|
||||
[mapping setObject: newKey forKey: idKey];
|
||||
[reverseMapping setObject: idKey forKey: newKey];
|
||||
[reverseMapping removeObjectForKey: currentKey];
|
||||
|
||||
/* update the record in the indexing database */
|
||||
key.dptr = (unsigned char *) talloc_asprintf (NULL, "0x%.16"PRIx64,
|
||||
(uint64_t) [idKey unsignedLongLongValue]);
|
||||
key.dsize = strlen ((const char *) key.dptr);
|
||||
|
||||
dbuf.dptr = (unsigned char *) talloc_strdup (NULL,
|
||||
[newKey UTF8String]);
|
||||
dbuf.dsize = strlen ((const char *) dbuf.dptr);
|
||||
tdb_store (indexing->tdb, key, dbuf, TDB_MODIFY);
|
||||
talloc_free (key.dptr);
|
||||
talloc_free (dbuf.dptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) updateID: (uint64_t) idNbr
|
||||
withURL: (NSString *) urlString
|
||||
{
|
||||
NSString *oldURL;
|
||||
NSNumber *idKey;
|
||||
TDB_DATA key, dbuf;
|
||||
|
||||
idKey = [NSNumber numberWithUnsignedLongLong: idNbr];
|
||||
oldURL = [mapping objectForKey: idKey];
|
||||
if (oldURL)
|
||||
{
|
||||
if ([oldURL hasSuffix: @"/"]) /* is container ? */
|
||||
{
|
||||
if (![urlString hasSuffix: @"/"])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"a container url must have an ending '/'"];
|
||||
tdb_transaction_start (indexing->tdb);
|
||||
[self _updateFolderWithURL: oldURL withURL: urlString];
|
||||
tdb_transaction_commit (indexing->tdb);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([urlString hasSuffix: @"/"])
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"a leaf url must not have an ending '/'"];
|
||||
[mapping setObject: urlString forKey: idKey];
|
||||
[reverseMapping setObject: idKey forKey: urlString];
|
||||
[reverseMapping removeObjectForKey: oldURL];
|
||||
|
||||
/* update the record in the indexing database */
|
||||
key.dptr = (unsigned char *) talloc_asprintf(NULL, "0x%.16"PRIx64, idNbr);
|
||||
key.dsize = strlen((const char *) key.dptr);
|
||||
|
||||
dbuf.dptr = (unsigned char *) talloc_strdup (NULL, [urlString UTF8String]);
|
||||
dbuf.dsize = strlen((const char *) dbuf.dptr);
|
||||
tdb_store (indexing->tdb, key, dbuf, TDB_MODIFY);
|
||||
talloc_free (key.dptr);
|
||||
talloc_free (dbuf.dptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) registerURL: (NSString *) urlString
|
||||
withID: (uint64_t) idNbr
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user