Skip to content

Commit

Permalink
Don't calculate free disk space since it requires grey APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
kstenerud committed Dec 7, 2023
1 parent aed032b commit 3d55181
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 89 deletions.
24 changes: 3 additions & 21 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashReport.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ void bsg_kscrw_i_writeTraceInfo(const BSG_KSCrash_Context *crashContext,
bool bsg_kscrw_i_exceedsBufferLen(const size_t length);

void bsg_kscrashreport_writeKSCrashFields(BSG_KSCrash_Context *crashContext,
BSG_KSCrashReportWriter *writer,
const char *const path);
BSG_KSCrashReportWriter *writer);

#pragma mark Backtrace

Expand Down Expand Up @@ -869,21 +868,6 @@ void bsg_kscrw_i_writeMemoryInfo(const BSG_KSCrashReportWriter *const writer,
writer->endContainer(writer);
}

void bsg_kscrw_i_writeDiskInfo(const BSG_KSCrashReportWriter *const writer,
const char *const key,
const char *const path) {
uint64_t freeDisk, size;
if (!bsg_ksfuStatfs(path, &freeDisk, &size)) {
return;
}
writer->beginObject(writer, key);
{
bsg_kscrw_i_addUIntegerElement(writer, BSG_KSCrashField_Free, freeDisk);
bsg_kscrw_i_addUIntegerElement(writer, BSG_KSCrashField_Size, size);
}
writer->endContainer(writer);
}

/** Write information about the error leading to the crash to the report.
*
* @param writer The writer.
Expand Down Expand Up @@ -1261,7 +1245,7 @@ void bsg_kscrashreport_writeStandardReport(
writer, BSG_KSCrashField_Report, BSG_KSCrashReportType_Standard,
crashContext->config.crashID, crashContext->config.processName);

bsg_kscrashreport_writeKSCrashFields(crashContext, writer, path);
bsg_kscrashreport_writeKSCrashFields(crashContext, writer);

if (crashContext->config.onCrashNotify != NULL) {
// NOTE: The deny list for BSG_KSCrashField_UserAtCrash children in BugsnagEvent.m
Expand All @@ -1282,8 +1266,7 @@ void bsg_kscrashreport_writeStandardReport(
}

void bsg_kscrashreport_writeKSCrashFields(BSG_KSCrash_Context *crashContext,
BSG_KSCrashReportWriter *writer,
const char *const path) {
BSG_KSCrashReportWriter *writer) {

bsg_kscrw_i_writeProcessState(writer, BSG_KSCrashField_ProcessState);

Expand All @@ -1298,7 +1281,6 @@ void bsg_kscrashreport_writeKSCrashFields(BSG_KSCrash_Context *crashContext,
bsg_kscrw_i_writeMemoryInfo(writer, BSG_KSCrashField_Memory);
bsg_kscrw_i_writeAppStats(writer, BSG_KSCrashField_AppStats,
&crashContext->state);
bsg_kscrw_i_writeDiskInfo(writer, BSG_KSCrashField_Disk, path);
}
writer->endContainer(writer);

Expand Down
13 changes: 0 additions & 13 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,6 @@ + (NSDictionary *)systemInfo {
@BSG_KSCrashField_Size: @(NSProcessInfo.processInfo.physicalMemory)
};

NSString *dir = NSSearchPathForDirectoriesInDomains(
NSCachesDirectory, NSUserDomainMask, YES).firstObject;
const char *path = dir.fileSystemRepresentation;
if (path) {
uint64_t dfree, size;
if (bsg_ksfuStatfs(path, &dfree, &size)) {
sysInfo[@BSG_KSSystemField_Disk] = @{
@ BSG_KSCrashField_Free: @(dfree),
@ BSG_KSCrashField_Size: @(size)
};
}
}

bsg_kscrashstate_updateDurationStats();
BSG_KSCrash_State state = crashContext()->state;
NSMutableDictionary *statsInfo = [NSMutableDictionary dictionary];
Expand Down
10 changes: 0 additions & 10 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSFileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,3 @@ bool bsg_ksfuwriteBytesToFD(const int fd, const char *const bytes,

return true;
}

bool bsg_ksfuStatfs(const char *path, uint64_t *free, uint64_t *total) {
struct statfs st;
if (statfs(path, &st) != 0) {
return false;
}
*free = st.f_bsize * st.f_bavail;
*total = st.f_bsize * st.f_blocks;
return true;
}
12 changes: 0 additions & 12 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/Tools/BSG_KSFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ bool bsg_ksfuwriteBytesToFD(const int fd, const char *bytes, ssize_t length);
*/
bool bsg_ksfuflushWriteBuffer(const int fd);

/**
* Get file system statistics.
*
* @param path The path name of any file or directory within the file system.
* @param free A pointer to where the number of free bytes availalable to a
* non-superuser (corresponding to NSFileSystemFreeSize) should be
* written.
* @param total A pointer to where the total number of bytes in the file system
* should be written.
*/
bool bsg_ksfuStatfs(const char *path, uint64_t *free, uint64_t *total);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 0 additions & 3 deletions Bugsnag/Payload/BugsnagDeviceWithState.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ + (BugsnagDeviceWithState *) deviceFromJson:(NSDictionary *)json {
BugsnagDeviceWithState *device = [BugsnagDeviceWithState new];
device.id = json[@"id"];
device.freeMemory = json[@"freeMemory"];
device.freeDisk = json[@"freeDisk"];
device.locale = json[@"locale"];
device.manufacturer = json[@"manufacturer"];
device.model = json[@"model"];
Expand Down Expand Up @@ -84,7 +83,6 @@ + (BugsnagDeviceWithState *)deviceWithKSCrashReport:(NSDictionary *)event {
[self populateFields:device dictionary:event];
device.orientation = [event valueForKeyPath:@"user.state.deviceState.orientation"];
device.freeMemory = [event valueForKeyPath:@"system." BSG_KSSystemField_Memory "." BSG_KSCrashField_Free];
device.freeDisk = [event valueForKeyPath:@"system." BSG_KSSystemField_Disk "." BSG_KSCrashField_Free];

NSString *val = [event valueForKeyPath:@"report.timestamp"];

Expand All @@ -103,7 +101,6 @@ + (BugsnagDeviceWithState *)deviceWithKSCrashReport:(NSDictionary *)event {

- (NSDictionary *)toDictionary {
NSMutableDictionary *dict = [[super toDictionary] mutableCopy];
dict[@"freeDisk"] = self.freeDisk;
dict[@"freeMemory"] = self.freeMemory;
dict[@"orientation"] = self.orientation;
dict[@"time"] = self.time ? [BSG_RFC3339DateTool stringFromDate:self.time] : nil;
Expand Down
5 changes: 0 additions & 5 deletions Bugsnag/include/Bugsnag/BugsnagDeviceWithState.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
BUGSNAG_EXTERN
@interface BugsnagDeviceWithState : BugsnagDevice

/**
* The number of free bytes of storage available on the device
*/
@property (strong, nullable, nonatomic) NSNumber *freeDisk;

/**
* The number of free bytes of memory available on the device
*/
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ GEM
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
nokogiri (1.15.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-darwin)
racc (~> 1.4)
optimist (3.0.1)
Expand Down Expand Up @@ -208,6 +210,7 @@ GEM
rexml (~> 3.2.4)

PLATFORMS
arm64-darwin-22
x86_64-darwin-19

DEPENDENCIES
Expand Down
1 change: 0 additions & 1 deletion Tests/BugsnagTests/BugsnagClientPayloadInfoTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ - (void)testAppInfo {
- (void)testDeviceInfo {
BugsnagClient *client = [Bugsnag client];
NSDictionary *device = [[client generateDeviceWithState:BSGGetSystemInfo()] toDictionary];
XCTAssertNotNil(device[@"freeDisk"]);
XCTAssertNotNil(device[@"freeMemory"]);
XCTAssertNotNil(device[@"id"]);
XCTAssertNotNil(device[@"jailbroken"]);
Expand Down
4 changes: 0 additions & 4 deletions Tests/BugsnagTests/BugsnagDeviceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ - (void)testDeviceWithState {
XCTAssertEqualObjects(runtimeVersions, device.runtimeVersions);

// verify stateful fields
XCTAssertGreaterThan(device.freeDisk.longLongValue, 0);
XCTAssertEqualObjects(@742920192, device.freeMemory);
XCTAssertEqualObjects(@"portrait", device.orientation);

Expand Down Expand Up @@ -153,7 +152,6 @@ - (void)testDeviceWithStateToDict {

// verify stateless fields
XCTAssertEqualObjects(@"portrait", dict[@"orientation"]);
XCTAssertTrue(dict[@"freeDisk"] > 0);
XCTAssertEqualObjects(@742920192, dict[@"freeMemory"]);

NSDateFormatter *formatter = [NSDateFormatter new];
Expand Down Expand Up @@ -190,7 +188,6 @@ - (void)testDeviceFromJson {
@"osBuild": @"14B25",
@"clangVersion": @"10.0.0 (clang-1000.11.45.5)"
},
@"freeDisk": @509234098,
@"freeMemory": @742920192,
@"orientation": @"portrait",
@"time": @"2014-12-02T01:56:13Z"
Expand All @@ -215,7 +212,6 @@ - (void)testDeviceFromJson {
XCTAssertEqualObjects(runtimeVersions, device.runtimeVersions);

// verify stateful fields
XCTAssertEqualObjects(@509234098, device.freeDisk);
XCTAssertEqualObjects(@742920192, device.freeMemory);
XCTAssertEqualObjects(@"portrait", device.orientation);

Expand Down
2 changes: 0 additions & 2 deletions Tests/BugsnagTests/BugsnagEventPersistLoadTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ - (void)testAppFieldsOverride {
- (void)testDeviceFieldsOverride {
BugsnagEvent *event = [self generateEventWithOverrides:@{
@"device": @{
@"freeDisk": @920234094,
@"freeMemory": @5092340923,
@"totalMemory": @92092340923,
@"orientation": @"landscape",
Expand All @@ -159,7 +158,6 @@ - (void)testDeviceFieldsOverride {
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];

BugsnagDeviceWithState *device = event.device;
XCTAssertEqualObjects(@920234094, device.freeDisk);
XCTAssertEqualObjects(@5092340923, device.freeMemory);
XCTAssertEqualObjects(@92092340923, device.totalMemory);
XCTAssertEqualObjects(@"landscape", device.orientation);
Expand Down
7 changes: 0 additions & 7 deletions Tests/BugsnagTests/BugsnagSwiftPublicAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,6 @@ class BugsnagSwiftPublicAPITests: BSGTestCase {

// withState

device.freeDisk = nil
device.freeDisk = 0
device.freeDisk = 1.1
device.freeDisk = -45
device.freeDisk = NSNumber(booleanLiteral: true)
_ = device.freeDisk

device.freeMemory = nil
device.freeMemory = 0
device.freeMemory = 1.1
Expand Down
2 changes: 1 addition & 1 deletion Tests/BugsnagTests/Data/BugsnagEvents/BugsnagEvent1.json

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Tests/BugsnagTests/EventApiValidationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ - (void)testValidDevice {
BugsnagDeviceWithState *device = self.event.device;
XCTAssertNotNil(device);

device.freeDisk = nil;
XCTAssertNil(device.freeDisk);
device.freeDisk = @20983409;
XCTAssertEqualObjects(@20983409, device.freeDisk);

device.freeMemory = nil;
XCTAssertNil(device.freeMemory);
device.freeMemory = @509234092;
Expand Down
1 change: 0 additions & 1 deletion features/app_and_device_attributes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Feature: App and Device attributes present

# DeviceWithState

And the error payload field "events.0.device.freeDisk" is an integer
And the error payload field "events.0.device.freeMemory" is an integer
And on iOS, the event "device.orientation" matches "(face(down|up)|landscape(left|right)|portrait(upsidedown)?)"
And the error payload field "events.0.device.time" is a date
Expand Down
1 change: 0 additions & 1 deletion features/app_hangs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Feature: App hangs

# DeviceWithState

And the error payload field "events.0.device.freeDisk" is an integer
And the error payload field "events.0.device.freeMemory" is an integer
And on iOS, the event "device.orientation" matches "(face(down|up)|landscape(left|right)|portrait(upsidedown)?)"
And the error payload field "events.0.device.time" is a date
Expand Down
3 changes: 0 additions & 3 deletions features/barebone_tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Feature: Barebone tests
And the error payload field "events.0.app.dsymUUIDs" is a non-empty array
And the error payload field "events.0.app.duration" is a number
And the error payload field "events.0.app.durationInForeground" is a number
And the error payload field "events.0.device.freeDisk" is an integer
And the error payload field "events.0.device.freeMemory" is an integer
And the error payload field "events.0.device.model" matches the regex "[iPad|Macmini|iPhone]1?\d,\d"
And the error payload field "events.0.device.totalMemory" is an integer
Expand Down Expand Up @@ -232,7 +231,6 @@ Feature: Barebone tests
And the error payload field "events.0.app.dsymUUIDs" is a non-empty array
And the error payload field "events.0.app.duration" is a number
And the error payload field "events.0.app.durationInForeground" is a number
And the error payload field "events.0.device.freeDisk" is an integer
And the error payload field "events.0.device.freeMemory" is an integer
And the error payload field "events.0.device.model" matches the regex "[iPad|Macmini|iPhone]1?\d,\d"
And the error payload field "events.0.device.totalMemory" is an integer
Expand Down Expand Up @@ -335,6 +333,5 @@ Feature: Barebone tests
And the error payload field "events.0.app.dsymUUIDs" is a non-empty array
And the error payload field "events.0.app.duration" is null
And the error payload field "events.0.app.durationInForeground" is null
And the error payload field "events.0.device.freeDisk" is null
And the error payload field "events.0.device.model" matches the regex "[iPad|Macmini|iPhone]1?\d,\d"
And the error payload field "events.0.threads" is an array with 0 elements

0 comments on commit 3d55181

Please sign in to comment.