From: Felix Fietkau <nbd@nbd.name>
Date: Sun, 8 Mar 2026 13:41:16 +0000
Subject: [PATCH] add: add --force-reinstall option

Allow reinstalling already-installed packages without a version change.
Only the named packages are reinstalled, not their dependencies.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
---

--- a/src/app_add.c
+++ b/src/app_add.c
@@ -24,6 +24,7 @@ struct add_ctx {
 	OPT(OPT_ADD_initdb,	"initdb") \
 	OPT(OPT_ADD_latest,	APK_OPT_SH("l") "latest") \
 	OPT(OPT_ADD_no_chown,   "no-chown") \
+	OPT(OPT_ADD_reinstall,	"force-reinstall") \
 	OPT(OPT_ADD_upgrade,	APK_OPT_SH("u") "upgrade") \
 	OPT(OPT_ADD_usermode,	"usermode") \
 	OPT(OPT_ADD_virtual,	APK_OPT_ARG APK_OPT_SH("t") "virtual")
@@ -41,6 +42,9 @@ static int add_parse_option(void *ctx, s
 	case OPT_ADD_latest:
 		actx->solver_flags |= APK_SOLVERF_LATEST;
 		break;
+	case OPT_ADD_reinstall:
+		actx->solver_flags |= APK_SOLVERF_REINSTALL;
+		break;
 	case OPT_ADD_upgrade:
 		actx->solver_flags |= APK_SOLVERF_UPGRADE;
 		break;
@@ -177,7 +181,7 @@ static int add_main(void *ctx, struct ap
 			apk_deps_add(&world, &dep);
 			apk_solver_set_name_flags(dep.name,
 						  actx->solver_flags,
-						  actx->solver_flags);
+						  actx->solver_flags & ~APK_SOLVERF_REINSTALL);
 		}
 	}
 	if (actx->virtpkg) {
@@ -185,7 +189,7 @@ static int add_main(void *ctx, struct ap
 		apk_deps_add(&world, &virtdep);
 		apk_solver_set_name_flags(virtdep.name,
 					  actx->solver_flags,
-					  actx->solver_flags);
+					  actx->solver_flags & ~APK_SOLVERF_REINSTALL);
 	}
 
 	r = apk_solver_commit(db, 0, world);
--- a/doc/apk-add.8.scd
+++ b/doc/apk-add.8.scd
@@ -30,6 +30,10 @@ To later upgrade or downgrade back to a
 *apk add* supports the commit options described in *apk*(8), as well as the
 following options:
 
+*--force-reinstall*
+	Allow reinstalling already-installed packages without a version
+	change. Only the named packages are reinstalled, not dependencies.
+
 *--initdb*
 	Initialize a new package database.
 
