summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-09-23 15:32:05 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-09-26 13:44:09 +0200
commit324556c1ef5ff6aca3ed331b71de0a30b0567032 (patch)
tree4028c8d42bd18f73c61f55f36a9f2a267dcd8249 /ios
parentd52fbbdc6f8a3626d2a222543ac51fd07634179a (diff)
downloadmullvadvpn-324556c1ef5ff6aca3ed331b71de0a30b0567032.tar.xz
mullvadvpn-324556c1ef5ff6aca3ed331b71de0a30b0567032.zip
LogRotation: use underlyingErrorChain instead of custom iterator
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/Logging/LogRotation.swift16
1 files changed, 2 insertions, 14 deletions
diff --git a/ios/MullvadVPN/Logging/LogRotation.swift b/ios/MullvadVPN/Logging/LogRotation.swift
index 4775315b77..a4c3be01f5 100644
--- a/ios/MullvadVPN/Logging/LogRotation.swift
+++ b/ios/MullvadVPN/Logging/LogRotation.swift
@@ -33,27 +33,15 @@ enum LogRotation {
}
static func rotateLog(logsDirectory: URL, logFileName: String) throws {
- let fileManager = FileManager.default
let source = logsDirectory.appendingPathComponent(logFileName)
let backup = source.deletingPathExtension().appendingPathExtension("old.log")
do {
- _ = try fileManager.replaceItemAt(backup, withItemAt: source)
+ _ = try FileManager.default.replaceItemAt(backup, withItemAt: source)
} catch {
// FileManager returns a very obscure error chain so we need to traverse it to find
// the root cause of the error.
- var errorCursor: Swift.Error? = error
- let cocoaErrorIterator = AnyIterator { () -> CocoaError? in
- if let cocoaError = errorCursor as? CocoaError {
- errorCursor = cocoaError.underlying
- return cocoaError
- } else {
- errorCursor = nil
- return nil
- }
- }
-
- while let fileError = cocoaErrorIterator.next() {
+ for case let fileError as CocoaError in error.underlyingErrorChain {
// .fileNoSuchFile is returned when both backup and source log files do not exist
// .fileReadNoSuchFile is returned when backup exists but source log file does not
if fileError.code == .fileNoSuchFile || fileError.code == .fileReadNoSuchFile,