From eb8f27b457e45c843c5e55a64640882afb7e595a Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Mon, 20 Sep 2021 09:48:31 +0800 Subject: [PATCH] Removes files if unzip is not successful --- iOS/SceneDelegate.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iOS/SceneDelegate.swift b/iOS/SceneDelegate.swift index 6658c3e55..54fc4dcc3 100644 --- a/iOS/SceneDelegate.swift +++ b/iOS/SceneDelegate.swift @@ -230,9 +230,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { private func unzipFile(at location: URL) throws -> URL { var unzippedDir = location.deletingLastPathComponent() unzippedDir.appendPathComponent("newtheme.nnwtheme") - try Zip.unzipFile(location, destination: unzippedDir, overwrite: true, password: nil, progress: nil, fileOutputHandler: nil) - try FileManager.default.removeItem(at: location) - return unzippedDir + do { + try Zip.unzipFile(location, destination: unzippedDir, overwrite: true, password: nil, progress: nil, fileOutputHandler: nil) + try FileManager.default.removeItem(at: location) + return unzippedDir + } catch { + try? FileManager.default.removeItem(at: location) + throw error + } } private func renameFileToThemeName(at location: URL) throws -> URL {