Fix missing profile attributes initialization (#828)

Also, log them better during remote import.
This commit is contained in:
Davide 2024-11-07 13:23:47 +01:00 committed by GitHub
parent 22a5cb9af2
commit 21c1bbdf0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 23 deletions

View File

@ -95,9 +95,7 @@ private extension NEProfileRepository {
func onLoadedManagers(_ managers: [Profile.ID: NETunnelProviderManager]) { func onLoadedManagers(_ managers: [Profile.ID: NETunnelProviderManager]) {
let profiles = managers.values.compactMap { let profiles = managers.values.compactMap {
do { do {
let profile = try repository.profile(from: $0) return try repository.profile(from: $0)
pp_log(.App.profiles, .debug, "Attributes for profile \(profile.id): \(profile.attributes)")
return profile
} catch { } catch {
pp_log(.App.profiles, .error, "Unable to decode profile from NE manager '\($0.localizedDescription ?? "")': \(error)") pp_log(.App.profiles, .error, "Unable to decode profile from NE manager '\($0.localizedDescription ?? "")': \(error)")
return nil return nil

View File

@ -360,15 +360,15 @@ private extension ProfileManager {
pp_log(.App.profiles, .info, "Start importing remote profiles...") pp_log(.App.profiles, .info, "Start importing remote profiles...")
pp_log(.App.profiles, .debug, "Local fingerprints:") pp_log(.App.profiles, .debug, "Local attributes:")
let localFingerprints: [Profile.ID: UUID] = await allProfiles.values.reduce(into: [:]) { let localAttributes: [Profile.ID: ProfileAttributes] = await allProfiles.values.reduce(into: [:]) {
$0[$1.id] = $1.attributes.fingerprint $0[$1.id] = $1.attributes
pp_log(.App.profiles, .debug, "\t\($1.id) = \($1.attributes.fingerprint?.description ?? "nil")") pp_log(.App.profiles, .debug, "\t\($1.id) = \($1.attributes)")
} }
pp_log(.App.profiles, .debug, "Remote fingerprints:") pp_log(.App.profiles, .debug, "Remote attributes:")
let remoteFingerprints: [Profile.ID: UUID] = result.reduce(into: [:]) { let remoteAttributes: [Profile.ID: ProfileAttributes] = result.reduce(into: [:]) {
$0[$1.id] = $1.attributes.fingerprint $0[$1.id] = $1.attributes
pp_log(.App.profiles, .debug, "\t\($1.id) = \($1.attributes.fingerprint?.description ?? "nil")") pp_log(.App.profiles, .debug, "\t\($1.id) = \($1.attributes)")
} }
let profilesToImport = result let profilesToImport = result
@ -390,7 +390,7 @@ private extension ProfileManager {
idsToRemove.append(remoteProfile.id) idsToRemove.append(remoteProfile.id)
continue continue
} }
guard remoteFingerprints[remoteProfile.id] != localFingerprints[remoteProfile.id] else { guard remoteAttributes[remoteProfile.id]?.fingerprint != localAttributes[remoteProfile.id]?.fingerprint else {
pp_log(.App.profiles, .info, "Skip re-importing local profile \(remoteProfile.id)") pp_log(.App.profiles, .info, "Skip re-importing local profile \(remoteProfile.id)")
continue continue
} }

View File

@ -28,30 +28,48 @@ import Foundation
import PassepartoutKit import PassepartoutKit
public struct ProfileAttributes: Hashable, Codable { public struct ProfileAttributes: Hashable, Codable {
public var isAvailableForTV: Bool? public var fingerprint: UUID?
public var expirationDate: Date?
public var lastUpdate: Date? public var lastUpdate: Date?
public var fingerprint: UUID? public var isAvailableForTV: Bool?
public var expirationDate: Date?
public init() { public init() {
} }
public init( public init(
isAvailableForTV: Bool?, fingerprint: UUID?,
expirationDate: Date?,
lastUpdate: Date?, lastUpdate: Date?,
fingerprint: UUID? isAvailableForTV: Bool?,
expirationDate: Date?
) { ) {
self.isAvailableForTV = isAvailableForTV
self.lastUpdate = lastUpdate
self.fingerprint = fingerprint self.fingerprint = fingerprint
self.lastUpdate = lastUpdate
self.isAvailableForTV = isAvailableForTV
self.expirationDate = expirationDate
} }
}
public func isEquivalent(to other: Self) -> Bool { extension ProfileAttributes: CustomDebugStringConvertible {
isAvailableForTV == other.isAvailableForTV public var debugDescription: String {
let descs = [
fingerprint.map {
"fingerprint: \($0)"
},
lastUpdate.map {
"lastUpdate: \($0)"
},
isAvailableForTV.map {
"isAvailableForTV: \($0)"
},
expirationDate.map {
"expirationDate: \($0)"
}
].compactMap { $0 }
return "{\(descs.joined(separator: ", "))}"
} }
} }