Skip to content

Commit

Permalink
properly parse output of vagrant version command (issue #127)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswayoub committed Jan 3, 2016
1 parent 5ad847f commit 582e6f4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Vagrant Manager/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,28 @@ - (void)checkForVagrantUpdates:(BOOL)showAlert {

BOOL newVersionAvailable = NO;
BOOL invalidOutput = YES;
NSString *currentVersion;
NSString *latestVersion;
NSString *currentVersion = nil;
NSString *latestVersion = nil;


if([lines count] >= 2) {
NSArray *installedVersionParts = [[lines objectAtIndex:0] componentsSeparatedByString:@","];
NSArray *latestVersionParts = [[lines objectAtIndex:1] componentsSeparatedByString:@","];
for(NSString *line in lines) {
NSArray *cols = [line componentsSeparatedByString:@","];

if([installedVersionParts count] >= 4 && [latestVersionParts count] >= 4) {
currentVersion = [installedVersionParts objectAtIndex:3];
latestVersion = [latestVersionParts objectAtIndex:3];

if([Util compareVersion:currentVersion toVersion:latestVersion] == NSOrderedAscending) {
newVersionAvailable = YES;
if([cols count] >=4 ) {
if([[cols objectAtIndex:2] isEqualToString:@"version-installed"]) {
currentVersion = [cols objectAtIndex:3];
} else if([[cols objectAtIndex:2] isEqualToString:@"version-latest"]) {
latestVersion = [cols objectAtIndex:3];
}

invalidOutput = NO;
}
}

if(currentVersion && latestVersion) {
newVersionAvailable = [Util compareVersion:currentVersion toVersion:latestVersion] == NSOrderedAscending;
invalidOutput = NO;
} else {
invalidOutput = YES;
}

dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"vagrant-manager.vagrant-update-available" object:nil userInfo:@{@"is_update_available": [NSNumber numberWithBool:newVersionAvailable]}];

Expand Down

0 comments on commit 582e6f4

Please sign in to comment.