Skip to content
This repository was archived by the owner on Oct 6, 2023. It is now read-only.

Commit 1dab1f7

Browse files
committed
Reset CoreData if on old model (needs a better migration policy)
1 parent 23c2544 commit 1dab1f7

File tree

7 files changed

+181
-4
lines changed

7 files changed

+181
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="19197" systemVersion="21A5304g" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
3+
<entity name="Account" representedClassName="Account" syncable="YES" codeGenerationType="class">
4+
<attribute name="dateAdded" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
5+
<attribute name="domain" attributeType="String" defaultValueString=""/>
6+
<attribute name="isPinned" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
7+
<attribute name="lastModified" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
8+
<attribute name="notes" optional="YES" attributeType="String"/>
9+
<attribute name="otpAuth" optional="YES" attributeType="String"/>
10+
<attribute name="password" optional="YES" attributeType="Binary" defaultValueString="" allowsCloudEncryption="YES"/>
11+
<attribute name="passwordLength" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
12+
<attribute name="url" attributeType="String" defaultValueString=""/>
13+
<attribute name="username" attributeType="String" defaultValueString=""/>
14+
<relationship name="vault" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="Vault" inverseName="accounts" inverseEntity="Vault"/>
15+
</entity>
16+
<entity name="Vault" representedClassName="Vault" syncable="YES" codeGenerationType="class">
17+
<attribute name="name" attributeType="String" defaultValueString=""/>
18+
<relationship name="accounts" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Account" inverseName="vault" inverseEntity="Account"/>
19+
</entity>
20+
<elements>
21+
<element name="Account" positionX="-54" positionY="9" width="128" height="194"/>
22+
<element name="Vault" positionX="-63" positionY="-18" width="128" height="59"/>
23+
</elements>
24+
</model>

Shared/OpenSesame.xcdatamodeld/Shared.xcdatamodel/contents

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
<entity name="Account" representedClassName="Account" syncable="YES" codeGenerationType="class">
44
<attribute name="dateAdded" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
55
<attribute name="domain" attributeType="String" defaultValueString=""/>
6-
<attribute name="encryptionTag" attributeType="String" defaultValueString=""/>
76
<attribute name="isPinned" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
87
<attribute name="lastModified" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
9-
<attribute name="nonce" optional="YES" attributeType="String"/>
108
<attribute name="notes" optional="YES" attributeType="String"/>
119
<attribute name="otpAuth" optional="YES" attributeType="String"/>
1210
<attribute name="password" optional="YES" attributeType="Binary" defaultValueString="" allowsCloudEncryption="YES"/>
@@ -20,7 +18,7 @@
2018
<relationship name="accounts" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Account" inverseName="vault" inverseEntity="Account"/>
2119
</entity>
2220
<elements>
23-
<element name="Account" positionX="-54" positionY="9" width="128" height="224"/>
21+
<element name="Account" positionX="-54" positionY="9" width="128" height="194"/>
2422
<element name="Vault" positionX="-63" positionY="-18" width="128" height="59"/>
2523
</elements>
2624
</model>

Shared/OpenSesameMapping.xcmappingmodel/xcmapping.xml

Lines changed: 138 additions & 0 deletions
Large diffs are not rendered by default.

Shared/Persistence.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import CoreData
10+
import KeychainAccess
1011

1112
struct PersistenceController {
1213
static let shared = PersistenceController()
@@ -52,6 +53,16 @@ struct PersistenceController {
5253

5354
print("CoreData location", PersistenceController.storeURL.path)
5455
}
56+
57+
if let coreDataVersion = UserDefaults(suiteName: "group.OpenSesame.ethanlipnik")?.float(forKey: "coreDataVersion"), coreDataVersion < 1.1 {
58+
try? FileManager.default.removeItem(at: PersistenceController.storeURL)
59+
try? Keychain(service: "com.ethanlipnik.OpenSesame", accessGroup: "B6QG723P8Z.OpenSesame")
60+
.synchronizable(true)
61+
.remove("encryptionTest")
62+
63+
UserDefaults(suiteName: "group.OpenSesame.ethanlipnik")?.set(1.1, forKey: "coreDataVersion")
64+
}
65+
5566
let viewContext = container.viewContext
5667
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
5768
if let error = error as NSError? {

Shared/Views/ContentView/ContentView+List.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ extension ContentView {
5858
Section("Pinned") {
5959
ForEach(pinnedAccounts) { account in
6060
NavigationLink {
61-
VaultView(vault: account.vault!, selectedAccount: account)
61+
if let vault = account.vault {
62+
VaultView(vault: vault, selectedAccount: account)
63+
} else {
64+
Text("Failed to get vault for pinned account")
65+
}
6266
} label: {
6367
VStack(alignment: .leading) {
6468
Text(account.domain!.capitalizingFirstLetter())

Shared/Views/LockView/LockView+CreatePassword.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extension LockView {
1818
.font(.title.bold())
1919
GroupBox {
2020
TextField("Enter a new master password", text: $password, onCommit: {
21+
guard !password.isEmpty else { return }
2122
completionAction(password)
2223
})
2324
.font(.system(.body, design: .monospaced))
@@ -28,6 +29,7 @@ extension LockView {
2829
#endif
2930
}
3031
Button("Continue") {
32+
guard !password.isEmpty else { return }
3133
completionAction(password)
3234
}
3335
}

0 commit comments

Comments
 (0)