static int bt_partition_delete(BT_HANDLE hShell, int argc, char **argv) { if(argc != 1) { usage_delete(hShell); return -1; } if(!device_path) { return no_disk(hShell); } if(!p_active_partition) { BT_PRSHELL("No partitions have been selected, use the select command.\n"); return -1; } memset(&p_partition_info[*p_active_partition], 0, sizeof(struct bt_part_t)); if(*p_active_partition != g_partitions-1) { _order_partitions(); } BT_PRSHELL("Partition %d was deleted\n", *p_active_partition); g_partitions -= 1; p_active_partition = NULL; g_active_partition = 0; return 0; }
static void usage_all(void) { (void) fprintf(stderr, gettext("Usage:\n")); usage_create(B_FALSE); usage_delete(B_FALSE); (void) fprintf(stderr, "ksslcfg -V\n"); (void) fprintf(stderr, "ksslcfg -?\n"); }
int exec_delete(int argc, char **argv) { struct pkg_jobs *jobs = NULL; struct pkgdb *db = NULL; match_t match = MATCH_EXACT; pkg_flags f = PKG_FLAG_NONE; bool recursive_flag = false, rc = false; int retcode = EX_SOFTWARE; int ch; int i; int lock_type = PKGDB_LOCK_ADVISORY; struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "case-sensitive", no_argument, NULL, 'C' }, { "no-deinstall-script", no_argument, NULL, 'D' }, { "force", no_argument, NULL, 'f' }, { "glob", no_argument, NULL, 'g' }, { "case-insensitive", no_argument, NULL, 'i' }, { "dry-run", no_argument, NULL, 'n' }, { "quiet", no_argument, NULL, 'q' }, { "recursive", no_argument, NULL, 'R' }, { "regex", no_argument, NULL, 'x' }, { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 }, }; nbactions = nbdone = 0; while ((ch = getopt_long(argc, argv, "+aCDfginqRxy", longopts, NULL)) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'C': pkgdb_set_case_sensitivity(true); break; case 'D': f |= PKG_FLAG_NOSCRIPT; break; case 'f': f |= PKG_FLAG_FORCE; force = true; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'n': f |= PKG_FLAG_DRY_RUN; lock_type = PKGDB_LOCK_READONLY; dry_run = true; break; case 'q': quiet = true; break; case 'R': recursive_flag = true; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_delete(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL) { usage_delete(); return (EX_USAGE); } if (dry_run) retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL); else retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE, PKGDB_DB_LOCAL); if (retcode == EPKG_ENODB) { warnx("No packages installed. Nothing to do!"); return (EX_OK); } else if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to delete packages"); return (EX_NOPERM); } else if (retcode != EPKG_OK) { warnx("Error accessing the package database"); return (EX_SOFTWARE); } if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) return (EX_IOERR); if (pkgdb_obtain_lock(db, lock_type) != EPKG_OK) { pkgdb_close(db); warnx("Cannot get an advisory lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } if (pkg_jobs_new(&jobs, PKG_JOBS_DEINSTALL, db) != EPKG_OK) { pkgdb_close(db); return (EX_IOERR); } /* * By default delete packages recursively. * If force mode is enabled then we try to remove packages non-recursively. * However, if -f and -R flags are both enabled then we return to * recursive deletion. */ if (!force || recursive_flag) f |= PKG_FLAG_RECURSIVE; pkg_jobs_set_flags(jobs, f); if (match == MATCH_EXACT) { for (i = 0; i < argc; i++) { if (strchr(argv[i], '*') != NULL) { match = MATCH_GLOB; break; } } } if (pkg_jobs_add(jobs, match, argv, argc) == EPKG_FATAL) goto cleanup; if (pkg_jobs_solve(jobs) != EPKG_OK) { fprintf(stderr, "Cannot perform request\n"); retcode = EX_NOPERM; goto cleanup; } /* check if we have something to deinstall */ if ((nbactions = pkg_jobs_count(jobs)) == 0) { if (argc == 0) { if (!quiet) printf("Nothing to do.\n"); retcode = EX_OK; } else { fprintf(stderr, "Package(s) not found!\n"); retcode = EX_DATAERR; } goto cleanup; } if (!quiet || dry_run) { if (!quiet) { print_jobs_summary(jobs, "Deinstallation has been requested for the following %d packages " "(of %d packages in the universe):\n\n", nbactions, pkg_jobs_total(jobs)); } if (dry_run) { retcode = EX_OK; goto cleanup; } rc = query_yesno(false, "\nProceed with deinstalling packages? "); } else rc = yes; if (!rc || (retcode = pkg_jobs_apply(jobs)) != EPKG_OK) goto cleanup; pkgdb_compact(db); retcode = EX_OK; cleanup: pkgdb_release_lock(db, lock_type); pkg_jobs_free(jobs); pkgdb_close(db); return (retcode); }
int exec_delete(int argc, char **argv) { struct pkg_jobs *jobs = NULL; struct pkgdb *db = NULL; match_t match = MATCH_EXACT; int ch; bool force = false; bool yes; bool dry_run = false; int retcode = EX_SOFTWARE; nbactions = nbdone = 0; pkg_flags f = PKG_FLAG_NONE; int i; pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); while ((ch = getopt(argc, argv, "aDfginqRxy")) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'D': f |= PKG_FLAG_NOSCRIPT; break; case 'f': f |= PKG_FLAG_FORCE; force = true; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'n': f |= PKG_FLAG_DRY_RUN; dry_run = true; break; case 'q': quiet = true; break; case 'R': f |= PKG_FLAG_RECURSIVE; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_delete(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL) { usage_delete(); return (EX_USAGE); } retcode = pkgdb_access(PKGDB_MODE_READ|PKGDB_MODE_WRITE, PKGDB_DB_LOCAL); if (retcode == EPKG_ENODB) { warnx("No packages installed. Nothing to do!"); return (EX_OK); } else if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privilege to delete packages"); return (EX_NOPERM); } else if (retcode != EPKG_OK) { warnx("Error accessing package database"); return (EX_SOFTWARE); } if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) return (EX_IOERR); if (pkg_jobs_new(&jobs, PKG_JOBS_DEINSTALL, db) != EPKG_OK) { pkgdb_close(db); return (EX_IOERR); } pkg_jobs_set_flags(jobs, f); if (match == MATCH_EXACT) { for (i = 0; i < argc; i++) { if (strchr(argv[i], '*') != NULL) { match = MATCH_GLOB; break; } } } if (pkg_jobs_add(jobs, match, argv, argc) == EPKG_FATAL) goto cleanup; if (pkg_jobs_solve(jobs) != EPKG_OK) goto cleanup; if ((pkg_jobs_find(jobs, "ports-mgmt/pkg", NULL) == EPKG_OK) && !force) { warnx("You are about to delete 'ports-mgmt/pkg' which is really " "dangerous, you can't do that without specifying -f"); goto cleanup; } /* check if we have something to deinstall */ if ((nbactions = pkg_jobs_count(jobs)) == 0) { if (argc == 0) { if (!quiet) printf("Nothing to do.\n"); retcode = EX_OK; } else { fprintf(stderr, "Package(s) not found!\n"); retcode = EX_DATAERR; } goto cleanup; } if (!quiet || dry_run) { print_jobs_summary(jobs, "Deinstallation has been requested for the following %d packages:\n\n", nbactions); if (!yes && !dry_run) yes = query_yesno( "\nProceed with deinstalling packages [y/N]: "); if (dry_run) yes = false; } if (!yes || (retcode = pkg_jobs_apply(jobs)) != EPKG_OK) goto cleanup; pkgdb_compact(db); retcode = EX_OK; cleanup: pkg_jobs_free(jobs); pkgdb_close(db); return (retcode); }
int do_delete(int argc, char *argv[]) { char c; int status, len, pcnt; char address_port[MAX_ADRPORT_LEN + 1]; char *instance_name; if (argc < 3) { goto err; } argc -= 1; argv += 1; while ((c = getopt(argc, argv, "v")) != -1) { switch (c) { case 'v': verbose = B_TRUE; break; default: goto err; } } pcnt = argc - optind; if (pcnt == 1) { if (strlen(argv[optind]) < MAX_ADRPORT_LEN) { (void) strcpy(address_port, argv[optind]); } else { (void) fprintf(stderr, gettext( "argument too long -- %s\n"), argv[optind]); return (FAILURE); } } else if (pcnt == 2) { if ((len = strlen(argv[optind])) + (strlen(argv[optind + 1])) < MAX_ADRPORT_LEN) { (void) strcpy(address_port, argv[optind]); address_port[len] = ' '; (void) strcpy(address_port + len + 1, argv[optind + 1]); } else { (void) fprintf(stderr, gettext( "arguments too long -- %s %s\n"), argv[optind], argv[optind + 1]); return (FAILURE); } } else { goto err; } instance_name = create_instance_name(address_port, NULL, B_FALSE); if (instance_name == NULL) { return (FAILURE); } KSSL_DEBUG("instance_name=%s\n", instance_name); status = delete_instance(instance_name); free(instance_name); return (status); err: usage_delete(B_TRUE); return (ERROR_USAGE); }