Skip to content

Commit 8b0b530

Browse files
committed
No needs to backup shm and wal
1 parent ae05c7d commit 8b0b530

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

Mixin/Service/Job/DatabaseBackupJob.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Foundation
22
import MixinServices
3-
import GRDB
43

54
class DatabaseBackupJob: AsynchronousJob {
65

@@ -14,13 +13,13 @@ class DatabaseBackupJob: AsynchronousJob {
1413
try DatabaseFile.removeIfExists(.temp)
1514
try DatabaseFile.copy(at: .original, to: .temp)
1615
}
17-
let dbQueue = try DatabaseQueue(path: DatabaseFile.temp.db.path)
18-
try dbQueue.write { db in
19-
try db.execute(sql: "PRAGMA integrity_check")
20-
}
16+
17+
try DatabaseFile.checkIntegrity(.temp)
18+
2119
try DatabaseFile.removeIfExists(.backup)
2220
try DatabaseFile.copy(at: .temp, to: .backup)
2321
try DatabaseFile.removeIfExists(.temp)
22+
2423
AppGroupUserDefaults.User.lastDatabaseBackupDate = Date()
2524
finishJob()
2625
} catch {

Mixin/UserInterface/Controllers/Home/Model/DatabaseFile.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import MixinServices
3+
import GRDB
34

45
enum DatabaseFile {
56

@@ -18,15 +19,15 @@ enum DatabaseFile {
1819
}
1920
}
2021

21-
var db: URL {
22+
private var db: URL {
2223
AppGroupContainer.accountUrl.appendingPathComponent("\(name)", isDirectory: false)
2324
}
2425

25-
var shm: URL {
26+
private var shm: URL {
2627
AppGroupContainer.accountUrl.appendingPathComponent("\(name)-shm", isDirectory: false)
2728
}
2829

29-
var wal: URL {
30+
private var wal: URL {
3031
AppGroupContainer.accountUrl.appendingPathComponent("\(name)-wal", isDirectory: false)
3132
}
3233

@@ -44,14 +45,17 @@ enum DatabaseFile {
4445

4546
static func copy(at srcFile: DatabaseFile, to dstFile: DatabaseFile) throws {
4647
try FileManager.default.copyItem(at: srcFile.db, to: dstFile.db)
47-
try FileManager.default.copyItem(at: srcFile.wal, to: dstFile.wal)
48-
try FileManager.default.copyItem(at: srcFile.shm, to: dstFile.shm)
4948
}
5049

5150
static func exists(_ file: DatabaseFile) -> Bool {
52-
FileManager.default.fileExists(atPath: file.db.path) &&
53-
FileManager.default.fileExists(atPath: file.wal.path) &&
54-
FileManager.default.fileExists(atPath: file.shm.path)
51+
FileManager.default.fileExists(atPath: file.db.path)
52+
}
53+
54+
static func checkIntegrity(_ file: DatabaseFile) throws {
55+
let dbQueue = try DatabaseQueue(path: file.db.path)
56+
try dbQueue.write { db in
57+
try db.execute(sql: "PRAGMA integrity_check")
58+
}
5559
}
5660

5761
}

0 commit comments

Comments
 (0)