fix(tvOS): use writable local paths for prefs, auth config, and Go state - #191
fix(tvOS): use writable local paths for prefs, auth config, and Go state#191CicerBro wants to merge 4 commits into
Conversation
App-group UserDefaults are non-functional on tvOS, so shared preferences and the cached device name silently failed. Prefer UserDefaults.standard and a writable Caches fallback in DEBUG.
NetBirdSDKNewAuth creates or updates netbird.cfg at the given path before the SSO check runs. On tvOS the path came from the App Group container, which is not writable, so changing the management server failed with EPERM before the UserDefaults fallbacks could run. Point configFile() at the caches directory on tvOS instead, mirroring the stateFile() treatment — persistence on tvOS goes through UserDefaults and IPC, not this file.
Empty state paths made the state manager write temp files into the extension CWD, which is read-only and failed with EPERM every 10s.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughtvOS storage now uses writable Caches or temporary directories, with standard process-local defaults. Device-name persistence uses the shared defaults. Network extension initialization validates and passes the resolved state path to the SDK. ChangestvOS storage and device persistence
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant NetBirdAdapter
participant Preferences
participant UserDefaults
participant NetBirdSDKNewClient
NetBirdAdapter->>Preferences: request stateFile()
Preferences-->>NetBirdAdapter: return writable state path
NetBirdAdapter->>NetBirdSDKNewClient: initialize with state path
Preferences->>UserDefaults: use standard defaults for tvOS
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes tvOS-specific sandbox/path issues by switching preference storage and SDK file paths away from App Group locations that are not usable on tvOS, ensuring config/auth setup and Go state persistence have writable locations.
Changes:
- Pass a writable state path into
NetBirdSDKNewClienton tvOS to prevent Go state persistence failures. - Adjust
Preferencesto use tvOS-appropriateUserDefaultsand to place config/state files in writable locations. - Update tvOS device-name caching to use the shared defaults abstraction.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| NetbirdNetworkExtension/NetBirdAdapter.swift | Passes a state path into the tvOS SDK client initialization to avoid EPERM persistence errors. |
| NetbirdKit/Preferences.swift | Updates tvOS defaults handling and redirects config/state paths to writable directories. |
| NetbirdKit/Device.swift | Uses Preferences.sharedUserDefaults() for tvOS device-name persistence. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What this fixes
Several tvOS failures share one root cause: App Group containers and related default paths are not usable the way they are on iOS.
UserDefaultsdo not work on tvOS (cfprefsddetaches), so shared prefs and the cached device name silently read as nil. DEBUG fallbacks under Application Support also fail because that directory is read-only in the sandbox.NetBirdSDKNewAuthcreates/updatesnetbird.cfgat the given path before SSO. That path came from the App Group container, so changing the management server failed withEPERMbefore UserDefaults/IPC fallbacks ran.EPERMerrors about every 10 seconds.Change
UserDefaults.standardon tvOS and writable Caches for DEBUG file-path fallbacks.configFile()at caches as scratch space for NewAuth (persistence stays UserDefaults + IPC).stateFile()at caches and pass it intoNetBirdSDKNewClientso the Go state manager has a writable location.Summary by CodeRabbit