From a9b6d18f7f979cf08f6f48f1f4c12d49689f51b9 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Wed, 15 Apr 2009 13:19:36 +0300 Subject: state: make package deletion safer Refuse to delete explicitly specified top-level packages unless --force is specified. --- src/apk.c | 8 ++++---- src/state.c | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/apk.c b/src/apk.c index 21e4359..bbee041 100644 --- a/src/apk.c +++ b/src/apk.c @@ -117,9 +117,9 @@ static struct option generic_options[32] = { { "quiet", no_argument, NULL, 'q' }, { "verbose", no_argument, NULL, 'v' }, { "version", no_argument, NULL, 'V' }, + { "force", no_argument, NULL, 'f' }, { "progress", no_argument, NULL, 0x101 }, { "clean-protected", no_argument, NULL, 0x102 }, - { "force", no_argument, NULL, 0x103 }, { "simulate", no_argument, NULL, 0x104 }, }; @@ -181,15 +181,15 @@ int main(int argc, char **argv) break; case 'V': return version(); + case 'f': + apk_flags |= APK_FORCE; + break; case 0x101: apk_flags |= APK_PROGRESS; break; case 0x102: apk_flags |= APK_CLEAN_PROTECTED; break; - case 0x103: - apk_flags |= APK_FORCE; - break; case 0x104: apk_flags |= APK_SIMULATE; break; diff --git a/src/state.c b/src/state.c index c07c806..5b6b81c 100644 --- a/src/state.c +++ b/src/state.c @@ -170,8 +170,16 @@ int apk_state_lock_dependency(struct apk_state *state, return -1; if (ns_empty(state->name[name->id])) { - if (dep->result_mask == APK_DEPMASK_CONFLICT) + if (dep->result_mask == APK_DEPMASK_CONFLICT) { + if ((name->flags & APK_NAME_TOPLEVEL) && + !(apk_flags & APK_FORCE)) { + apk_error("Not deleting top level dependency " + "'%s'. Use -f to override.", + name->name); + return -1; + } return apk_state_lock_name(state, name, NULL); + } /* This name has not been visited yet. * Construct list of candidates. */ -- cgit v1.2.3-70-g09d2