diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2020-10-30 09:11:47 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-02-24 14:28:01 +0100 |
| commit | 2c358d6023398f210823d6ea0d417cba5f68a61c (patch) | |
| tree | a7b5e14bb57f5e7214acd105cabcf5d13ce253fa | |
| parent | 2af7cd841c5090e09cea9df70afa88ce5f1c05ef (diff) | |
| download | mullvadvpn-2c358d6023398f210823d6ea0d417cba5f68a61c.tar.xz mullvadvpn-2c358d6023398f210823d6ea0d417cba5f68a61c.zip | |
Use withCString instead of utf8CString.map {}
| -rw-r--r-- | ios/MullvadVPN/Logging/TextFileOutputStream.swift | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/ios/MullvadVPN/Logging/TextFileOutputStream.swift b/ios/MullvadVPN/Logging/TextFileOutputStream.swift index 006e79a6e1..751f897b7d 100644 --- a/ios/MullvadVPN/Logging/TextFileOutputStream.swift +++ b/ios/MullvadVPN/Logging/TextFileOutputStream.swift @@ -34,15 +34,21 @@ class TextFileOutputStream: TextOutputStream { mode = filePermissions } - let filePath = fileURL.path.utf8CString.map { $0 } - guard let writer = DispatchIO(type: .stream, path: filePath, oflag: oflag, mode: mode, queue: queue, cleanupHandler: { (errno) in - if errno != 0 { - print("TextFileOutputStream: closed channel with error: \(errno)") - } - }) else { return nil } + let queue = self.queue + let writer = fileURL.path.withCString { (filePathPointer) -> DispatchIO? in + return DispatchIO(type: .stream, path: filePathPointer, oflag: oflag, mode: mode, queue: queue, cleanupHandler: { (errno) in + if errno != 0 { + print("TextFileOutputStream: closed channel with error: \(errno)") + } + }) + } - self.writer = writer - self.encoding = encoding + if let writer = writer { + self.writer = writer + self.encoding = encoding + } else { + return nil + } } deinit { |
