Skip to content

Commit

Permalink
fix: Only set options for filtered patches
Browse files Browse the repository at this point in the history
This prevents errors when settings required options from patches that are not accepted to `null`.
  • Loading branch information
oSumAtrIX committed Oct 4, 2023
1 parent e3c5550 commit 64d9127
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/kotlin/app/revanced/cli/command/PatchCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,6 @@ internal object PatchCommand : Runnable {
logger.warning("Unknown input of patches:\n${unknownPatches.joinToString("\n")}")
}

logger.info("Setting patch options")

optionsFile.let {
if (it.exists()) patches.setOptions(it)
else Options.serialize(patches, prettyPrint = true).let(it::writeText)
}

// endregion

Patcher(
Expand All @@ -213,11 +206,18 @@ internal object PatchCommand : Runnable {
resourceCachePath.absolutePath,
)
).use { patcher ->
val filteredPatches = patcher.filterPatchSelection(patches).also { patches ->
logger.info("Setting patch options")

if (optionsFile.exists()) patches.setOptions(optionsFile)
else Options.serialize(patches, prettyPrint = true).let(optionsFile::writeText)
}

// region Patch

val patcherResult = patcher.apply {
acceptIntegrations(integrations)
acceptPatches(filterPatchSelection(patches))
acceptPatches(filteredPatches.toList())

// Execute patches.
runBlocking {
Expand Down Expand Up @@ -277,7 +277,7 @@ internal object PatchCommand : Runnable {
* @param patches The patches to filter.
* @return The filtered patches.
*/
private fun Patcher.filterPatchSelection(patches: PatchSet) = buildList {
private fun Patcher.filterPatchSelection(patches: PatchSet): PatchSet = buildSet {
val packageName = context.packageMetadata.packageName
val packageVersion = context.packageMetadata.packageVersion

Expand Down

0 comments on commit 64d9127

Please sign in to comment.