Skip to content

Commit

Permalink
Drop Configuration.fileAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Jan 20, 2017
1 parent cdf18b5 commit 519d447
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 308 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,17 @@
Release Notes
=============

## Next Release

**New**

- `DatabaseEventKind.tableName`

**Breaking Changes**

- `Configuration.fileAttributes` has been removed (see [Data Protection](https://github.com/groue/GRDB.swift#data-protection))


## 0.100.0

Released January 10, 2017
Expand Down
52 changes: 0 additions & 52 deletions GRDB.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions GRDB/Core/Configuration.swift
Expand Up @@ -49,23 +49,6 @@ public struct Configuration {
#endif


// MARK: - File Attributes

/// The file attributes that should be applied to the database files (see
/// `NSFileMnager.setAttributes(_,ofItemAtPath:)`).
///
/// SQLite will create [temporary files](https://www.sqlite.org/tempfiles.html)
/// when it needs them.
///
/// In WAL mode (see DatabasePool), SQLite will also eventually create
/// `-shm` and `-wal` files.
///
/// GRDB will apply file attributes to all those files.
///
/// Default: nil
public var fileAttributes: [FileAttributeKey: Any]? = nil


// MARK: - Transactions

/// The default kind of transaction.
Expand Down
6 changes: 1 addition & 5 deletions GRDB/Core/DatabasePool.swift
Expand Up @@ -41,9 +41,6 @@ public final class DatabasePool {
public init(path: String, configuration: Configuration = Configuration()) throws {
GRDBPrecondition(configuration.maximumReaderCount > 0, "configuration.maximumReaderCount must be at least 1")

// Database Store
store = try DatabaseStore(path: path, attributes: configuration.fileAttributes)

// Writer and readers share the same database schema cache
let sharedSchemaCache = SharedDatabaseSchemaCache()

Expand Down Expand Up @@ -116,7 +113,7 @@ public final class DatabasePool {

/// The path to the database.
public var path: String {
return store.path
return writer.path
}


Expand Down Expand Up @@ -212,7 +209,6 @@ public final class DatabasePool {

// MARK: - Not public

let store: DatabaseStore // Not private for tests that require syncing with the store
fileprivate let writer: SerializedDatabase
fileprivate var readerConfig: Configuration
fileprivate let readerPool: Pool<SerializedDatabase>
Expand Down
10 changes: 3 additions & 7 deletions GRDB/Core/DatabaseQueue.swift
Expand Up @@ -20,7 +20,6 @@ public final class DatabaseQueue {
/// - configuration: A configuration.
/// - throws: A DatabaseError whenever an SQLite error occurs.
public init(path: String, configuration: Configuration = Configuration()) throws {
store = try DatabaseStore(path: path, attributes: configuration.fileAttributes)
serializedDatabase = try SerializedDatabase(
path: path,
configuration: configuration,
Expand All @@ -35,7 +34,6 @@ public final class DatabaseQueue {
///
/// - parameter configuration: A configuration.
public init(configuration: Configuration = Configuration()) {
store = nil
// Assume SQLite always succeeds creating an in-memory database
serializedDatabase = try! SerializedDatabase(
path: ":memory:",
Expand All @@ -61,9 +59,9 @@ public final class DatabaseQueue {
return serializedDatabase.configuration
}

/// The path to the database file; nil for in-memory databases.
public var path: String! {
return store?.path
/// The path to the database file; it is ":memory:" for in-memory databases.
public var path: String {
return serializedDatabase.path
}


Expand Down Expand Up @@ -175,8 +173,6 @@ public final class DatabaseQueue {


// MARK: - Not public

private let store: DatabaseStore?

// https://www.sqlite.org/isolation.html
//
Expand Down
87 changes: 0 additions & 87 deletions GRDB/Core/DatabaseStore.swift

This file was deleted.

4 changes: 4 additions & 0 deletions GRDB/Core/SerializedDatabase.swift
Expand Up @@ -10,6 +10,9 @@ final class SerializedDatabase {
return db.configuration
}

/// The path to the database file
var path: String

/// The dispatch queue
private let queue: DispatchQueue

Expand All @@ -36,6 +39,7 @@ final class SerializedDatabase {

db = try Database(path: path, configuration: config, schemaCache: schemaCache)
queue = SchedulingWatchdog.makeSerializedQueue(allowingDatabase: db)
self.path = path
try queue.sync {
try db.setup()
}
Expand Down
11 changes: 8 additions & 3 deletions README.md
Expand Up @@ -214,6 +214,7 @@ Documentation
- [Error Handling](#error-handling)
- [Unicode](#unicode)
- [Memory Management](#memory-management)
- [Data Protection](#data-protection)
- [Concurrency](#concurrency)
- [Performance](#performance)

Expand Down Expand Up @@ -356,7 +357,6 @@ var config = Configuration()
config.readonly = true
config.foreignKeysEnabled = true // Default is already true
config.trace = { print($0) } // Prints all SQL statements
config.fileAttributes = [FileAttributeKey.protectionKey.rawValue: ...] // Configure database protection

let dbQueue = try DatabaseQueue(
path: "/path/to/database.sqlite",
Expand Down Expand Up @@ -433,7 +433,6 @@ var config = Configuration()
config.readonly = true
config.foreignKeysEnabled = true // Default is already true
config.trace = { print($0) } // Prints all SQL statements
config.fileAttributes = [FileAttributeKey.protectionKey.rawValue: ...] // Configure database protection
config.maximumReaderCount = 10 // The default is 5

let dbPool = try DatabasePool(
Expand Down Expand Up @@ -4609,6 +4608,7 @@ This chapter covers general topics that you should be aware of.
- [Error Handling](#error-handling)
- [Unicode](#unicode)
- [Memory Management](#memory-management)
- [Data Protection](#data-protection)
- [Concurrency](#concurrency)
- [Performance](#performance)

Expand Down Expand Up @@ -4926,6 +4926,11 @@ dbQueue.setupMemoryManagement(in: UIApplication.sharedApplication())
```


## Data Protection

TODO [data protection](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforImplementingYourApp/StrategiesforImplementingYourApp.html#//apple_ref/doc/uid/TP40007072-CH5-SW21) FileAttributeKey.protectionKey


## Concurrency

- [Guarantees and Rules](#guarantees-and-rules)
Expand Down Expand Up @@ -5481,7 +5486,7 @@ var persistentDictionary: [String: DatabaseValueConvertible?] {

### SQLite error 10 "disk I/O error", SQLite error 23 "not authorized"

Those errors may be the sign that SQLite can't access the database due to [data protection](https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforImplementingYourApp/StrategiesforImplementingYourApp.html#//apple_ref/doc/uid/TP40007072-CH5-SW21).
Those errors may be the sign that SQLite can't access the database due to [data protection](#data-protection).

When your application should be able to run in the background on a locked device, it has to catch this error, and, for example, wait for [UIApplicationDelegate.applicationProtectedDataDidBecomeAvailable(_:)](https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623044-applicationprotecteddatadidbecom) or [UIApplicationProtectedDataDidBecomeAvailable](https://developer.apple.com/reference/uikit/uiapplicationprotecteddatadidbecomeavailable) notification and retry the failed database operation.

Expand Down
1 change: 0 additions & 1 deletion TODO.md
@@ -1,4 +1,3 @@
- [ ] Drop DatabaseStore and support for FileProtectionKey if it can be confirmed that file inherit protection from their directory (see http://stackoverflow.com/questions/26033127/why-doesnt-nsfileprotectionkey-attribute-when-a-device-is-jailbroken)
- [ ] Check for SQLCipher at runtime with `PRAGMA cipher_version`: https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688
- [ ] We share the database cache between database pool writers and readers. But what if a writer modifies the database schema within a transaction, and a concurrent reader reads the cache? Bad things, isn't it? Write failing tests first, and fix the bug.
- [ ] FetchedRecordsController is not reactive:
Expand Down

This file was deleted.

0 comments on commit 519d447

Please sign in to comment.