From 14fec1a6084875c7d32be0f3c7edd01b60077af4 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Wed, 8 May 2013 10:19:25 -0400 Subject: [PATCH] Fixed: deleted xib or cib files were not processed correctly. Now, deleting a xib file will delete its corresponding cib. Deleting the cib will mark its corresponding xib for updating. --- Tools/XcodeCapp/XcodeCapp/XcodeCapp.m | 57 +++++++++++++++++++++------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/Tools/XcodeCapp/XcodeCapp/XcodeCapp.m b/Tools/XcodeCapp/XcodeCapp/XcodeCapp.m index 70ce45d18..d51e4ef35 100644 --- a/Tools/XcodeCapp/XcodeCapp/XcodeCapp.m +++ b/Tools/XcodeCapp/XcodeCapp/XcodeCapp.m @@ -1002,9 +1002,35 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, if ([self.fm fileExistsAtPath:path]) [modifiedPaths addObject:path]; + else if ([path.pathExtension isEqualToString:@"xib"]) + { + // If a xib is deleted, delete its cib. There is no need to update when a xib is deleted, + // it is inside a folder in Xcode, which updates automatically. + + if (![self.fm fileExistsAtPath:path]) + { + NSString *cibPath = [path.stringByDeletingPathExtension stringByAppendingPathExtension:@"cib"]; + + if ([self.fm fileExistsAtPath:cibPath]) + [self.fm removeItemAtPath:cibPath error:nil]; + + continue; + } + } needUpdate = YES; } + else if (isFile && (renamed || removed) && !(modified || created) && [path.pathExtension isEqualToString:@"cib"]) + { + // If a cib is deleted, mark its xib as needing update so the cib is regenerated + NSString *xibPath = [path.stringByDeletingPathExtension stringByAppendingPathExtension:@"xib"]; + + if ([self.fm fileExistsAtPath:xibPath]) + { + [modifiedPaths addObject:xibPath]; + needUpdate = YES; + } + } } else // directory-based listening { @@ -1087,14 +1113,15 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, // Make sure we don't get any more events while handling these events [self stopFSEventStream]; - DDLogVerbose(@"Modified files: %@", modifiedPaths); + NSArray *removedFiles = [self tidyShadowedFiles]; - [self tidyShadowedFiles]; + if (removedFiles.count || modifiedPaths.count) + { + for (NSString *path in modifiedPaths) + [self handleFileModificationAtPath:path]; - for (NSString *path in modifiedPaths) - [self handleFileModificationAtPath:path]; - - [self waitForOperationQueueToFinishWithSelector:@selector(batchDidFinish)]; + [self waitForOperationQueueToFinishWithSelector:@selector(batchDidFinish)]; + } } - (void)resetProjectForWatchedPath:(NSString *)path @@ -1313,26 +1340,30 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, DDLogVerbose(@"Removed shadow references to: %@", sourcePaths); } -- (void)tidyShadowedFiles +- (NSArray *)tidyShadowedFiles { NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.supportPath error:nil]; NSMutableArray *pathsToRemove = [NSMutableArray new]; for (NSString *path in subpaths) { - if (![path.pathExtension isEqual:@"h"] || [path.lastPathComponent isEqualToString:@"xcc_general_include.h"]) - continue; + NSString *extension = path.pathExtension; + + if ([extension isEqualToString:@"h"] && ![path.lastPathComponent isEqualToString:@"xcc_general_include.h"]) + { + NSString *sourcePath = [self sourcePathForShadowPath:path]; - NSString *sourcePath = [self sourcePathForShadowPath:path]; - - if (![self.fm fileExistsAtPath:sourcePath]) - [pathsToRemove addObject:sourcePath]; + if (![self.fm fileExistsAtPath:sourcePath]) + [pathsToRemove addObject:sourcePath]; + } } [self removeReferencesToSourcePaths:pathsToRemove]; if (pathsToRemove.count) self.pbxOperations[@"remove"] = pathsToRemove; + + return pathsToRemove; } #pragma mark - XCC Ignore management