int exec_fetch(int argc, char **argv) { struct pkg *pkg = NULL; struct pkgdb_it *it = NULL; struct pkgdb *db = NULL; struct pkg_jobs *jobs = NULL; const char *reponame = NULL; int retcode = EXIT_FAILURE; int ch; int flags = PKG_LOAD_BASIC; bool yes = false; bool auto_update = true; match_t match = MATCH_EXACT; while ((ch = getopt(argc, argv, "ygxXr:qaLd")) != -1) { switch (ch) { case 'y': yes = true; break; case 'a': match = MATCH_ALL; break; case 'g': match = MATCH_GLOB; break; case 'x': match = MATCH_REGEX; break; case 'X': match = MATCH_EREGEX; break; case 'r': reponame = optarg; break; case 'q': quiet = true; break; case 'L': auto_update = false; break; case 'd': flags |= PKG_LOAD_DEPS; break; default: usage_fetch(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL) { usage_fetch(); return (EX_USAGE); } /* TODO: Allow the user to specify an output directory via -o outdir */ if (geteuid() != 0) { warnx("Fetching packages can only be done as root"); return (EX_NOPERM); } /* first update the remote repositories if needed */ if (auto_update && (retcode = pkgcli_update()) != EPKG_OK) return (retcode); if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) { return (EX_IOERR); } if (pkg_jobs_new(&jobs, PKG_JOBS_FETCH, db) != EPKG_OK) { goto cleanup; } if ((it = pkgdb_query_fetch(db, match, argc, argv, reponame, flags)) == NULL) goto cleanup; while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) { pkg_jobs_add(jobs, pkg); pkg = NULL; } pkgdb_it_free(it); if (pkg_jobs_is_empty(jobs)) goto cleanup; if (!quiet) { print_jobs_summary(jobs, PKG_JOBS_FETCH, "The following packages will be fetched:\n\n"); if (!yes) pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); if (!yes) yes = query_yesno("\nProceed with fetching packages [y/N]: "); } if (yes) if (pkg_jobs_apply(jobs, 0) != EPKG_OK) goto cleanup; retcode = EXIT_SUCCESS; cleanup: pkg_jobs_free(jobs); pkgdb_close(db); return (retcode); }
int exec_fetch(int argc, char **argv) { struct pkgdb *db = NULL; struct pkg_jobs *jobs = NULL; const char *reponame = NULL; int ch; int retcode = EX_SOFTWARE; bool upgrades_for_installed = false, rc; unsigned mode; match_t match = MATCH_EXACT; pkg_flags f = PKG_FLAG_NONE; struct option longopts[] = { { "all", no_argument, NULL, 'a' }, { "case-sensitive", no_argument, NULL, 'C' }, { "dependencies", no_argument, NULL, 'd' }, { "glob", no_argument, NULL, 'g' }, { "case-insensitive", no_argument, NULL, 'i' }, { "quiet", no_argument, NULL, 'q' }, { "repository", required_argument, NULL, 'r' }, { "avaialbe-updates", no_argument, NULL, 'u' }, { "no-repo-update", no_argument, NULL, 'U' }, { "regex", no_argument, NULL, 'x' }, { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "aCdgiqr:Uuxy", longopts, NULL)) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'C': pkgdb_set_case_sensitivity(true); break; case 'd': f |= PKG_FLAG_WITH_DEPS | PKG_FLAG_RECURSIVE; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'q': quiet = true; break; case 'r': reponame = optarg; break; case 'u': f |= PKG_FLAG_UPGRADES_FOR_INSTALLED; upgrades_for_installed = true; break; case 'U': auto_update = false; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_fetch(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL && !upgrades_for_installed) { usage_fetch(); return (EX_USAGE); } if (match == MATCH_ALL && upgrades_for_installed) { usage_fetch(); return (EX_USAGE); } /* TODO: Allow the user to specify an output directory via -o outdir */ if (auto_update) mode = PKGDB_MODE_READ|PKGDB_MODE_WRITE|PKGDB_MODE_CREATE; else mode = PKGDB_MODE_READ; retcode = pkgdb_access(mode, PKGDB_DB_REPO); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to access repo catalogue"); return (EX_NOPERM); } else if (retcode != EPKG_OK) return (EX_IOERR); if (upgrades_for_installed) { retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to access the package database"); return (EX_NOPERM); } else if (retcode != EPKG_OK) return (EX_IOERR); } /* first update the remote repositories if needed */ if (auto_update && (retcode = pkgcli_update(false, reponame)) != EPKG_OK) return (retcode); if (pkgdb_open_all(&db, PKGDB_REMOTE, reponame) != EPKG_OK) return (EX_IOERR); if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY) != EPKG_OK) { pkgdb_close(db); warnx("Cannot get a read lock on a database, it is locked by another process"); return (EX_TEMPFAIL); } if (pkg_jobs_new(&jobs, PKG_JOBS_FETCH, db) != EPKG_OK) goto cleanup; if (reponame != NULL && pkg_jobs_set_repository(jobs, reponame) != EPKG_OK) goto cleanup; pkg_jobs_set_flags(jobs, f); if (!upgrades_for_installed && pkg_jobs_add(jobs, match, argv, argc) != EPKG_OK) goto cleanup; if (pkg_jobs_solve(jobs) != EPKG_OK) goto cleanup; if (pkg_jobs_count(jobs) == 0) goto cleanup; if (!quiet) { print_jobs_summary(jobs, "The following packages will be fetched:\n\n"); rc = query_yesno(false, "\nProceed with fetching packages [y/N]: "); } else { rc = true; } if (!rc || pkg_jobs_apply(jobs) != EPKG_OK) goto cleanup; retcode = EX_OK; cleanup: pkg_jobs_free(jobs); pkgdb_release_lock(db, PKGDB_LOCK_READONLY); pkgdb_close(db); return (retcode); }
int exec_fetch(int argc, char **argv) { struct pkgdb *db = NULL; struct pkg_jobs *jobs = NULL; const char *reponame = NULL; int ch; int retcode = EX_SOFTWARE; bool auto_update; bool upgrades_for_installed = false; bool yes; unsigned mode; match_t match = MATCH_EXACT; pkg_flags f = PKG_FLAG_NONE; pkg_config_bool(PKG_CONFIG_REPO_AUTOUPDATE, &auto_update); pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); while ((ch = getopt(argc, argv, "adgiqr:Uuxy")) != -1) { switch (ch) { case 'a': match = MATCH_ALL; break; case 'd': f |= PKG_FLAG_WITH_DEPS; break; case 'g': match = MATCH_GLOB; break; case 'i': pkgdb_set_case_sensitivity(false); break; case 'U': auto_update = false; break; case 'q': quiet = true; break; case 'r': reponame = optarg; break; case 'u': f |= PKG_FLAG_UPGRADES_FOR_INSTALLED; upgrades_for_installed = true; break; case 'x': match = MATCH_REGEX; break; case 'y': yes = true; break; default: usage_fetch(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL && !upgrades_for_installed) { usage_fetch(); return (EX_USAGE); } if (match == MATCH_ALL && upgrades_for_installed) { usage_fetch(); return (EX_USAGE); } /* TODO: Allow the user to specify an output directory via -o outdir */ if (auto_update) mode = PKGDB_MODE_READ|PKGDB_MODE_WRITE|PKGDB_MODE_CREATE; else mode = PKGDB_MODE_READ; retcode = pkgdb_access(mode, PKGDB_DB_REPO); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to access repo catalogue"); return (EX_NOPERM); } else if (retcode != EPKG_OK) return (EX_IOERR); if (upgrades_for_installed) { retcode = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL); if (retcode == EPKG_ENOACCESS) { warnx("Insufficient privileges to access the package database"); return (EX_NOPERM); } else if (retcode != EPKG_OK) return (EX_IOERR); } /* first update the remote repositories if needed */ if (auto_update && (retcode = pkgcli_update(false)) != EPKG_OK) return (retcode); if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) return (EX_IOERR); if (pkg_jobs_new(&jobs, PKG_JOBS_FETCH, db) != EPKG_OK) goto cleanup; if (reponame != NULL && pkg_jobs_set_repository(jobs, reponame) != EPKG_OK) goto cleanup; pkg_jobs_set_flags(jobs, f); if (!upgrades_for_installed && pkg_jobs_add(jobs, match, argv, argc) != EPKG_OK) goto cleanup; if (pkg_jobs_solve(jobs) != EPKG_OK) goto cleanup; if (pkg_jobs_count(jobs) == 0) goto cleanup; if (!quiet) { print_jobs_summary(jobs, "The following packages will be fetched:\n\n"); if (!yes) yes = query_yesno("\nProceed with fetching packages [y/N]: "); } if (!yes || pkg_jobs_apply(jobs) != EPKG_OK) goto cleanup; retcode = EX_OK; cleanup: pkg_jobs_free(jobs); pkgdb_close(db); return (retcode); }
int exec_fetch(int argc, char **argv) { struct pkgdb *db = NULL; struct pkg_jobs *jobs = NULL; const char *reponame = NULL; int retcode = EX_SOFTWARE; int ch; bool force = false; bool yes = false; bool auto_update = true; match_t match = MATCH_EXACT; pkg_flags f = PKG_FLAG_NONE; while ((ch = getopt(argc, argv, "ygxr:qaLd")) != -1) { switch (ch) { case 'y': yes = true; break; case 'a': match = MATCH_ALL; break; case 'g': match = MATCH_GLOB; break; case 'x': match = MATCH_REGEX; break; case 'r': reponame = optarg; break; case 'q': quiet = true; break; case 'L': auto_update = false; break; case 'd': f |= PKG_FLAG_WITH_DEPS; force = true; break; default: usage_fetch(); return (EX_USAGE); } } argc -= optind; argv += optind; if (argc < 1 && match != MATCH_ALL) { usage_fetch(); return (EX_USAGE); } /* TODO: Allow the user to specify an output directory via -o outdir */ if (geteuid() != 0) { warnx("Fetching packages can only be done as root"); return (EX_NOPERM); } /* first update the remote repositories if needed */ if (auto_update && (retcode = pkgcli_update(false)) != EPKG_OK) return (retcode); if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) return (EX_IOERR); if (pkg_jobs_new(&jobs, PKG_JOBS_FETCH, db) != EPKG_OK) goto cleanup; pkg_jobs_set_flags(jobs, f); if (pkg_jobs_add(jobs, match, argv, argc) != EPKG_OK) goto cleanup; if (pkg_jobs_solve(jobs) != EPKG_OK) goto cleanup; if (pkg_jobs_count(jobs) == 0) goto cleanup; if (!quiet) { print_jobs_summary(jobs, "The following packages will be fetched:\n\n"); if (!yes) pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes); if (!yes) yes = query_yesno("\nProceed with fetching packages [y/N]: "); } if (!yes || pkg_jobs_apply(jobs) != EPKG_OK) goto cleanup; retcode = EX_OK; cleanup: pkg_jobs_free(jobs); pkgdb_close(db); return (retcode); }