]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Settings: Add timestamp to exported log
authorRoopesh Chander <roop@roopc.net>
Tue, 4 Dec 2018 08:20:43 +0000 (13:50 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 4 Dec 2018 08:42:53 +0000 (14:12 +0530)
And remove the exported log afterwards.

Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift

index 994eb222fe4102f54a5ec9df3121db89d12b71b4..6f8410eda055b2dc9382faa69d0b3ea11d1a676d 100644 (file)
@@ -96,7 +96,10 @@ class SettingsTableViewController: UITableViewController {
             return
         }
 
-        let destinationURL = destinationDir.appendingPathComponent("WireGuard_iOS_log.txt")
+        let dateFormatter = ISO8601DateFormatter()
+        dateFormatter.formatOptions = [.withFullDate, .withTime, .withTimeZone] // Avoid ':' in the filename
+        let timeStampString = dateFormatter.string(from: Date())
+        let destinationURL = destinationDir.appendingPathComponent("WireGuard_iOS_log_\(timeStampString).txt")
 
         if (FileManager.default.fileExists(atPath: destinationURL.path)) {
             do {
@@ -126,6 +129,10 @@ class SettingsTableViewController: UITableViewController {
         // popoverPresentationController shall be non-nil on the iPad
         activityVC.popoverPresentationController?.sourceView = sourceView
         activityVC.popoverPresentationController?.sourceRect = sourceView.bounds
+        activityVC.completionWithItemsHandler = { (_, _, _, _) in
+            // Remove the exported log file after the activity has completed
+            try? FileManager.default.removeItem(at: destinationURL)
+        }
         self.present(activityVC, animated: true)
     }