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]) {
let profiles = managers.values.compactMap {
do {
let profile = try repository.profile(from: $0)
pp_log(.App.profiles, .debug, "Attributes for profile \(profile.id): \(profile.attributes)")
return profile
return try repository.profile(from: $0)
} catch {
pp_log(.App.profiles, .error, "Unable to decode profile from NE manager '\($0.localizedDescription ?? "")': \(error)")
return nil

View File

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

View File

@ -28,30 +28,48 @@ import Foundation
import PassepartoutKit
public struct ProfileAttributes: Hashable, Codable {
public var isAvailableForTV: Bool?
public var expirationDate: Date?
public var fingerprint: UUID?
public var lastUpdate: Date?
public var fingerprint: UUID?
public var isAvailableForTV: Bool?
public var expirationDate: Date?
public init() {
}
public init(
isAvailableForTV: Bool?,
expirationDate: Date?,
fingerprint: UUID?,
lastUpdate: Date?,
fingerprint: UUID?
isAvailableForTV: Bool?,
expirationDate: Date?
) {
self.isAvailableForTV = isAvailableForTV
self.lastUpdate = lastUpdate
self.fingerprint = fingerprint
self.lastUpdate = lastUpdate
self.isAvailableForTV = isAvailableForTV
self.expirationDate = expirationDate
}
}
public func isEquivalent(to other: Self) -> Bool {
isAvailableForTV == other.isAvailableForTV
extension ProfileAttributes: CustomDebugStringConvertible {
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: ", "))}"
}
}