Skip to content

Conversation

pudquick
Copy link

This is both a bug fix and a new feature.

First the bug fix - here's an example situation:

  • expectedVersion set to: 10.14.3
  • systemVersion read as: 10.15.1

This logic: https://github.com/google/macops/blob/master/deprecation_notifier/DeprecationNotifier/DNAppDelegate.m#L60-L63

  } else if (([expectedVersionArray[0] intValue] <= [systemVersionArray[0] intValue]) &&
             ([expectedVersionArray[1] intValue] <= [systemVersionArray[1] intValue]) &&
             ([expectedVersionArray[2] intValue] <= [systemVersionArray[2] intValue])) {
    NSLog(@"Exiting: OS is already %@ or greater", expectedVersion);

10 <= 10: true
14 <= 15: true
3 <= 1: false

The comparison will fail when it shouldn't.

This PR includes better comparison logic.

It additionally adds support for a new optional Localizable string value: expectedBuilds

The value of this string should be a comma delimited string (no spaces) of allowed builds.

If the OS is detected to be exactly the expectedVersion, then:

  • if no expectedBuilds is defined, Deprecation Notifier will determine the OS meets the requirement
  • if expectedBuilds is defined, the system build is looked for in expectedBuilds - if and only if the build is present, then the OS meets the requirement

Use case: for environments that are supporting a major OS version which has now gone into Security Updates, Deprecation Notifier is unable to tell a "fully patched" OS version without looking at the build information.

@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@pudquick
Copy link
Author

I signed it!

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@tburgin tburgin self-requested a review January 2, 2019 15:38
} else {
NSLog(@"Checking: OS build not found in expected builds [ %@ ]", expectedBuildsStr);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic, while correct, is a bit more difficult to read as it's quite repetitive. Could we flip it around?

if ([expectedVersionArray isEqualToArray:systemVersionArray]) {
  NSLog(@"Checking: running OS is equal to %@, checking build version", expectedVersion);
  if (!expectedBuilds.count) {
    NSLog(@"Exiting: No preferred build, so considered equal");
    [NSApp terminate:nil];
  }
  if ([expectedBuilds containsObject:systemBuild]) {
    NSLog(@"Exiting: OS build is one of the expected builds %@", expectedBuilds);
    [NSApp terminate:nil];
  }
  NSLog(@"Checking: OS build not found in expected builds %@", expectedBuilds);
} else if ([systemVersionArray[0] intValue] < [expectedVersionArray[0] intValue] ||
           [systemVersionArray[1] intValue] < [expectedVersionArray[1] intValue] ||
           [systemVersionArray[2] intValue] < [expectedVersionArray[2] intValue]) {
  NSLog(@"Checking: OS build is lower than required");
} else {
  NSLog(@"Exiting: OS build is greater than required");
  [NSapp terminate:nil];
}

([expectedVersionArray[1] intValue] == [systemVersionArray[1] intValue]) &&
([expectedVersionArray[2] intValue] == [systemVersionArray[2] intValue])) {
NSLog(@"Checking: OS is equal to %@, checking build version", expectedVersion);
if (expectedBuilds == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use expectedBuilds.count == 0 or !expectedBuilds.count to catch both nil and an empty array

if ([expectedBuilds containsObject:systemBuild]) {
NSLog(@"Exiting: OS build is one of the expected builds [ %@ ]", expectedBuildsStr);
[NSApp terminate:nil];
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the last line of the first condition exits, there's no need for the else, might as well remove it and reduce the indentation.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *expectedVersion = NSLocalizedString(@"expectedVersion", @"");
NSString *expectedBuildsStr = NSLocalizedString(@"expectedBuilds", @"");
NSArray *expectedBuilds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: For large expectedBuilds builds list, a set theoretically has faster lookups.

NSString *buildsKey = @"expectedBuilds";
NSString *builds = NSLocalizedString(buildsKey, @"");
NSSet *expectedBuilds = [NSSet setWithArray:[builds componentsSeparatedByString:@","]];
if (!expectedBuilds.count || [expectedBuilds containsObject:buildsKey]) expectedBuilds = nil;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants