fix(ios): better handling of scoped vs non-scoped package URLs

This commit is contained in:
jahorton 2021-01-25 12:39:41 +07:00
parent 3cd23a5740
commit 54f3bd17ef

View file

@ -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)
}
}