mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-08 01:45:32 +00:00
feat(ios/engine): temp package cleanup
This commit is contained in:
parent
bfd90f3280
commit
9bc385b8a4
4 changed files with 28 additions and 6 deletions
|
|
@ -26,6 +26,8 @@ public class KeymanPackage {
|
|||
public let sourceFolder: URL
|
||||
public let id: String
|
||||
internal let metadata: KMPMetadata
|
||||
|
||||
// Used to denote Packages pending installation; referenced by ResourceFileManager.
|
||||
internal let isTemp: Bool
|
||||
|
||||
internal init(metadata: KMPMetadata, folder: URL) {
|
||||
|
|
|
|||
|
|
@ -518,12 +518,7 @@ public enum Migrations {
|
|||
|
||||
allLocalPackages = kmpFiles.compactMap { file in
|
||||
let filePath = cachedKMPsDirectory.appendingPathComponent(file)
|
||||
do {
|
||||
return try ResourceFileManager.shared.prepareKMPInstall(from: filePath)
|
||||
} catch {
|
||||
log.error("Error occurred when processing existing packages during cloud -> KMP migration: \(String(describing: error))")
|
||||
return nil as KeymanPackage?
|
||||
}
|
||||
return ResourceFileManager.shared.getPackageInfo(for: filePath)
|
||||
}
|
||||
} catch {
|
||||
log.error("Could not check contents of Documents directory for resource-migration assist")
|
||||
|
|
|
|||
|
|
@ -55,6 +55,14 @@ public class PackageInstallViewController: UIViewController {
|
|||
|
||||
@objc func cancelBtnHandler() {
|
||||
dismiss(animated: true, completion: nil)
|
||||
// Note: package.sourceFolder is a temporary directory, as set by preparePackageInstall.
|
||||
do {
|
||||
try FileManager.default.removeItem(at: package.sourceFolder)
|
||||
} catch {
|
||||
// Our attempt to clean up the temporarily-extracted contents failed.
|
||||
// At least we extracted to a temp (cache) folder; we'll let iOS
|
||||
// handle it, then.
|
||||
}
|
||||
}
|
||||
|
||||
@objc func installBtnHandler() {
|
||||
|
|
|
|||
|
|
@ -138,6 +138,23 @@ public class ResourceFileManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to `preparePackageInstall`, but the resuting `KeymanPackage` cannot be used for installation. Use when you
|
||||
* want information about a package's contents when not immediately looking to install its resources.
|
||||
*/
|
||||
public func getPackageInfo(for url: URL) -> KeymanPackage? {
|
||||
// Facilitates clean retrieval of a package's metadata by temporarily extracting
|
||||
// its contents just long enough to parse the kmp.json.
|
||||
do {
|
||||
let package = try self.prepareKMPInstall(from: url)
|
||||
try FileManager.default.removeItem(at: package.sourceFolder)
|
||||
return package
|
||||
} catch {
|
||||
log.error("Error occurred attempting to extract metadata for KMP at \(String(describing: url)): \(String(describing: error))")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public func promptPackageInstall(of package: KeymanPackage,
|
||||
in rootVC: UIViewController,
|
||||
isCustom: Bool,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue