Skip to content

Commit

Permalink
Fix issue#565
Browse files Browse the repository at this point in the history
  • Loading branch information
jepiqueau committed Jun 14, 2024
1 parent 6f50de2 commit 0dcd585
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 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

- Fix TypeError: Cannot read properties of undefined (reading 'lastId') issue#558
- Fix exportToJson generate unusable export for table created with separate UNIQUE syntax. issue#561
- Fix Multi Row Statement does not suppress control characters ($) issue#562

# 5.7.3-3 (2024-04-28)

### Bug Fixes
Expand Down
18 changes: 10 additions & 8 deletions ios/Plugin/Utils/UtilsDownloadFromHTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ class UtilsDownloadFromHTTP {
}
}

class func extractDBFiles(from zipFile: URL, completion: @escaping ([URL], Error?) -> Void) {
DispatchQueue.global().async {
class func extractDBFiles(from zipFile: URL, completion: @escaping ([URL], Error?) -> Void) {
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)
Expand All @@ -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)
}
}
})

}
}
13 changes: 8 additions & 5 deletions ios/Plugin/Utils/UtilsFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)")
Expand Down

0 comments on commit 0dcd585

Please sign in to comment.