fix(apple): ensure log file exists before writing to it - #9597
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the log file exists before writing to it, thereby supporting proper log rollover after logs are cleared. Additionally, it reorders several import statements for consistency.
- Added logic to check and recreate the log file if it’s missing.
- Reordered SwiftUI (and related) imports in multiple files.
- Updated file system handling in Log.swift to support log rotation.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| swift/apple/FirezoneKit/Sources/FirezoneKit/Views/MenuBar.swift | Reordered SwiftUI import to maintain consistency. |
| swift/apple/FirezoneKit/Sources/FirezoneKit/Views/GrantVPNView.swift | Reordered SwiftUI import to maintain consistency. |
| swift/apple/FirezoneKit/Sources/FirezoneKit/Models/SessionNotification.swift | Reordered UserNotifications import with no functional change. |
| swift/apple/FirezoneKit/Sources/FirezoneKit/Helpers/Log.swift | Introduced file existence checks and log file recreation logic to support log rollover. |
| swift/apple/Firezone/Application/FirezoneApp.swift | Reordered SwiftUI import for consistency. |
| } | ||
|
|
||
| // File was deleted, need to recreate | ||
| try? handle.close() |
There was a problem hiding this comment.
Consider logging the error from closing the file handle instead of silently ignoring it with 'try?'. Explicit error handling can help diagnose potential issues during log file recreation.
| try? handle.close() | |
| do { | |
| try handle.close() | |
| } catch { | |
| logger.error("Could not close logfile during recreation: \(error)") | |
| } |
|
Tested on live device(s). |
| import OSLog | ||
| import SwiftUI | ||
| import Sentry | ||
| import SwiftUI |
There was a problem hiding this comment.
Where are these reformattings coming from?
There was a problem hiding this comment.
swift-format must have decided it wants to do things this way now. Probably a swift minor update.
| if self.ensureFileExists() { | ||
| self.handle.write(jsonData) | ||
| // Get valid handle, recreating file if necessary | ||
| if let handle = self.ensureFileExists() { |
There was a problem hiding this comment.
I think a guard would be very clean here.
Similar to the issue for the gui clients, the log file handle needs to be able to be rolled over after logs are cleared.
related: #6850