fix(apple): don't return Data() to fetchResources (#10605)

When the tunnel first comes up, the first call to `fetchResources` was
returning an empty `Data()` instance that the receiver would fail to
decode properly because it assumes if a `Data` is non-nil, it is a list
of Resources.

This resulted in a decode error each time the tunnel was started.

Related:
https://github.com/firezone/firezone/pull/10603#discussion_r2438472011

---------

Signed-off-by: Jamil <jamilbk@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Jamil
2025-10-17 08:50:44 -07:00
committed by GitHub
parent 73576922ff
commit fbade40e66

View File

@@ -297,24 +297,22 @@ class Adapter: @unchecked Sendable {
guard let self = self else { return }
// Convert uniffi resources to FirezoneKit resources and encode with PropertyList
let propertyListData: Data
if let uniffiResources = self.resources {
let firezoneResources = uniffiResources.map { self.convertResource($0) }
guard let encoded = try? PropertyListEncoder().encode(firezoneResources) else {
Log.log("Failed to encode resources as PropertyList")
completionHandler(nil)
return
}
propertyListData = encoded
} else {
propertyListData = Data()
guard let uniffiResources = self.resources
else { return completionHandler(nil) }
let firezoneResources = uniffiResources.map { self.convertResource($0) }
guard let encoded = try? PropertyListEncoder().encode(firezoneResources)
else {
Log.log("Failed to encode resources as PropertyList")
return completionHandler(nil)
}
if hash == Data(SHA256.hash(data: propertyListData)) {
if hash == Data(SHA256.hash(data: encoded)) {
// nothing changed
completionHandler(nil)
} else {
completionHandler(propertyListData)
completionHandler(encoded)
}
}
}