Skip to content

Commit

Permalink
feat: resolve #176
Browse files Browse the repository at this point in the history
- feat: resolve #176: Add sandboxing status detection to RollbarCachesDirectory.
  • Loading branch information
akornich committed Jul 9, 2019
1 parent b5cc4c8 commit 6cab14a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co
**1.8.0-alpha1**
**1.8.0**

- fix: ref #171: Fix build errors during cocoapods' trunk push
- feat: ref #168: add support for high sierra
- feat: ref #45: How about support for macOS?
- docs: ref #175: Create a sample app - macOSAppWithRollbarCocoaPod.
- feat: resolve #176: Add sandboxing status detection to RollbarCachesDirectory.
- fix: resolve #171: Fix build errors during cocoapods' trunk push
- docs: resolve #175: Create a sample app - macOSAppWithRollbarCocoaPod.


**1.7.0**
Expand Down
24 changes: 20 additions & 4 deletions Rollbar/RollbarCachesDirectory.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,34 @@
@implementation RollbarCachesDirectory

+ (NSString *)directory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory,
NSUserDomainMask,
YES);
NSString *cachesDirectory = paths.firstObject;

#if TARGET_OS_OSX
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if (nil != [processInfo.environment
valueForKey:@"APP_SANDBOX_CONTAINER_ID"]) {
// when the hosting process is sandboxed, the cachesDirectory is already
// allocated per application:
return cachesDirectory;
}

// when the hosting process is not sandboxed let's make sure we sandbox
// our own cache based on the process' unique attributes:
NSString *appBundleID = [NSBundle mainBundle].bundleIdentifier;
if (appBundleID) {
cachesDirectory = [cachesDirectory stringByAppendingPathComponent:appBundleID];
cachesDirectory =
[cachesDirectory stringByAppendingPathComponent:appBundleID];
}
else {
cachesDirectory =
[cachesDirectory stringByAppendingPathComponent:
[[NSProcessInfo processInfo] processName]];
[cachesDirectory stringByAppendingPathComponent:processInfo.processName];
}

#endif
return cachesDirectory;
}
Expand Down
46 changes: 29 additions & 17 deletions Rollbar/RollbarNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,54 @@ @implementation RollbarNotifier
- (id)initWithAccessToken:(NSString*)accessToken
configuration:(RollbarConfiguration*)configuration
isRoot:(BOOL)isRoot {

if ((self = [super init])) {
[self updateAccessToken:accessToken
configuration:configuration
isRoot:isRoot];

if (isRoot) {
NSString *cachesDirectory = [RollbarCachesDirectory directory];
if (nil != self.configuration.logPayloadFile
&& self.configuration.logPayloadFile.length > 0) {

payloadsFilePath =
[cachesDirectory stringByAppendingPathComponent:self.configuration.logPayloadFile];
[cachesDirectory stringByAppendingPathComponent:self.configuration.logPayloadFile];
}
else {

payloadsFilePath =
[cachesDirectory stringByAppendingPathComponent:PAYLOADS_FILE_NAME];
[cachesDirectory stringByAppendingPathComponent:PAYLOADS_FILE_NAME];
}
// create working cache directory:
if (![[NSFileManager defaultManager] fileExistsAtPath:cachesDirectory]) {
NSError *error;
BOOL result =
[[NSFileManager defaultManager] createDirectoryAtPath:cachesDirectory
withIntermediateDirectories:YES
attributes:nil
error:&error
];
NSLog(@"result %@", result);
}

queuedItemsFilePath =
[cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME];
[cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME];
stateFilePath =
[cachesDirectory stringByAppendingPathComponent:STATE_FILE_NAME];

[cachesDirectory stringByAppendingPathComponent:STATE_FILE_NAME];
// either create or overwrite the payloads log file:
[[NSFileManager defaultManager] createFileAtPath:payloadsFilePath
contents:nil
attributes:nil];
contents:nil
attributes:nil];

// create the queued items file if does not exist already:
if (![[NSFileManager defaultManager] fileExistsAtPath:queuedItemsFilePath]) {
[[NSFileManager defaultManager] createFileAtPath:queuedItemsFilePath
contents:nil
attributes:nil];
}

// create state tracking file if does not exist already:
if ([[NSFileManager defaultManager] fileExistsAtPath:stateFilePath]) {
NSData *stateData = [NSData dataWithContentsOfFile:stateFilePath];
Expand All @@ -92,31 +104,31 @@ - (id)initWithAccessToken:(NSString*)accessToken
queueState = [@{@"offset": [NSNumber numberWithUnsignedInt:0],
@"retry_count": [NSNumber numberWithUnsignedInt:0]} mutableCopy];
}

// Deals with sending items that have been queued up
rollbarThread = [[RollbarThread alloc] initWithNotifier:self reportingRate:configuration.maximumReportsPerMinute];
[rollbarThread start];

// Listen for reachability status
// so that items are only sent when the internet is available
reachability = [RollbarReachability reachabilityForInternetConnection];

isNetworkReachable = [reachability isReachable];

reachability.reachableBlock = ^(RollbarReachability*reach) {
[self captureTelemetryDataForNetwork:true];
isNetworkReachable = YES;
};

reachability.unreachableBlock = ^(RollbarReachability*reach) {
[self captureTelemetryDataForNetwork:false];
isNetworkReachable = NO;
};

[reachability startNotifier];
}
}

return self;
}

Expand Down

0 comments on commit 6cab14a

Please sign in to comment.