From c8abb245f300005443ea7a6cde75ccbeaf50c3c4 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 30 Jul 2023 17:43:03 +0200 Subject: [PATCH] Restore on-demand backward compatibility (#338) In #333, the non-optional field `disconnectsIfNotMatching` was removed completely. Therefore, downgrading from 2.2.0 may lose profiles due to the missing required field. Mitigate the issue by restoring the field as optional, even if it's unused, for the sake of not breaking profile serialization until the 2.2.0 release. Remove the deprecated field after that. --- .../Sources/PassepartoutVPN/Domain/Profile+OnDemand.swift | 3 +++ .../Strategies/CDProfileRepository.swift | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/PassepartoutLibrary/Sources/PassepartoutVPN/Domain/Profile+OnDemand.swift b/PassepartoutLibrary/Sources/PassepartoutVPN/Domain/Profile+OnDemand.swift index 38c45e8d..32cfcb7f 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPN/Domain/Profile+OnDemand.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPN/Domain/Profile+OnDemand.swift @@ -49,6 +49,9 @@ extension Profile { public var withOtherNetworks: Set = [] + @available(*, deprecated, message: "Drop field after releasing as optional to the App Store") + public var disconnectsIfNotMatching: Bool? = true + public init() { } } diff --git a/PassepartoutLibrary/Sources/PassepartoutVPNImpl/Strategies/CDProfileRepository.swift b/PassepartoutLibrary/Sources/PassepartoutVPNImpl/Strategies/CDProfileRepository.swift index ce457aec..6557bd56 100644 --- a/PassepartoutLibrary/Sources/PassepartoutVPNImpl/Strategies/CDProfileRepository.swift +++ b/PassepartoutLibrary/Sources/PassepartoutVPNImpl/Strategies/CDProfileRepository.swift @@ -98,7 +98,12 @@ final class CDProfileRepository: ProfileRepository { existing.forEach(context.delete) try profiles.forEach { - _ = try ProfileMapper(context).toDTO($0) + + // FIXME: on-demand, workaround to retain profiles on downgrade (field is required before 2.2.0) + var copy = $0 + copy.onDemand.disconnectsIfNotMatching = true + + _ = try ProfileMapper(context).toDTO(copy) } try context.save() } catch {