From f90883c4914e5ab52eb2c19f32339817e8b876a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Gutowski?= Date: Mon, 20 Nov 2023 19:46:49 +0100 Subject: [PATCH] Drop the use of disk space APIs --- .../Fingerprints/DeviceInfoTreeProvider.swift | 16 ---- .../Harvesters/DataExchange/DeviceInfo.swift | 10 +- .../DataExchange/DiskSpaceInfo.swift | 1 + .../HardwareInfoHarvester.swift | 35 ------- .../Library/DeviceInfoProvider.swift | 2 - .../HardwareInfoHarvesterTests.swift | 96 ------------------- 6 files changed, 8 insertions(+), 152 deletions(-) diff --git a/Sources/FingerprintJS/Fingerprints/DeviceInfoTreeProvider.swift b/Sources/FingerprintJS/Fingerprints/DeviceInfoTreeProvider.swift index 31a2871..e6a5c4e 100644 --- a/Sources/FingerprintJS/Fingerprints/DeviceInfoTreeProvider.swift +++ b/Sources/FingerprintJS/Fingerprints/DeviceInfoTreeProvider.swift @@ -130,22 +130,6 @@ extension HardwareInfoHarvester: DeviceInfoTreeProvider { stabilityLevel: .stable, versions: .all ), - AnnotatedInfoItem( - DeviceInfoItem( - label: "Free disk space (B)", - value: .info(String(describing: freeDiskSpace)) - ), - stabilityLevel: .unique, - versions: .since(.v2) - ), - AnnotatedInfoItem( - DeviceInfoItem( - label: "Total disk space (B)", - value: .info(String(describing: totalDiskSpace)) - ), - stabilityLevel: .stable, - versions: .since(.v2) - ), AnnotatedInfoItem( DeviceInfoItem( label: "Device hostname", diff --git a/Sources/FingerprintJS/Harvesters/DataExchange/DeviceInfo.swift b/Sources/FingerprintJS/Harvesters/DataExchange/DeviceInfo.swift index 9625b90..45c7dc5 100644 --- a/Sources/FingerprintJS/Harvesters/DataExchange/DeviceInfo.swift +++ b/Sources/FingerprintJS/Harvesters/DataExchange/DeviceInfo.swift @@ -14,7 +14,13 @@ public struct DeviceInfo: Equatable, Encodable { /// The style associated with the user interface of the app. public let userInterfaceStyle: UserInterfaceStyle - public let diskSpace: DiskSpaceInfo? + @available( + *, + deprecated, + message: "DeviceInfo.diskSpace is always nil and will be removed in a future library version" + ) + public let diskSpace: DiskSpaceInfo? = nil + public let screenResolution: CGSize? /// The native scale factor for the screen. public let screenScale: CGFloat @@ -101,7 +107,6 @@ extension DeviceInfo { vendorIdentifier: UUID?, localeIdentifier: String, userInterfaceStyle: UserInterfaceStyle, - diskSpace: DiskSpaceInfo?, screenResolution: CGSize?, screenScale: CGFloat, deviceName: String, @@ -125,7 +130,6 @@ extension DeviceInfo { self.vendorIdentifier = vendorIdentifier self.localeIdentifier = localeIdentifier self.userInterfaceStyle = userInterfaceStyle - self.diskSpace = diskSpace self.screenResolution = screenResolution self.screenScale = screenScale self.deviceName = deviceName diff --git a/Sources/FingerprintJS/Harvesters/DataExchange/DiskSpaceInfo.swift b/Sources/FingerprintJS/Harvesters/DataExchange/DiskSpaceInfo.swift index c50e54a..97d12ac 100644 --- a/Sources/FingerprintJS/Harvesters/DataExchange/DiskSpaceInfo.swift +++ b/Sources/FingerprintJS/Harvesters/DataExchange/DiskSpaceInfo.swift @@ -1,3 +1,4 @@ +@available(*, deprecated, message: "DiskSpaceInfo will be removed in a future library version") public struct DiskSpaceInfo: Equatable, Encodable { public let freeDiskSpace: UInt64 public let totalDiskSpace: UInt64 diff --git a/Sources/FingerprintJS/Harvesters/HardwareInfoHarvester/HardwareInfoHarvester.swift b/Sources/FingerprintJS/Harvesters/HardwareInfoHarvester/HardwareInfoHarvester.swift index f9247e3..1f7b94e 100644 --- a/Sources/FingerprintJS/Harvesters/HardwareInfoHarvester/HardwareInfoHarvester.swift +++ b/Sources/FingerprintJS/Harvesters/HardwareInfoHarvester/HardwareInfoHarvester.swift @@ -20,15 +20,6 @@ protocol HardwareInfoHarvesting { /// The native scale factor for the display. var displayScale: CGFloat { get } - /// Free disk space on the device or 0 if a permission problem occurs - var freeDiskSpace: UInt64 { get } - - /// Total disk space on the device or 0 if a permission problem occurs - var totalDiskSpace: UInt64 { get } - - /// Disk space information (free and total) - var diskSpaceInfo: DiskSpaceInfo? { get } - /// Number of physical CPU cores var cpuCount: String { get } @@ -69,24 +60,6 @@ struct HardwareInfoHarvester { processInfo: ProcessInfo.processInfo ) } - - var diskSpaceInfo: DiskSpaceInfo? { - do { - let dict = try fileManager.documentsDirectoryAttributes() - if let fileSystemSizeInBytes = dict[.systemSize] as? UInt64, - let fileSystemFreeSizeInBytes = dict[.systemFreeSize] as? UInt64 - { - return DiskSpaceInfo( - freeDiskSpace: fileSystemFreeSizeInBytes, - totalDiskSpace: fileSystemSizeInBytes - ) - } - } catch { - print("Failed to obtain disk space info: \(error)") - } - - return nil - } } extension HardwareInfoHarvester: HardwareInfoHarvesting { @@ -136,14 +109,6 @@ extension HardwareInfoHarvester: HardwareInfoHarvesting { return "\(cpuFrequency)" } - var freeDiskSpace: UInt64 { - return diskSpaceInfo?.freeDiskSpace ?? 0 - } - - var totalDiskSpace: UInt64 { - return diskSpaceInfo?.totalDiskSpace ?? 0 - } - var kernelHostname: String { systemControl.hostname ?? "Undefined" } diff --git a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift index c387e7d..c383ae5 100644 --- a/Sources/FingerprintJS/Library/DeviceInfoProvider.swift +++ b/Sources/FingerprintJS/Library/DeviceInfoProvider.swift @@ -89,7 +89,6 @@ extension DeviceInfoProvider: DeviceInfoProviding { vendorIdentifier: identifierHarvester.vendorIdentifier, localeIdentifier: appInfoHarvester.localeIdentifier, userInterfaceStyle: appInfoHarvester.userInterfaceStyle, - diskSpace: hardwareInfoHarvester.diskSpaceInfo, screenResolution: hardwareInfoHarvester.displayResolution, screenScale: hardwareInfoHarvester.displayScale, deviceName: hardwareInfoHarvester.deviceName, @@ -121,7 +120,6 @@ extension DeviceInfoProvider: DeviceInfoProviding { vendorIdentifier: identifierHarvester.vendorIdentifier, localeIdentifier: appInfoHarvester.localeIdentifier, userInterfaceStyle: appInfoHarvester.userInterfaceStyle, - diskSpace: hardwareInfoHarvester.diskSpaceInfo, screenResolution: hardwareInfoHarvester.displayResolution, screenScale: hardwareInfoHarvester.displayScale, deviceName: hardwareInfoHarvester.deviceName, diff --git a/Tests/FingerprintJSTests/Harvesters/HardwareInfoHarvesterTests.swift b/Tests/FingerprintJSTests/Harvesters/HardwareInfoHarvesterTests.swift index 4afb6d5..d3f2c9e 100644 --- a/Tests/FingerprintJSTests/Harvesters/HardwareInfoHarvesterTests.swift +++ b/Tests/FingerprintJSTests/Harvesters/HardwareInfoHarvesterTests.swift @@ -94,84 +94,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { XCTAssertEqual(1, screenInfoProviderSpy.nativeScaleCallCount) } - func testFreeDiskSpaceReturnsZeroIfDocumentsDirAttributesEmpty() { - XCTAssertEqual(sut.freeDiskSpace, 0) - } - - func testFreeDiskSpaceReturnsZeroIfDocumentsAttributesThrowsError() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError = - DocumentsDirectoryError.documentsDirectoryNotFound - XCTAssertEqual(sut.freeDiskSpace, 0) - } - - func testFreeDiskSpaceReturnsZeroIfDocumentsAttributesPresentButThrowError() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemFreeSize: UInt64(100), - .systemSize: UInt64(100), - ] - - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError = - DocumentsDirectoryError.documentsDirectoryNotFound - - XCTAssertEqual(sut.freeDiskSpace, 0) - } - - func testFreeDiskSpaceReturnsCorrectValuesOnSuccess() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemFreeSize: UInt64(100), - .systemSize: UInt64(100), - ] - - XCTAssertEqual(sut.freeDiskSpace, 100) - } - - func testFreeDiskSpaceReturnsZeroIfOtherValueMissing() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemFreeSize: UInt64(100) - ] - - XCTAssertEqual(sut.freeDiskSpace, 0) - } - - func testTotalDiskSpaceReturnsZeroIfDocumentsDirAttributesEmpty() { - XCTAssertEqual(sut.totalDiskSpace, 0) - } - - func testTotalDiskSpaceReturnsZeroIfDocumentsAttributesThrowsError() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError = - DocumentsDirectoryError.documentsDirectoryNotFound - XCTAssertEqual(sut.totalDiskSpace, 0) - } - - func testTotalDiskSpaceReturnsZeroIfDocumentsAttributesPresentButThrowError() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemFreeSize: UInt64(100), - .systemSize: UInt64(100), - ] - - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributesError = - DocumentsDirectoryError.documentsDirectoryNotFound - - XCTAssertEqual(sut.totalDiskSpace, 0) - } - - func testTotalDiskSpaceReturnsCorrectValuesOnSuccess() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemFreeSize: UInt64(100), - .systemSize: UInt64(100), - ] - - XCTAssertEqual(sut.totalDiskSpace, 100) - } - - func testTotalDiskSpaceReturnZeroIfOneValueMissing() { - mockDocumentDirectoryAttributesProvider.mockDocumentsDirectoryAttributes = [ - .systemSize: UInt64(100) - ] - - XCTAssertEqual(sut.totalDiskSpace, 0) - } - func test_givenConfigurationWithVersionOneAndUniqueStabilityLevel_whenBuildTree_thenReturnsExpectedItems() { // given let config = Configuration(version: .v1, stabilityLevel: .unique) @@ -244,8 +166,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display resolution", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -265,8 +185,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display resolution", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -286,8 +204,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display resolution", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -309,8 +225,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -331,7 +245,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -352,7 +265,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -374,8 +286,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", "Device hostname", ] XCTAssertEqual(expectedItemLabels, itemLabels) @@ -397,7 +307,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -418,7 +327,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -440,8 +348,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Free disk space (B)", - "Total disk space (B)", "Device hostname", ] XCTAssertEqual(expectedItemLabels, itemLabels) @@ -463,7 +369,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) } @@ -484,7 +389,6 @@ final class HardwareInfoHarvesterTests: XCTestCase { "Display scale", "Physical memory", "Processor count", - "Total disk space (B)", ] XCTAssertEqual(expectedItemLabels, itemLabels) }