--- a/Source/AILoggerPlugin.m Wed Jun 20 23:31:00 2012 +0200
+++ b/Source/AILoggerPlugin.m Sat Jul 21 14:17:16 2012 +0200
@@ -483,6 +483,7 @@
bself->logIndex = _index;
+ if (logIndex) CFRetain(logIndex); @@ -531,6 +532,8 @@
+ CFRelease(logSearchIndex); @@ -1423,16 +1426,15 @@
//Reset the cleaning progress
__block __typeof__(self) bself = self;
__block NSMutableSet *localLogSet = nil;
dispatch_sync(dirtyLogSetMutationQueue, ^{
localLogSet = [[self.dirtyLogSet mutableCopy] autorelease];
- // bself.logsToIndex = [bself.dirtyLogSet count];
OSAtomicCompareAndSwap64Barrier(bself->logsToIndex, [localLogSet count], (int64_t *)&(bself->logsToIndex));
OSAtomicCompareAndSwap64Barrier(_remainingLogs, bself->logsToIndex, (int64_t *)&_remainingLogs);
if (self.logsToIndex == 0){
dispatch_async(defaultDispatchQueue, ^{
OSAtomicCompareAndSwap64Barrier(logsIndexed, 0, (int64_t*)&logsIndexed);
[bself _didCleanDirtyLogs];
@@ -1440,14 +1442,12 @@
__block SKIndexRef searchIndex = [self logContentIndex];
AILogWithSignature(@"*** Warning: Could not open searchIndex in -[%@ _cleanDirtyLogs]. That shouldn't happen!", self);
OSAtomicCompareAndSwap64Barrier(logsIndexed, 0, (int64_t*)&logsIndexed);
if (self.indexingAllowed) {
@@ -1457,7 +1457,9 @@
__block SInt32 unsavedChanges = 0;
AILogWithSignature(@"Cleaning %i dirty logs", [localLogSet count]);
dispatch_group_async(loggerPluginGroup, searchIndexQueue, blockWithAutoreleasePool(^{
dispatch_group_enter(logIndexingGroup);
@@ -1474,15 +1476,20 @@
[localLogSet removeObject:__logPath];
logPath = [[__logPath copy] autorelease];
NSURL *logURL = [NSURL fileURLWithPath:logPath];
+ NSAssert(logURL != nil, @"Converting path to url failed"); dispatch_semaphore_wait(logLoadingPrefetchSemaphore, DISPATCH_TIME_FOREVER);
dispatch_group_async(logIndexingGroup, ioQueue, blockWithAutoreleasePool(^{
__block SKDocumentRef document = SKDocumentCreateWithURL((CFURLRef)logURL);
if (document && bself.indexingAllowed) {
/* We _could_ use SKIndexAddDocument() and depend on our Spotlight plugin for importing.
* However, this has three problems:
@@ -1492,29 +1499,33 @@
* 3. On 10.3, this means that logs' markup is indexed in addition to their text, which is undesireable.
- NSData *documentData = [CopyDataForURL(NULL, logURL) autorelease];
+ NSData *documentData = CopyDataForURL(NULL, logURL); dispatch_semaphore_wait(jobSemaphore, DISPATCH_TIME_FOREVER);
- dispatch_group_async(logIndexingGroup, defaultDispatchQueue, blockWithAutoreleasePool(^{
+ dispatch_group_async(logIndexingGroup, defaultDispatchQueue, blockWithAutoreleasePool(^{ __block CFStringRef documentText = CopyTextContentForFileData(NULL, logURL, documentData);
- CFRetain(documentText);
+ [documentData release]; dispatch_group_async(logIndexingGroup, defaultDispatchQueue, blockWithAutoreleasePool(^{
- if (documentText && bself.indexingAllowed) {
+ if (documentText && CFStringGetLength(documentText) > 0 && bself.indexingAllowed) { static dispatch_queue_t skQueue = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
skQueue = dispatch_queue_create("im.adium.AILoggerPlugin._cleanDirtyLogs.skQueue", 0);
dispatch_group_async(logIndexingGroup, skQueue, ^{
- SKIndexAddDocumentWithText(searchIndex,
+ SKIndexAddDocumentWithText(searchIndex, document, documentText, YES); OSAtomicIncrement64Barrier((int64_t *)&(bself->logsIndexed));
OSAtomicDecrement64Barrier((int64_t *)&_remainingLogs);
@@ -1528,6 +1539,7 @@
OSAtomicIncrement32Barrier((int32_t *)&unsavedChanges);
if (unsavedChanges > LOG_CLEAN_SAVE_INTERVAL) {
[bself _saveDirtyLogSet];
OSAtomicCompareAndSwap32Barrier(unsavedChanges, 0, (int32_t *)&unsavedChanges);
@@ -1543,6 +1555,7 @@
} else if (documentText) {
dispatch_semaphore_signal(jobSemaphore);
OSAtomicIncrement64Barrier((int64_t *)&(bself->logsIndexed));
@@ -1553,23 +1566,29 @@
dispatch_semaphore_signal(logLoadingPrefetchSemaphore);
- AILogWithSignature(@"Could not create document for %@ [%@]",logPath,[NSURL fileURLWithPath:logPath]);
- if (document) CFRelease(document);
+ AILogWithSignature(@"Could not create document for %@ [%@]", logPath, logURL); OSAtomicIncrement64Barrier((int64_t *)&(bself->logsIndexed));
OSAtomicDecrement64Barrier((int64_t *)&_remainingLogs);
- OSAtomicIncrement32Barrier((int32_t *)&unsavedChanges);
dispatch_semaphore_signal(jobSemaphore);
dispatch_semaphore_signal(logLoadingPrefetchSemaphore);
[pool release]; pool = nil;
@@ -1577,19 +1596,26 @@
[bself _saveDirtyLogSet];
dispatch_group_enter(closingIndexGroup);
dispatch_group_leave(logIndexingGroup);
dispatch_group_notify(logIndexingGroup, searchIndexQueue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
[[AILogViewerWindowController existingWindowController] logIndexingProgressUpdate];
[bself _flushIndex:searchIndex];
AILogWithSignature(@"After cleaning dirty logs, the search index has a max ID of %i and a count of %i",
SKIndexGetMaximumDocumentID(searchIndex),
SKIndexGetDocumentCount(searchIndex));
[bself _didCleanDirtyLogs];
dispatch_group_leave(closingIndexGroup);