aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-05 15:23:55 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-07 12:36:19 +0530
commitf6faffa4c1e0c11b7e2756d18d747dde43add529 (patch)
tree89dd0fadd08b20b09cc0769b9fef57ad684e2ba8 /WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
parentNE: Logging: Log file should begin with version numbers and tunnel name (diff)
downloadwireguard-apple-f6faffa4c1e0c11b7e2756d18d747dde43add529.tar.xz
wireguard-apple-f6faffa4c1e0c11b7e2756d18d747dde43add529.zip
Refactoring: Consolidate file deletion into a separate function
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift15
1 files changed, 5 insertions, 10 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
index 6f8410e..7beb2e9 100644
--- a/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
@@ -69,12 +69,9 @@ class SettingsTableViewController: UITableViewController {
guard let destinationDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {
return
}
+
let destinationURL = destinationDir.appendingPathComponent("wireguard-export.zip")
- do {
- try FileManager.default.removeItem(at: destinationURL)
- } catch {
- os_log("Failed to delete file: %{public}@ : %{public}@", log: OSLog.default, type: .error, destinationURL.absoluteString, error.localizedDescription)
- }
+ _ = FileManager.deleteFile(at: destinationURL)
let count = tunnelsManager.numberOfTunnels()
let tunnelConfigurations = (0 ..< count).compactMap { tunnelsManager.tunnel(at: $0).tunnelConfiguration() }
@@ -102,10 +99,8 @@ class SettingsTableViewController: UITableViewController {
let destinationURL = destinationDir.appendingPathComponent("WireGuard_iOS_log_\(timeStampString).txt")
if (FileManager.default.fileExists(atPath: destinationURL.path)) {
- do {
- try FileManager.default.removeItem(at: destinationURL)
- } catch {
- os_log("Failed to delete file: %{public}@ : %{public}@", log: OSLog.default, type: .error, destinationURL.absoluteString, error.localizedDescription)
+ let isDeleted = FileManager.deleteFile(at: destinationURL)
+ if (!isDeleted) {
showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared")
return
}
@@ -131,7 +126,7 @@ class SettingsTableViewController: UITableViewController {
activityVC.popoverPresentationController?.sourceRect = sourceView.bounds
activityVC.completionWithItemsHandler = { (_, _, _, _) in
// Remove the exported log file after the activity has completed
- try? FileManager.default.removeItem(at: destinationURL)
+ _ = FileManager.deleteFile(at: destinationURL)
}
self.present(activityVC, animated: true)
}