CommitController: don't mutate array we enumerate when refreshing index

There was a nasty bug in handling the finishing of the index change.
This code path was changed when I simplified the file tracking, but
as a result the code now mutated the files array, over which
we were also enumerating. This can cause all sorts of bad stuff, like
files that aren't really deleted from the view, to wrong files that
are deleted, to a crash of the system for wrong memory access.
This commit is contained in:
Pieter de Bie
2009-06-11 23:37:41 +01:00
parent 5090d4f159
commit 963969af78
+16 -10
View File
@@ -160,17 +160,23 @@
// all files previously marked as deletable
- (void) doneProcessingIndex
{
[self willChangeValueForKey:@"files"];
if (!--self.busy) {
self.status = @"Ready";
for (PBChangedFile *file in files) {
if (!file.hasStagedChanges && !file.hasUnstagedChanges) {
NSLog(@"Deleting file: %@", [file path]);
[files removeObject:file];
}
}
// if we're still busy, do nothing :)
if (--self.busy)
return;
NSMutableArray *deleteFiles = [NSMutableArray array];
for (PBChangedFile *file in files) {
if (!file.hasStagedChanges && !file.hasUnstagedChanges)
[deleteFiles addObject:file];
}
[self didChangeValueForKey:@"files"];
if ([deleteFiles count]) {
[self willChangeValueForKey:@"files"];
for (PBChangedFile *file in deleteFiles)
[files removeObject:file];
[self didChangeValueForKey:@"files"];
}
self.status = @"Ready";
}
- (void) readOtherFiles:(NSNotification *)notification;