Permalink
Browse files

Add missing braces.

Also fix the weird SPInvocationGrabber initializer.
  • Loading branch information...
martinh committed Mar 10, 2012
1 parent b4fb01c commit bb3d8d6f818c4cb4af7133946600e6da24b9dc50
Showing with 80 additions and 55 deletions.
  1. +10 −10 app/NSObject+SPInvocationGrabbing.h
  2. +18 −15 app/NSObject+SPInvocationGrabbing.m
  3. +36 −23 app/SFTPConnection.m
  4. +16 −7 app/ViURLManager.m
@@ -9,22 +9,22 @@
BOOL onMainAfterForward;
BOOL waitUntilDone;
}
--(id)initWithObject:(id)obj;
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
+- (id)initWithObject:(id)obj;
+- (id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
@property(nonatomic, readonly, retain, nonatomic) id object;
@property(nonatomic, readonly, retain, nonatomic) NSInvocation *invocation;
@property(nonatomic) BOOL backgroundAfterForward;
@property(nonatomic) BOOL onMainAfterForward;
@property(nonatomic) BOOL waitUntilDone;
--(void)invoke; // will release object and invocation
--(void)printBacktrace;
--(void)saveBacktrace;
+- (void)invoke; // will release object and invocation
+- (void)printBacktrace;
+- (void)saveBacktrace;
@end
@interface NSObject (SPInvocationGrabbing)
--(id)grab;
--(id)invokeAfter:(NSTimeInterval)delta;
--(id)nextRunloop;
--(id)inBackground;
--(id)onMainAsync:(BOOL)async;
+- (id)grab;
+- (id)invokeAfter:(NSTimeInterval)delta;
+- (id)nextRunloop;
+- (id)inBackground;
+- (id)onMainAsync:(BOOL)async;
@end
@@ -19,18 +19,18 @@ - (id)initWithObject:(id)obj
return [self initWithObject:obj stacktraceSaving:NO];
}
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack
+- (id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack
{
- self.object = obj;
-
- if (saveStack) {
- [self saveBacktrace];
+ if ((self = [super init]) != nil) {
+ _object = [obj retain];
+ if (saveStack) {
+ [self saveBacktrace];
+ }
}
-
return self;
}
--(void)dealloc
+- (void)dealloc
{
free(frameStrings);
[_object release];
@@ -66,15 +66,15 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation
- (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector
{
NSMethodSignature *signature = [super methodSignatureForSelector:inSelector];
- if (signature == NULL)
+ if (signature == NULL) {
signature = [_object methodSignatureForSelector:inSelector];
+ }
return signature;
}
- (void)invoke
{
-
@try {
[_invocation invoke];
}
@@ -89,14 +89,14 @@ - (void)invoke
self.object = nil;
}
--(void)saveBacktrace
+- (void)saveBacktrace
{
void *backtraceFrames[128];
frameCount = backtrace(&backtraceFrames[0], 128);
frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
}
--(void)printBacktrace
+- (void)printBacktrace
{
for (int x = 3; x < frameCount; x++) {
if (frameStrings[x] == NULL) {
@@ -105,15 +105,18 @@ -(void)printBacktrace
printf("%s\n", frameStrings[x]);
}
}
+
@end
+
@implementation NSObject (SPInvocationGrabbing)
--(id)grab
+
+- (id)grab
{
return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease];
}
--(id)invokeAfter:(NSTimeInterval)delta
+- (id)invokeAfter:(NSTimeInterval)delta
{
id grabber = [self grab];
[NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO];
@@ -125,14 +128,14 @@ - (id)nextRunloop
return [self invokeAfter:0];
}
--(id)inBackground
+- (id)inBackground
{
SPInvocationGrabber *grabber = [self grab];
grabber.backgroundAfterForward = YES;
return grabber;
}
--(id)onMainAsync:(BOOL)async
+- (id)onMainAsync:(BOOL)async
{
SPInvocationGrabber *grabber = [self grab];
grabber.onMainAfterForward = YES;
View
@@ -166,10 +166,11 @@ - (void)response:(SFTPMessage *)msg
DEBUG(@"got wait response %@ for %@", msg, _waitRequest);
}
- if (_responseCallback)
+ if (_responseCallback) {
_responseCallback(msg);
- else
+ } else {
DEBUG(@"NULL response callback for request id %u", _requestId);
+ }
_finished = YES;
if (gotWaitResponse) {
@@ -1284,15 +1285,16 @@ - (SFTPRequest *)contentsOfDirectoryAtURL:(NSURL *)aURL
openRequest.subRequest = [self closeHandle:handle
onResponse:^(NSError *error) {
openRequest.subRequest = nil;
- if (error)
+ if (error) {
originalCallback(nil, error);
- else {
+ } else {
openRequest.subRequest = [self resolveSymlinksInEntries:entries
relativeToURL:aURL
onCompletion:^(NSArray *resolvedEntries, NSError *error) {
openRequest.subRequest = nil;
- if (error)
+ if (error) {
resolvedEntries = nil;
+ }
originalCallback(resolvedEntries, error);
}];
}
@@ -1351,10 +1353,11 @@ - (SFTPRequest *)createDirectory:(NSString *)path
SFTPRequest *req = [self addRequest:SSH2_FXP_MKDIR format:"sa", path, [NSDictionary dictionary]];
req.onResponse = ^(SFTPMessage *msg) {
NSError *error;
- if (![msg expectStatus:SSH2_FX_OK error:&error])
+ if (![msg expectStatus:SSH2_FX_OK error:&error]) {
originalCallback(error);
- else
+ } else {
originalCallback(nil);
+ }
};
req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
return req;
@@ -1406,10 +1409,11 @@ - (SFTPRequest *)openFile:(NSString *)path
onResponse:(void (^)(NSData *handle, NSError *error))responseCallback
{
uint32_t mode;
- if (isWrite)
+ if (isWrite) {
mode = SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_EXCL;
- else
+ } else {
mode = SSH2_FXF_READ;
+ }
void (^originalCallback)(NSData *, NSError *) = [[responseCallback copy] autorelease];
@@ -1523,20 +1527,24 @@ - (SFTPRequest *)dataWithContentsOfURL:(NSURL *)url
}
DEBUG(@"got %lu bytes of data, requested %u", [data length], len);
- if (dataCallback)
+ if (dataCallback) {
dataCallback(data);
+ }
offset += [data length];
- if (fileSize > 0)
+ if (fileSize > 0) {
statRequest.progress = (CGFloat)offset / (CGFloat)fileSize;
- else
+ } else {
statRequest.progress = -1.0; /* unknown/indefinite progress */
+ }
/* Data callback may have cancelled us. */
- if (statRequest.cancelled)
+ if (statRequest.cancelled) {
return;
+ }
- if ([data length] < len)
+ if ([data length] < len) {
len = (uint32_t)[data length];
+ }
/* Dispatch next read request. */
for (int i = 0; i < 1/*max_req*/; i++) {
@@ -1580,10 +1588,11 @@ - (SFTPRequest *)setAttributes:(NSDictionary *)attributes
SFTPRequest *req = [self addRequest:SSH2_FXP_FSETSTAT format:"da", handle, attributes];
req.onResponse = ^(SFTPMessage *msg) {
NSError *error;
- if (![msg expectStatus:SSH2_FX_OK error:&error])
+ if (![msg expectStatus:SSH2_FX_OK error:&error]) {
originalCallback(error);
- else
+ } else {
originalCallback(nil);
+ }
};
req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
return req;
@@ -1651,8 +1660,9 @@ - (SFTPRequest *)uploadData:(NSData *)data
/* Dispatch next read request. */
uint32_t len = _transfer_buflen;
- if (offset + len > [data length])
+ if (offset + len > [data length]) {
len = (uint32_t)([data length] - offset);
+ }
NSData *chunk = [NSData dataWithBytesNoCopy:(void *)[data bytes] + offset length:len freeWhenDone:NO];
DEBUG(@"writing %u bytes at offset %lu", len, offset);
SFTPRequest *req = [self addRequest:SSH2_FXP_WRITE format:"dqd", handle, offset, chunk];
@@ -1665,8 +1675,9 @@ - (SFTPRequest *)uploadData:(NSData *)data
/* Dispatch first read request. */
uint32_t len = _transfer_buflen;
- if (offset + len > [data length])
+ if (offset + len > [data length]) {
len = (uint32_t)([data length] - offset);
+ }
NSData *chunk = [NSData dataWithBytesNoCopy:(void *)[data bytes] + offset length:len freeWhenDone:NO];
DEBUG(@"writing %u bytes at offset %lu", len, offset);
SFTPRequest *req = [self addRequest:SSH2_FXP_WRITE format:"dqd", handle, offset, chunk];
@@ -1688,10 +1699,11 @@ - (SFTPRequest *)removeItemAtPath:(NSString *)path
SFTPRequest *req = [self addRequest:SSH2_FXP_REMOVE format:"s", path];
req.onResponse = ^(SFTPMessage *msg) {
NSError *error;
- if (![msg expectStatus:SSH2_FX_OK error:&error])
+ if (![msg expectStatus:SSH2_FX_OK error:&error]) {
originalCallback(error);
- else
+ } else {
originalCallback(nil);
+ }
};
req.onCancel = ^(SFTPRequest *req) { originalCallback([ViError operationCancelled]); };
return req;
@@ -1708,10 +1720,12 @@ - (SFTPRequest *)removeItemsAtURLs:(NSArray *)urls
for (NSURL *url in mutableURLs) {
req = [self removeItemAtPath:[url path] onResponse:^(NSError *error) {
[mutableURLs removeObject:url];
- if (error)
+ if (error) {
originalCallback(error);
- if ([mutableURLs count] == 0)
+ }
+ if ([mutableURLs count] == 0) {
originalCallback(nil);
+ }
}];
}
@@ -1905,4 +1919,3 @@ - (NSString *)stderr
}
@end
-
View
@@ -289,8 +289,9 @@ - (BOOL)shouldRescanDirectoryAtURL:(NSURL *)aURL
ViWindowController *wincon = [window windowController];
if ([wincon respondsToSelector:@selector(explorer)]) {
ViFileExplorer *explorer = [wincon explorer];
- if ([explorer displaysURL:aURL])
+ if ([explorer displaysURL:aURL]) {
return YES;
+ }
}
}
@@ -312,27 +313,32 @@ - (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
DEBUG(@"directory %@ has changed, recursive = %s", aURL, recursiveFlush ? "YES" : "NO");
+ // XXX: Why is this event not triggered by the file explorer itself!?
[[ViEventManager defaultManager] emit:ViEventDirectoryChanged for:nil with:aURL, nil];
for (NSWindow *window in [NSApp windows]) {
ViWindowController *wincon = [window windowController];
if ([wincon respondsToSelector:@selector(explorer)]) {
ViFileExplorer *explorer = [wincon explorer];
if ([explorer displaysURL:aURL])
- [[ViEventManager defaultManager] emit:ViEventExplorerDirectoryChanged for:explorer with:explorer, aURL, nil];
+ [[ViEventManager defaultManager] emit:ViEventExplorerDirectoryChanged
+ for:explorer
+ with:explorer, aURL, nil];
}
}
if (!recursiveFlush) {
- if (![self directoryIsCachedAtURL:aURL])
+ if (![self directoryIsCachedAtURL:aURL]) {
return;
+ }
[self flushCachedContentsOfDirectoryAtURL:aURL];
if ([self shouldRescanDirectoryAtURL:aURL]) {
[self contentsOfDirectoryAtURL:aURL onCompletion:^(NSArray *contents, NSError *error) {
/* Any interested project explorer will get a notification. */
DEBUG(@"rescanned URL %@, error %@", aURL, error);
}];
- } else if ([aURL isFileURL])
+ } else if ([aURL isFileURL]) {
[self restartEvents]; /* To un-monitor the flushed directory. */
+ }
return;
}
@@ -352,13 +358,15 @@ - (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
/* Any interested project explorer will get a notification. */
DEBUG(@"rescanned URL %@, error %@", url, error);
}];
- } else
+ } else {
restart = YES;
+ }
}
}
- if (restart && [aURL isFileURL])
+ if (restart && [aURL isFileURL]) {
[self restartEvents];
+ }
}
- (void)notifyChangedDirectoryAtURL:(NSURL *)aURL
@@ -413,12 +421,13 @@ - (BOOL)URLIsMonitored:(NSURL *)aURL
NSString *path = [aURL path];
NSArray *pathsBeingWatched = (NSArray *)FSEventStreamCopyPathsBeingWatched(_evstream);
- for (NSString *p in pathsBeingWatched)
+ for (NSString *p in pathsBeingWatched) {
if ([path hasPrefix:p]) {
DEBUG(@"URL %@ is already being watched", aURL);
CFRelease(pathsBeingWatched);
return YES;
}
+ }
CFRelease(pathsBeingWatched);
return NO;

0 comments on commit bb3d8d6

Please sign in to comment.