mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-20 20:23:25 +01:00
Verifies Sources don’t contain duplicate app versions
This commit is contained in:
@@ -20,29 +20,53 @@ extension SourceError
|
|||||||
|
|
||||||
case unsupported
|
case unsupported
|
||||||
case duplicateBundleID
|
case duplicateBundleID
|
||||||
|
case duplicateVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
static func unsupported(_ source: Source) -> SourceError { SourceError(code: .unsupported, source: source) }
|
static func unsupported(_ source: Source) -> SourceError { SourceError(code: .unsupported, source: source) }
|
||||||
static func duplicateBundleID(_ bundleID: String, source: Source) -> SourceError { SourceError(code: .duplicateBundleID, source: source, duplicateBundleID: bundleID) }
|
static func duplicateBundleID(_ bundleID: String, source: Source) -> SourceError { SourceError(code: .duplicateBundleID, source: source, bundleID: bundleID) }
|
||||||
|
static func duplicateVersion(_ version: String, for app: StoreApp, source: Source) -> SourceError { SourceError(code: .duplicateVersion, source: source, app: app, version: version) }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SourceError: ALTLocalizedError
|
struct SourceError: ALTLocalizedError
|
||||||
{
|
{
|
||||||
var code: Code
|
let code: Code
|
||||||
var errorTitle: String?
|
var errorTitle: String?
|
||||||
var errorFailure: String?
|
var errorFailure: String?
|
||||||
|
|
||||||
@Managed var source: Source
|
@Managed var source: Source
|
||||||
var duplicateBundleID: String?
|
@Managed var app: StoreApp?
|
||||||
|
var bundleID: String?
|
||||||
|
var version: String?
|
||||||
|
|
||||||
var errorFailureReason: String {
|
var errorFailureReason: String {
|
||||||
switch self.code
|
switch self.code
|
||||||
{
|
{
|
||||||
case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of AltStore.", comment: ""), self.$source.name)
|
case .unsupported: return String(format: NSLocalizedString("The source “%@” is not supported by this version of AltStore.", comment: ""), self.$source.name)
|
||||||
case .duplicateBundleID:
|
case .duplicateBundleID:
|
||||||
let bundleIDFragment = self.duplicateBundleID.map { String(format: NSLocalizedString("the bundle identifier %@", comment: ""), $0) } ?? NSLocalizedString("the same bundle identifier", comment: "")
|
let bundleIDFragment = self.bundleID.map { String(format: NSLocalizedString("the bundle identifier %@", comment: ""), $0) } ?? NSLocalizedString("the same bundle identifier", comment: "")
|
||||||
let failureReason = String(format: NSLocalizedString("The source “%@” contains multiple apps with %@.", comment: ""), self.$source.name, bundleIDFragment)
|
let failureReason = String(format: NSLocalizedString("The source “%@” contains multiple apps with %@.", comment: ""), self.$source.name, bundleIDFragment)
|
||||||
return failureReason
|
return failureReason
|
||||||
|
|
||||||
|
case .duplicateVersion:
|
||||||
|
var versionFragment = NSLocalizedString("duplicate versions", comment: "")
|
||||||
|
if let version
|
||||||
|
{
|
||||||
|
versionFragment += " (\(version))"
|
||||||
|
}
|
||||||
|
|
||||||
|
let appFragment: String
|
||||||
|
if let name = self.$app.name, let bundleID = self.$app.bundleIdentifier
|
||||||
|
{
|
||||||
|
appFragment = name + " (\(bundleID))"
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
appFragment = NSLocalizedString("one or more apps", comment: "")
|
||||||
|
}
|
||||||
|
|
||||||
|
let failureReason = String(format: NSLocalizedString("The source “%@” contains %@ for %@.", comment: ""), self.$source.name, versionFragment, appFragment)
|
||||||
|
return failureReason
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +183,13 @@ private extension FetchSourceOperation
|
|||||||
{
|
{
|
||||||
guard !bundleIDs.contains(app.bundleIdentifier) else { throw SourceError.duplicateBundleID(app.bundleIdentifier, source: source) }
|
guard !bundleIDs.contains(app.bundleIdentifier) else { throw SourceError.duplicateBundleID(app.bundleIdentifier, source: source) }
|
||||||
bundleIDs.insert(app.bundleIdentifier)
|
bundleIDs.insert(app.bundleIdentifier)
|
||||||
|
|
||||||
|
var versions = Set<String>()
|
||||||
|
for version in app.versions
|
||||||
|
{
|
||||||
|
guard !versions.contains(version.version) else { throw SourceError.duplicateVersion(version.version, for: app, source: source) }
|
||||||
|
versions.insert(version.version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user