Skip to content

Commit

Permalink
Add missing braces.
Browse files Browse the repository at this point in the history
Also fix the weird SPInvocationGrabber initializer.
  • Loading branch information
martinh committed Jul 8, 2012
1 parent b4fb01c commit bb3d8d6
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 55 deletions.
20 changes: 10 additions & 10 deletions app/NSObject+SPInvocationGrabbing.h
Expand Up @@ -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
33 changes: 18 additions & 15 deletions app/NSObject+SPInvocationGrabbing.m
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}
Expand All @@ -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) {
Expand All @@ -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];
Expand All @@ -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;
Expand Down
59 changes: 36 additions & 23 deletions app/SFTPConnection.m
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}];
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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);
}
}];
}

Expand Down Expand Up @@ -1905,4 +1919,3 @@ - (NSString *)stderr
}

@end

23 changes: 16 additions & 7 deletions app/ViURLManager.m
Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bb3d8d6

Please sign in to comment.