split --force to several --force-[type] options

This unloads --force as several of the things are really not wanted
together. E.g. --force-refresh is a lot different from --force-broken-world
and doing --force to get the other might introduce unwanted behaviour.

--force is still kept for backwards compatibility and it enables
most things --force was used for.
cute-signatures
Timo Teräs 2018-01-03 15:17:11 +02:00
parent f90af35e9c
commit 039ff3bd46
9 changed files with 60 additions and 24 deletions

View File

@ -60,7 +60,7 @@ static const struct apk_option_group optgroup_applet = {
static int non_repository_check(struct apk_database *db)
{
if (apk_flags & APK_FORCE)
if (apk_force & APK_FORCE_NON_REPOSITORY)
return 0;
if (apk_db_cache_active(db))
return 0;
@ -69,8 +69,8 @@ static int non_repository_check(struct apk_database *db)
apk_error("You tried to add a non-repository package to system, "
"but it would be lost on next reboot. Enable package caching "
"(apk cache --help) or use --force if you know what you are "
"doing.");
"(apk cache --help) or use --force-non-repository "
"if you know what you are doing.");
return 1;
}

View File

@ -95,7 +95,27 @@ static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt
version();
return -ESHUTDOWN;
case 'f':
apk_flags |= APK_FORCE;
apk_force |= APK_FORCE_OVERWRITE | APK_FORCE_OLD_APK
| APK_FORCE_BROKEN_WORLD | APK_FORCE_NON_REPOSITORY
| APK_FORCE_BINARY_STDOUT;
break;
case 0x120:
apk_force |= APK_FORCE_OVERWRITE;
break;
case 0x121:
apk_force |= APK_FORCE_OLD_APK;
break;
case 0x122:
apk_force |= APK_FORCE_BROKEN_WORLD;
break;
case 0x123:
apk_force |= APK_FORCE_REFRESH;
break;
case 0x124:
apk_force |= APK_FORCE_NON_REPOSITORY;
break;
case 0x125:
apk_force |= APK_FORCE_BINARY_STDOUT;
break;
case 'i':
apk_flags |= APK_INTERACTIVE;
@ -166,7 +186,13 @@ static const struct apk_option options_global[] = {
{ 'v', "verbose", "Print more information (can be doubled)" },
{ 'i', "interactive", "Ask confirmation for certain operations" },
{ 'V', "version", "Print program version and exit" },
{ 'f', "force", "Do what was asked even if it looks dangerous" },
{ 'f', "force", "Enable selected --force-* (deprecated)" },
{ 0x125, "force-binary-stdout", "Continue even if binary data is to be output" },
{ 0x122, "force-broken-world", "Continue even if 'world' cannot be satisfied" },
{ 0x124, "force-non-repository", "Continue even if packages may be lost on reboot" },
{ 0x121, "force-old-apk", "Continue even if packages use unsupported features" },
{ 0x120, "force-overwrite", "Overwrite files in other packages" },
{ 0x123, "force-refresh", "Do not use cached files (local or from proxy)" },
{ 'U', "update-cache", "Update the repository cache" },
{ 0x101, "progress", "Show a progress bar" },
{ 0x10f, "progress-fd", "Write progress to fd", required_argument, "FD" },
@ -182,7 +208,7 @@ static const struct apk_option options_global[] = {
{ 0x108, "repositories-file", "Override repositories file",
required_argument, "REPOFILE" },
{ 0x109, "no-network", "Do not use network (cache is still used)" },
{ 0x115, "no-cache", "Read uncached index from network" },
{ 0x115, "no-cache", "Do not use any local cache path" },
{ 0x116, "cache-dir", "Override cache directory",
required_argument, "CACHEDIR" },
{ 0x112, "arch", "Use architecture with --root",
@ -222,7 +248,9 @@ static int option_parse_commit(void *ctx, struct apk_db_options *dbopts, int opt
break;
case 0x118:
dbopts->open_flags |= APK_OPENF_CREATE;
apk_flags |= APK_FORCE | APK_NO_COMMIT_HOOKS;
apk_flags |= APK_NO_COMMIT_HOOKS;
apk_force |= APK_FORCE_OVERWRITE | APK_FORCE_OLD_APK
| APK_FORCE_BROKEN_WORLD | APK_FORCE_NON_REPOSITORY;
break;
default:
return -ENOTSUP;

View File

@ -60,11 +60,10 @@ static inline int IS_ERR_OR_NULL(const void *ptr) { return IS_ERR(ptr) || !ptr;
#endif
extern int apk_verbosity;
extern unsigned int apk_flags;
extern unsigned int apk_flags, apk_force;
extern const char *apk_arch;
extern char **apk_argv;
#define APK_FORCE 0x0001
#define APK_SIMULATE 0x0002
#define APK_CLEAN_PROTECTED 0x0004
#define APK_PROGRESS 0x0008
@ -79,6 +78,13 @@ extern char **apk_argv;
#define APK_NO_CACHE 0x8000
#define APK_NO_COMMIT_HOOKS 0x00010000
#define APK_FORCE_OVERWRITE BIT(0)
#define APK_FORCE_OLD_APK BIT(1)
#define APK_FORCE_BROKEN_WORLD BIT(2)
#define APK_FORCE_REFRESH BIT(3)
#define APK_FORCE_NON_REPOSITORY BIT(4)
#define APK_FORCE_BINARY_STDOUT BIT(5)
/* default architecture for APK packages. */
#if defined(__x86_64__)
#define APK_DEFAULT_ARCH "x86_64"

View File

@ -266,7 +266,8 @@ int apk_solver_commit_changeset(struct apk_database *db,
int r, errors = 0;
if (apk_db_check_world(db, world) != 0) {
apk_error("Not committing changes due to missing repository tags. Use --force to override.");
apk_error("Not committing changes due to missing repository tags. "
"Use --force-broken-world to override.");
return -1;
}
@ -675,7 +676,8 @@ int apk_solver_commit(struct apk_database *db,
int r;
if (apk_db_check_world(db, world) != 0) {
apk_error("Not committing changes due to missing repository tags. Use --force to override.");
apk_error("Not committing changes due to missing repository tags. "
"Use --force-broken-world to override.");
return -1;
}

View File

@ -47,7 +47,7 @@ enum {
};
int apk_verbosity = 1;
unsigned int apk_flags = 0;
unsigned int apk_flags = 0, apk_force = 0;
static apk_blob_t tmpprefix = { .len=8, .ptr = ".apknew." };
@ -633,7 +633,7 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
r = apk_repo_format_real_url(db, repo, pkg, url, sizeof(url));
if (r < 0) return r;
if ((apk_flags & APK_FORCE) ||
if ((apk_force & APK_FORCE_REFRESH) ||
fstatat(db->cache_fd, cacheitem, &st, 0) != 0)
st.st_mtime = 0;
@ -867,13 +867,13 @@ int apk_db_index_read(struct apk_database *db, struct apk_bstream *bs, int repo)
case 's': ipkg->broken_script = 1; break;
case 'x': ipkg->broken_xattr = 1; break;
default:
if (!(apk_flags & APK_FORCE))
if (!(apk_force & APK_FORCE_OLD_APK))
goto old_apk_tools;
}
}
break;
default:
if (r != 0 && !(apk_flags & APK_FORCE))
if (r != 0 && !(apk_force & APK_FORCE_OLD_APK))
goto old_apk_tools;
/* Installed. So mark the package as installable. */
pkg->filename = NULL;
@ -2033,7 +2033,7 @@ int apk_db_check_world(struct apk_database *db, struct apk_dependency_array *wor
struct apk_dependency *dep;
int bad = 0, tag;
if (apk_flags & APK_FORCE)
if (apk_force & APK_FORCE_BROKEN_WORLD)
return 0;
foreach_array_item(dep, world) {
@ -2463,7 +2463,7 @@ static int apk_db_install_archive_entry(void *_ctx,
if (pkg_prio >= 0)
break;
if (!(apk_flags & APK_FORCE)) {
if (!(apk_force & APK_FORCE_OVERWRITE)) {
apk_error(PKG_VER_FMT": trying to overwrite %s owned by "PKG_VER_FMT".",
PKG_VER_PRINTF(pkg), ae->name, PKG_VER_PRINTF(opkg));
ipkg->broken_files = 1;

View File

@ -319,8 +319,7 @@ static int fetch_main(void *pctx, struct apk_database *db, struct apk_string_arr
ctx->outdir_fd = AT_FDCWD;
if ((args->num == 1) && (strcmp(args->item[0], "coffee") == 0)) {
if (apk_flags & APK_FORCE)
return cup();
if (apk_force) return cup();
apk_message("Go and fetch your own coffee.");
return 0;
}

View File

@ -118,9 +118,9 @@ static int index_main(void *ctx, struct apk_database *db, struct apk_string_arra
char **parg;
if (isatty(STDOUT_FILENO) && ictx->output == NULL &&
!(apk_flags & APK_FORCE)) {
apk_error("Will not write binary index to console "
"without --force");
!(apk_force & APK_FORCE_BINARY_STDOUT)) {
apk_error("Will not write binary index to console. "
"Use --force-binary-stdout to override.");
return -1;
}

View File

@ -1022,7 +1022,7 @@ restart:
generate_changeset(ss, world);
if (ss->errors && (apk_flags & APK_FORCE)) {
if (ss->errors && (apk_force & APK_FORCE_BROKEN_WORLD)) {
foreach_array_item(d, world) {
name = d->name;
pkg = name->ss.chosen.pkg;

View File

@ -144,7 +144,8 @@ static int upgrade_main(void *ctx, struct apk_database *db, struct apk_string_ar
int r = 0;
if (apk_db_check_world(db, db->world) != 0) {
apk_error("Not continuing with upgrade due to missing repository tags. Use --force to override.");
apk_error("Not continuing with upgrade due to missing repository tags. "
"Use --force-broken-world to override.");
return -1;
}