-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from WideSpectrumComputing/GH180
Resolve GH180, GH176 and GH166
- Loading branch information
Showing
35 changed files
with
344 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#import "RollbarFileWriter.h" | ||
#import "RollbarSdkLog.h" | ||
|
||
@implementation RollbarFileWriter | ||
|
||
+ (BOOL)ensureFileExists: (nullable NSString *)fileFullPath { | ||
|
||
if (!(fileFullPath && (fileFullPath.length > 0))) { | ||
|
||
RollbarSdkLog(@"Can't ensure existance of this file: %@!", fileFullPath); | ||
NO; | ||
} | ||
|
||
// make sure the file exists: | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileFullPath]) { | ||
|
||
if (![[NSFileManager defaultManager] createFileAtPath:fileFullPath | ||
contents:nil | ||
attributes:nil]) { | ||
RollbarSdkLog(@" Error while creating file: %@", fileFullPath); | ||
return NO; | ||
} | ||
} | ||
|
||
return YES; | ||
} | ||
|
||
+ (void)appendData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath { | ||
|
||
if (!(data && fileFullPath && (fileFullPath.length > 0))) { | ||
|
||
RollbarSdkLog(@"Can't append data: %@ to file: %@!", data, fileFullPath); | ||
return; | ||
} | ||
|
||
// append-save the data into the file (assuming it exists): | ||
|
||
NSError *error; | ||
|
||
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:fileFullPath]; | ||
if (!fileHandle) { | ||
|
||
RollbarSdkLog(@" Error while acquiring file handle for: %@", fileFullPath); | ||
return; | ||
} | ||
|
||
unsigned long long offset; | ||
if (![fileHandle seekToEndReturningOffset:&offset error:&error]) { | ||
|
||
RollbarSdkLog(@" Error while seeking to file end of %@: %@", fileFullPath, [error localizedDescription]); | ||
return; | ||
} | ||
|
||
if (![fileHandle writeData:data error:&error]) { | ||
|
||
RollbarSdkLog(@" Error while writing data to %@: %@", fileFullPath, [error localizedDescription]); | ||
return; | ||
} | ||
|
||
if (![fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding] error:&error]) { | ||
|
||
RollbarSdkLog(@" Error while writing data to %@: %@", fileFullPath, [error localizedDescription]); | ||
return; | ||
} | ||
|
||
if (![fileHandle closeAndReturnError:&error]) { | ||
|
||
RollbarSdkLog(@" Error while closing %@: %@", fileFullPath, [error localizedDescription]); | ||
return; | ||
} | ||
} | ||
|
||
+ (void)appendSafelyData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath { | ||
|
||
if (!data) { | ||
|
||
RollbarSdkLog(@"No data to append!"); | ||
return; | ||
} | ||
|
||
// make sure the file exists: | ||
if (NO == [RollbarFileWriter ensureFileExists:fileFullPath]) { | ||
|
||
return; | ||
} | ||
|
||
// append-save the data into the file: | ||
[RollbarFileWriter appendData:data toFile:fileFullPath]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
RollbarCommon/Sources/RollbarCommon/include/RollbarFileWriter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RollbarFileWriter.h | ||
// | ||
// | ||
// Created by Andrey Kornich on 2022-05-23. | ||
// | ||
|
||
@import Foundation; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RollbarFileWriter : NSObject | ||
|
||
+ (BOOL)ensureFileExists: (nullable NSString *)fileFullPath; | ||
+ (void)appendData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath; | ||
+ (void)appendSafelyData:(nullable NSData *)data toFile:(nullable NSString *)fileFullPath; | ||
|
||
/// Hides parameterless initializer. | ||
- (instancetype)init | ||
NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.