Merge commit 'eb59174efabb75701f24c148fd492e016770f190'

This commit is contained in:
Peter 2019-05-21 20:11:13 +02:00
commit 6de107d9c3
7 changed files with 33 additions and 20 deletions

View File

@ -39,7 +39,9 @@ public final class Database {
}
}
deinit { sqlite3_close(self.handle) } // sqlite3_close_v2 in Yosemite/iOS 8?
deinit {
sqlite3_close(self.handle)
} // sqlite3_close_v2 in Yosemite/iOS 8?
public func execute(_ SQL: String) -> Bool {
let res = sqlite3_exec(self.handle, SQL, nil, nil, nil)

View File

@ -443,7 +443,7 @@ public struct MessageForwardInfo: Equatable {
}
}
public protocol MessageAttribute: PostboxCoding {
public protocol MessageAttribute: class, PostboxCoding {
var associatedPeerIds: [PeerId] { get }
var associatedMessageIds: [MessageId] { get }
}

View File

@ -146,6 +146,10 @@ final class MessageHistoryIndexTable: Table {
operations.append(.Update(previousIndex, message))
case let .InsertMessage(insertMessage) where insertMessage.index == message.index:
break
case let .InsertExistingMessage(insertMessage) where insertMessage.index == message.index:
operations.removeAll()
operations.append(.Remove(index: previousIndex))
operations.append(.Update(insertMessage.index, message))
default:
operations.append(operation)
}

View File

@ -377,6 +377,21 @@ final class MutableMessageHistoryView {
}
case let .loaded(loadedState):
for operationSet in operations {
var addCount = 0
var removeCount = 0
for operation in operationSet {
switch operation {
case .InsertMessage:
addCount += 1
case .Remove:
removeCount += 1
default:
break
}
}
if addCount == 2 && removeCount == 2 {
assert(true)
}
for operation in operationSet {
switch operation {
case let .InsertMessage(message):

View File

@ -973,6 +973,7 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
subscriber.putNext(.upgrading(progress))
})
if let updatedPath = updatedPath {
valueBox.internalClose()
let _ = try? FileManager.default.removeItem(atPath: basePath + "/db")
let _ = try? FileManager.default.moveItem(atPath: updatedPath, toPath: basePath + "/db")
valueBox = SqliteValueBox(basePath: basePath + "/db", queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: { progress in

View File

@ -8,22 +8,9 @@ import SwiftSignalKit
func postboxUpgrade_21to22(queue: Queue, basePath: String, valueBox: ValueBox, encryptionParameters: ValueBoxEncryptionParameters, progress: (Float) -> Void) -> String? {
postboxLog("Upgrade 21->22 started")
if encryptionParameters.forceEncryptionIfNoSet {
let exportPath = "\(basePath)/version22"
let _ = try? FileManager.default.removeItem(atPath: exportPath)
valueBox.exportEncrypted(to: exportPath, encryptionParameters: encryptionParameters)
let updatedValueBox = SqliteValueBox(basePath: exportPath, queue: queue, encryptionParameters: encryptionParameters, upgradeProgress: progress)
let metadataTable = MetadataTable(valueBox: updatedValueBox, table: MetadataTable.tableSpec(0))
updatedValueBox.begin()
metadataTable.setUserVersion(22)
updatedValueBox.commit()
return exportPath
} else {
valueBox.begin()
let metadataTable = MetadataTable(valueBox: valueBox, table: MetadataTable.tableSpec(0))
metadataTable.setUserVersion(22)
valueBox.commit()
return nil
}
valueBox.begin()
let metadataTable = MetadataTable(valueBox: valueBox, table: MetadataTable.tableSpec(0))
metadataTable.setUserVersion(22)
valueBox.commit()
return nil
}

View File

@ -212,6 +212,10 @@ public final class SqliteValueBox: ValueBox {
checkpoints.dispose()
}
func internalClose() {
self.database = nil
}
private func openDatabase(encryptionParameters: ValueBoxEncryptionParameters?, upgradeProgress: (Float) -> Void) -> Database {
precondition(self.queue.isCurrent())