@@ -126,22 +126,39 @@ extension ExploreDatabaseSyncManager {
126126 self ? . syncState = . error( date, e)
127127 } else {
128128 try ? data? . write ( to: urlToSave)
129- self ? . exploreDatabaseLastSyncTimestamp = now
130- self ? . exploreDatabaseLastVersion = timeIntervalMillesecond / 1000
131- self ? . syncState = . synced( date)
132- self ? . unzipFile ( at: urlToSave. path, password: checksum)
129+
130+ Task {
131+ do {
132+ try await self ? . unzipFile ( at: urlToSave. path, password: checksum)
133+ self ? . exploreDatabaseLastSyncTimestamp = now
134+ self ? . exploreDatabaseLastVersion = timeIntervalMillesecond / 1000
135+ self ? . syncState = . synced( date)
136+
137+ NotificationCenter . default. post ( name: ExploreDatabaseSyncManager . databaseHasBeenUpdatedNotification, object: nil )
138+ try ? FileManager . default. removeItem ( at: URL ( fileURLWithPath: urlToSave. path) )
139+ } catch {
140+ DSLogger . log ( " ExploreDash: failed to open DB archive: \( String ( describing: error) ) " )
141+ self ? . syncState = . error( Date ( ) , error)
142+ }
143+ }
133144 }
134145 }
135146 }
136147
137- private func unzipFile( at path: String , password: String ) {
138- var error : NSError ?
148+ private func unzipFile( at path: String , password: String ) async throws {
139149 let urlToUnzip = self . getDocumentsDirectory ( )
140- SSZipArchive . unzipFile ( atPath: path, toDestination: urlToUnzip. path, preserveAttributes: true , overwrite: true ,
141- nestedZipLevel: 0 , password: password, error: & error, delegate: nil ,
142- progressHandler: nil ) { path, _, _ in
143- NotificationCenter . default. post ( name: ExploreDatabaseSyncManager . databaseHasBeenUpdatedNotification, object: nil )
144- try ? FileManager . default. removeItem ( at: URL ( fileURLWithPath: path) )
150+
151+ return try await withCheckedThrowingContinuation { continuation in
152+ SSZipArchive . unzipFile ( atPath: path, toDestination: urlToUnzip. path, preserveAttributes: true , overwrite: true ,
153+ nestedZipLevel: 0 , password: password, error: nil , delegate: nil ,
154+ progressHandler: nil ) { path, success, error in
155+ if success {
156+ continuation. resume ( )
157+ } else {
158+ let errorToThrow = error ?? NSError ( domain: " ExploreDatabaseSyncManager " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " Failed to unzip archive " ] )
159+ continuation. resume ( throwing: errorToThrow)
160+ }
161+ }
145162 }
146163 }
147164
0 commit comments