From 3e68be406673d30f14cb8957f66835f0e9d786c0 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Sat, 17 Apr 2021 14:52:48 +0200 Subject: [PATCH 1/9] Update Package.swift --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index fd66ca9d..51492c81 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.3 // // Package.swift // CoreStore @@ -40,7 +40,7 @@ let package = Package( name: "CoreStore", dependencies: [], path: "Sources", - exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m"] + exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m", "ObjectPublisher+Rective.swift"] ), .testTarget( name: "CoreStoreTests", From 19df3218c3b68b643608f292fc85036a4dafd4e8 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Sat, 17 Apr 2021 15:06:01 +0200 Subject: [PATCH 2/9] Update Package.swift --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 51492c81..f3725810 100644 --- a/Package.swift +++ b/Package.swift @@ -40,7 +40,7 @@ let package = Package( name: "CoreStore", dependencies: [], path: "Sources", - exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m", "ObjectPublisher+Rective.swift"] + exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m", "ObjectPublisher+Reactive.swift"] ), .testTarget( name: "CoreStoreTests", From 619f2b75af20f07adc230abbf75cbeec08713e62 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Tue, 20 Apr 2021 00:31:46 +0200 Subject: [PATCH 3/9] introduce secure storage --- Sources/SQLiteStore.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index f8d2abcb..acb8a1e7 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -74,12 +74,13 @@ public final class SQLiteStore: LocalStorage { - Warning: The default SQLite file location for the `LegacySQLiteStore` and `SQLiteStore` are different. If the app was depending on CoreStore's default directories prior to 2.0.0, make sure to use the `SQLiteStore.legacy(...)` factory methods to create the `SQLiteStore` instead of using initializers directly. */ - public init() { + public init(secure: Bool = false) { self.fileURL = SQLiteStore.defaultFileURL self.configuration = nil self.migrationMappingProviders = [] self.localStorageOptions = nil + self.secure = secure } /** @@ -133,7 +134,8 @@ public final class SQLiteStore: LocalStorage { // MARK: StorageInterface - + private let secure: Bool = false + /** The string identifier for the `NSPersistentStore`'s `type` property. For `SQLiteStore`s, this is always set to `NSSQLiteStoreType`. */ @@ -217,6 +219,9 @@ public final class SQLiteStore: LocalStorage { var storeOptions = self.storeOptions ?? [:] storeOptions[NSSQLitePragmasOption] = ["journal_mode": "DELETE"] + if secure { + storeOptions[NSPersistentStoreFileProtectionKey] = FileProtectionType.complete + } try coordinator.addPersistentStore( ofType: Self.storeType, configurationName: self.configuration, @@ -242,7 +247,7 @@ public final class SQLiteStore: LocalStorage { do { let trashURL = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!) - .appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true) + .appendingPathComponent(BundlstoreOptionse.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true) .appendingPathComponent("trash", isDirectory: true) try fileManager.createDirectory( at: trashURL, From 0d3928c43d480a20382d2bbbbf2a8af7f06bd8a7 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Tue, 20 Apr 2021 00:35:26 +0200 Subject: [PATCH 4/9] Update SQLiteStore.swift --- Sources/SQLiteStore.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index acb8a1e7..2fc492cb 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -247,7 +247,7 @@ public final class SQLiteStore: LocalStorage { do { let trashURL = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!) - .appendingPathComponent(BundlstoreOptionse.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true) + .appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true) .appendingPathComponent("trash", isDirectory: true) try fileManager.createDirectory( at: trashURL, From 6eac8601fc3f5d5c6483fd97c8617ea3797d3b9d Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Tue, 20 Apr 2021 00:36:44 +0200 Subject: [PATCH 5/9] Update SQLiteStore.swift --- Sources/SQLiteStore.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index 2fc492cb..879e4092 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -134,7 +134,7 @@ public final class SQLiteStore: LocalStorage { // MARK: StorageInterface - private let secure: Bool = false + private var secure: Bool = false /** The string identifier for the `NSPersistentStore`'s `type` property. For `SQLiteStore`s, this is always set to `NSSQLiteStoreType`. From e7314eeaa417cbad908fd1820d2c21af14a6b955 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Thu, 29 Apr 2021 09:51:55 +0200 Subject: [PATCH 6/9] add infoplist to excluded to silent error on spm --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index f3725810..c9460916 100644 --- a/Package.swift +++ b/Package.swift @@ -40,7 +40,7 @@ let package = Package( name: "CoreStore", dependencies: [], path: "Sources", - exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m", "ObjectPublisher+Reactive.swift"] + exclude: ["CoreStoreBridge.h", "CoreStoreBridge.m", "ObjectPublisher+Reactive.swift", "Info.plist"] ), .testTarget( name: "CoreStoreTests", From 02156dbfab2fe39624a564e24a0b72f4963c5404 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Sat, 15 May 2021 22:35:23 +0200 Subject: [PATCH 7/9] avoid force cast --- Sources/From.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/From.swift b/Sources/From.swift index c12bbefb..84f7e61c 100644 --- a/Sources/From.swift +++ b/Sources/From.swift @@ -149,7 +149,8 @@ public struct From { ) throw CoreStoreError.unknown } - fetchRequest.entity = parentStack.entityDescription(for: Internals.EntityIdentifier(self.entityClass))! + guard let entity = parentStack.entityDescription(for: Internals.EntityIdentifier(self.entityClass)) else { return } + fetchRequest.entity = entity guard applyAffectedStores else { return From 5ab5fd20d477a8f9c1b41a63d5e2b1c34a2435d5 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Mon, 7 Jun 2021 14:36:08 +0200 Subject: [PATCH 8/9] remove force try! --- Sources/FieldCoders.Json.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FieldCoders.Json.swift b/Sources/FieldCoders.Json.swift index 8d05a5b7..520c2ee0 100644 --- a/Sources/FieldCoders.Json.swift +++ b/Sources/FieldCoders.Json.swift @@ -57,7 +57,7 @@ extension FieldCoders { return nil } - return try! JSONDecoder().decode([FieldStoredValue].self, from: data).first + return try? JSONDecoder().decode([FieldStoredValue].self, from: data).first } } } From cf636f26b964ae67812a5f3e7f784e16b68a04a8 Mon Sep 17 00:00:00 2001 From: Matteo Crippa Date: Mon, 7 Jun 2021 15:09:37 +0200 Subject: [PATCH 9/9] rollback --- Sources/FieldCoders.Json.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FieldCoders.Json.swift b/Sources/FieldCoders.Json.swift index 520c2ee0..8d05a5b7 100644 --- a/Sources/FieldCoders.Json.swift +++ b/Sources/FieldCoders.Json.swift @@ -57,7 +57,7 @@ extension FieldCoders { return nil } - return try? JSONDecoder().decode([FieldStoredValue].self, from: data).first + return try! JSONDecoder().decode([FieldStoredValue].self, from: data).first } } }