From 54f3bd17ef981dffd5b39b00a8bd9b725a2347c8 Mon Sep 17 00:00:00 2001 From: jahorton Date: Mon, 25 Jan 2021 12:39:41 +0700 Subject: [PATCH] fix(ios): better handling of scoped vs non-scoped package URLs --- .../Resource Management/ResourceFileManager.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceFileManager.swift b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceFileManager.swift index c14c161c2f..ab84bbc9a6 100644 --- a/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceFileManager.swift +++ b/ios/engine/KMEI/KeymanEngine/Classes/Resource Management/ResourceFileManager.swift @@ -92,15 +92,16 @@ public class ResourceFileManager { try fileManager.removeItem(at: destination) } - // Throws an error if the destination file already exists, and there's no - // built-in override parameter. Hence, the previous if-block. - if source.startAccessingSecurityScopedResource() { - defer { source.stopAccessingSecurityScopedResource() } // The Swift version of 'finally'. + // If we've been provided a security-scoped resource URL, + // it needs special handling. This function needs to accept + // both scoped & non-scoped URLs. + if source.startAccessingSecurityScopedResource() { // only succeeds if scoped + // The Swift version of 'finally'. + defer { source.stopAccessingSecurityScopedResource() } try fileManager.copyItem(at: source, to: destination) } else { - // We _could_ get more specific, as it's due to issues with security-scoped resources... - // but this ought be fine for now. - throw KMPError.copyFiles + // Not scoped? No problem! + try fileManager.copyItem(at: source, to: destination) } }