File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed
UserInterface/Controllers/Home/Model Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 11import Foundation
22import MixinServices
3- import GRDB
43
54class 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 {
Original file line number Diff line number Diff line change 11import Foundation
22import MixinServices
3+ import GRDB
34
45enum 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}
You can’t perform that action at this time.
0 commit comments