From 3036c85775d226415a362bf906dff68db3232d8f Mon Sep 17 00:00:00 2001 From: QUEAU Jean Pierre Date: Fri, 14 Jun 2024 12:00:14 +0200 Subject: [PATCH] fix issue#565 --- CHANGELOG.md | 13 ++++++++++++- ios/Plugin/Utils/UtilsDownloadFromHTTP.swift | 16 +++++++++------- ios/Plugin/Utils/UtilsFile.swift | 13 ++++++++----- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2edd312..e9b9a07c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ -# 6.0.0 (2024-06-12) +# 6.0.1 (2024-06-14) + +### Bug Fixes + - Fix For-in loop requires 'Archive?' to conform to 'Sequence'; did you mean to unwrap optional? issue565 + +# 6.0.0 (2024-06-12) # 6.0.0-beta.2 (2024-06-12) @@ -23,6 +28,12 @@ - Add the fixes of 5.7.3 +# 5.7.4 (2024-06-14) + +### Bug Fixes + + - Fix For-in loop requires 'Archive?' to conform to 'Sequence'; did you mean to unwrap optional? issue565 + # 5.7.3 (2024-06-09) ### Bug Fixes diff --git a/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift b/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift index 3f746916..4c9d3bf5 100644 --- a/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +++ b/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift @@ -158,14 +158,17 @@ class UtilsDownloadFromHTTP { } class func extractDBFiles(from zipFile: URL, completion: @escaping ([URL], Error?) -> Void) { - DispatchQueue.global().async { + DispatchQueue.global().async(execute: { var dbFiles: [URL] = [] do { let destinationURL = zipFile.deletingLastPathComponent() - // Use the throwing initializer - let archive = try Archive(url: zipFile, accessMode: .read) + guard let archive = Archive(url: zipFile, accessMode: .read) else { + let msg = "Failed in reading Archive" + completion([], UtilsDownloadError.invalidArchive(message: msg)) + return + } for entry in archive where entry.type == .file { let fileURL = destinationURL.appendingPathComponent(entry.path) @@ -176,15 +179,14 @@ class UtilsDownloadFromHTTP { dbFiles.append(fileURL) } } - // Delete the zip file try FileManager.default.removeItem(at: zipFile) completion(dbFiles, nil) } catch { - let msg = "Failed in reading Archive: \(error.localizedDescription)" - completion([], UtilsDownloadError.invalidArchive(message: msg)) + completion([], error) } - } + }) + } } diff --git a/ios/Plugin/Utils/UtilsFile.swift b/ios/Plugin/Utils/UtilsFile.swift index 86a2dab3..9545c428 100644 --- a/ios/Plugin/Utils/UtilsFile.swift +++ b/ios/Plugin/Utils/UtilsFile.swift @@ -421,13 +421,15 @@ class UtilsFile { } - class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String, overwrite: Bool) throws { + class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String, + overwrite: Bool) throws { do { let zipAsset: URL = fromURL.appendingPathComponent(zip) - - // Use the throwing initializer - let archive = try Archive(url: zipAsset, accessMode: .read) - + guard let archive = Archive(url: zipAsset, accessMode: .read) else { + let msg = "Error: Read Archive: \(zipAsset) failed" + print("\(msg)") + throw UtilsFileError.unzipToDatabaseFailed(message: msg) + } let uDb: URL = try getFolderURL(folderPath: databaseLocation) for entry in archive { let dbEntry = setPathSuffix(sDb: entry.path) @@ -440,6 +442,7 @@ class UtilsFile { } _ = try archive.extract(entry, to: zipCopy) } + } catch { let msg = "Error: Extracting \(entry.path) from archive failed \(error.localizedDescription)" print("\(msg)")