uint8_t upgrade_database() { if (pkgindb_doquery(COMPAT_CHECK, pkgindb_simple_callback, NULL) == PDB_ERR) { /* COMPAT_CHECK query leads to an error for an incompatible database */ printf(MSG_DATABASE_NOT_COMPAT); if (!check_yesno(DEFAULT_YES)) exit(EXIT_FAILURE); pkgindb_reset(); return 1; } return 0; }
static int pkg_download(Plisthead *installhead) { FILE *fp; Pkglist *pinstall; struct stat st; Dlfile *dlpkg; char pkg_fs[BUFSIZ], pkg_url[BUFSIZ], query[BUFSIZ]; int rc = EXIT_SUCCESS; printf(MSG_DOWNLOAD_PKGS); SLIST_FOREACH(pinstall, installhead, next) { snprintf(pkg_fs, BUFSIZ, "%s/%s%s", pkgin_cache, pinstall->depend, PKG_EXT); /* pkg_info -X -a produces pkg_summary with empty FILE_SIZE, * people could spend some time blaming on pkgin before finding * what's really going on. */ if (pinstall->file_size == 0) printf(MSG_EMPTY_FILE_SIZE, pinstall->depend); /* already fully downloaded */ if (stat(pkg_fs, &st) == 0 && st.st_size == pinstall->file_size && pinstall->file_size != 0 ) continue; snprintf(query, BUFSIZ, PKG_URL, pinstall->depend); /* retrieve repository for package */ if (pkgindb_doquery(query, pdb_get_value, pkg_url) != 0) errx(EXIT_FAILURE, MSG_PKG_NO_REPO, pinstall->depend); strlcat(pkg_url, "/", sizeof(pkg_url)); strlcat(pkg_url, pinstall->depend, sizeof(pkg_url)); strlcat(pkg_url, PKG_EXT, sizeof(pkg_url)); /* if pkg's repo URL is file://, just symlink */ if (strncmp(pkg_url, SCHEME_FILE, strlen(SCHEME_FILE)) == 0) { (void)unlink(pkg_fs); if (symlink(&pkg_url[strlen(SCHEME_FILE) + 3], pkg_fs) < 0) errx(EXIT_FAILURE, MSG_SYMLINK_FAILED, pkg_fs); printf(MSG_SYMLINKING_PKG, pkg_url); continue; } umask(DEF_UMASK); if ((fp = fopen(pkg_fs, "w")) == NULL) err(EXIT_FAILURE, MSG_ERR_OPEN, pkg_fs); if ((dlpkg = download_file(pkg_url, NULL)) == NULL) { fprintf(stderr, MSG_PKG_NOT_AVAIL, pinstall->depend); rc = EXIT_FAILURE; if (!check_yesno(DEFAULT_NO)) errx(EXIT_FAILURE, MSG_PKG_NOT_AVAIL, pinstall->depend); pinstall->file_size = -1; fclose(fp); continue; } fwrite(dlpkg->buf, dlpkg->size, 1, fp); fclose(fp); XFREE(dlpkg->buf); XFREE(dlpkg); } /* download loop */