Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CareKitStore/CareKitStore/CoreData/OCKStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ public final class OCKStore: OCKStoreProtocol, Equatable {
if case .onDisk(let protection) = self.storeType {
let fileManager = FileManager()
let attributes: [FileAttributeKey: Any] = [
FileAttributeKey(kCFURLIsExcludedFromBackupKey as String): true,
FileAttributeKey.protectionKey: protection
]

Expand All @@ -296,6 +295,7 @@ public final class OCKStore: OCKStoreProtocol, Equatable {
descriptor.url = storeURL
descriptor.type = NSSQLiteStoreType
descriptor.shouldAddStoreAsynchronously = false
descriptor.setOption(storeType.securityClass as NSObject, forKey: NSPersistentStoreFileProtectionKey)
container.persistentStoreDescriptions = [descriptor]

// This closure runs synchronously because of the settings above
Expand All @@ -306,6 +306,20 @@ public final class OCKStore: OCKStoreProtocol, Equatable {
loadError = error
return
}

if case .onDisk = self.storeType {
do {
guard var storeUrl = descriptor.url else {
loadError = OCKStoreError.invalidValue(reason: "Bad URL")
return
}
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
try storeUrl.setResourceValues(resourceValues)
} catch {
loadError = error
}
}
})

if let error = loadError {
Expand Down