# HG changeset patch # User Jens Alfke # Date 1251906085 25200 # Node ID 5cab3034d3a104ea576ea2be94152116f057ad9e # Parent 50c4f26bcc1b0251f3722b858141afd7afb19ce4 10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath. diff -r 50c4f26bcc1b -r 5cab3034d3a1 MYDirectoryWatcher.m --- a/MYDirectoryWatcher.m Mon Aug 10 08:29:32 2009 -0700 +++ b/MYDirectoryWatcher.m Wed Sep 02 08:41:25 2009 -0700 @@ -35,7 +35,8 @@ self = [super init]; if (self != nil) { _path = path.copy; - _standardizedPath = [[_path stringByStandardizingPath] copy]; + // stringByStandardizingPath is supposed to resolve symlinks, but in 10.6 this seems to have stopped happening... + _standardizedPath = [[[path stringByResolvingSymlinksInPath] stringByStandardizingPath] copy]; _target = target; _action = action; _latency = 5.0; @@ -198,7 +199,8 @@ - (NSString*) relativePath { NSString *base = watcher.standardizedPath; - NSString *standardizedPath = [path stringByStandardizingPath]; + // stringByStandardizingPath is supposed to resolve symlinks, but in 10.6 this seems to have stopped happening... + NSString *standardizedPath = [[path stringByResolvingSymlinksInPath] stringByStandardizingPath]; if( ! [standardizedPath hasPrefix: base] ) return nil; unsigned length = base.length; diff -r 50c4f26bcc1b -r 5cab3034d3a1 MYTask.m --- a/MYTask.m Mon Aug 10 08:29:32 2009 -0700 +++ b/MYTask.m Wed Sep 02 08:41:25 2009 -0700 @@ -9,7 +9,6 @@ //FIX: NOTICE: This code was written assuming garbage collection. It will currently leak like a sieve without it. - NSString* const MYTaskErrorDomain = @"MYTaskError"; NSString* const MYTaskExitCodeKey = @"MYTaskExitCode"; NSString* const MYTaskObjectKey = @"MYTask"; @@ -205,6 +204,8 @@ [self _close]; return [self makeError: @"Exception launching %@: %@",_task.launchPath,x]; } + LogTo(MYTaskVerbose, @"Launched task, modes %@", _modes); + Assert(_task.isRunning); _taskRunning = YES; self.isRunning = YES; @@ -214,6 +215,7 @@ - (void) stop { + LogTo(MYTaskVerbose, @"Stopping task"); [_task interrupt]; [self _close]; _taskRunning = NO; @@ -233,7 +235,7 @@ if( n.object == _outHandle ) { if( data.length > 0 ) { [_outHandle readInBackgroundAndNotifyForModes: _modes]; - LogTo(HgTaskVerbose, @"Got %u bytes of output",data.length); + LogTo(MYTaskVerbose, @"Got %u bytes of output",data.length); if( _outputData ) { [self willChangeValueForKey: @"output"]; [self willChangeValueForKey: @"outputData"]; @@ -243,7 +245,7 @@ [self didChangeValueForKey: @"output"]; } } else { - LogTo(HgTaskVerbose, @"Closed output"); + LogTo(MYTaskVerbose, @"Closed output"); _outHandle = nil; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -257,12 +259,12 @@ NSData *data = [n.userInfo objectForKey: NSFileHandleNotificationDataItem]; if( data.length > 0 ) { [_errHandle readInBackgroundAndNotifyForModes: _modes]; - LogTo(HgTaskVerbose, @"Got %u bytes of stderr",data.length); + LogTo(MYTaskVerbose, @"Got %u bytes of stderr",data.length); [self willChangeValueForKey: @"errorData"]; [_errorData appendData: data]; [self didChangeValueForKey: @"errorData"]; } else { - LogTo(HgTaskVerbose, @"Closed stderr"); + LogTo(MYTaskVerbose, @"Closed stderr"); _errHandle = nil; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -273,7 +275,7 @@ - (void) _exited: (NSNotification*)n { _resultCode = _task.terminationStatus; - LogTo(HgTaskVerbose, @"Exited with result=%i",_resultCode); + LogTo(MYTaskVerbose, @"Exited with result=%i",_resultCode); _taskRunning = NO; if( [self _shouldFinishUp] ) [self _finishUp]; @@ -287,7 +289,7 @@ [NSObject cancelPreviousPerformRequestsWithTarget: self selector: @selector(_finishUp) object: nil]; [self _close]; - LogTo(HgTaskVerbose, @"Finished!"); + LogTo(MYTaskVerbose, @"Finished!"); if( _resultCode != 0 ) { // Handle errors: @@ -326,8 +328,22 @@ { // wait for task to exit: while( _task.isRunning || self.isRunning ) - [[NSRunLoop currentRunLoop] runMode: MYTaskSynchronousRunLoopMode - beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]]; + if (![[NSRunLoop currentRunLoop] runMode: runLoopMode + beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]]) { + // This happens if both stderr and stdout are closed (leaving no NSFileHandles running + // in this runloop mode) but the task hasn't yet notified me that it exited. + // For some reason, in 10.6 the notification sometimes just doesn't appear, so poll + // for it: + if (_task.isRunning) { + Warn(@"MYTask _waitTillFinishedInMode: no runloop sources left for %@ mode; waiting...", runLoopMode); + sleep(1); + } else { + Warn(@"MYTask _waitTillFinishedInMode: Task exited without notifying!"); + [self _exited: nil]; + } + } else + LogTo(MYTaskVerbose, @"..._waitTillFinishedInMode still waiting..."); + return (_resultCode==0); } diff -r 50c4f26bcc1b -r 5cab3034d3a1 Test.h --- a/Test.h Mon Aug 10 08:29:32 2009 -0700 +++ b/Test.h Wed Sep 02 08:41:25 2009 -0700 @@ -93,7 +93,7 @@ struct TestCaseLink {void (*testptr)(); const char *name; BOOL passed; struct TestCaseLink *next;}; extern struct TestCaseLink *gAllTestCases; -#endif DEBUG +#endif // DEBUG void _AssertFailed( id rcvr, const void *selOrFn, const char *sourceFile, int sourceLine, const char *condString, NSString *message, ... ) __attribute__((noreturn)); void _AssertAbstractMethodFailed( id rcvr, SEL cmd) __attribute__((noreturn)); diff -r 50c4f26bcc1b -r 5cab3034d3a1 Test.m --- a/Test.m Mon Aug 10 08:29:32 2009 -0700 +++ b/Test.m Wed Sep 02 08:41:25 2009 -0700 @@ -120,7 +120,7 @@ } -#endif DEBUG +#endif // DEBUG #pragma mark -