void print_info(struct pkg * const pkg, unsigned int options) { struct pkg_category *cat = NULL; struct pkg_dep *dep = NULL; struct pkg_dir *dir = NULL; struct pkg_file *file = NULL; struct pkg_group *group = NULL; struct pkg_license *lic = NULL; struct pkg_option *option = NULL; struct pkg_shlib *shlib = NULL; struct pkg_user *user = NULL; bool multirepos_enabled = false; bool print_tag = false; bool show_locks = false; char size[7]; const char *name, *version, *prefix, *origin, *reponame, *repourl; const char *maintainer, *www, *comment, *desc, *message, *arch; const char *repopath; const char *tab; char *m; unsigned opt; int64_t flatsize, newflatsize, newpkgsize; lic_t licenselogic; bool locked; int cout = 0; /* Number of characters output */ int info_num; /* Number of different data items to print */ pkg_config_bool(PKG_CONFIG_MULTIREPOS, &multirepos_enabled); pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_PREFIX, &prefix, PKG_ORIGIN, &origin, PKG_REPONAME, &reponame, PKG_REPOURL, &repourl, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &newpkgsize, PKG_LICENSE_LOGIC, &licenselogic, PKG_MESSAGE, &message, PKG_ARCH, &arch, PKG_REPOPATH, &repopath, PKG_LOCKED, &locked); if (!multirepos_enabled) pkg_config_string(PKG_CONFIG_REPO, &repourl); if (options & INFO_RAW) { /* Not for remote packages */ if (pkg_type(pkg) != PKG_REMOTE) { pkg_emit_manifest(pkg, &m); printf("%s\n", m); free(m); } return; } /* Show locking status when requested to display it and the package is locally installed */ if (pkg_type(pkg) == PKG_INSTALLED && (options & INFO_LOCKED) != 0) show_locks = true; if (!quiet) { /* Print a tag-line identifying the package -- either NAMEVER, ORIGIN or NAME (in that order of preference). This may be the only output from this function */ if (options & INFO_TAG_NAMEVER) cout = printf("%s-%s", name, version); else if (options & INFO_TAG_ORIGIN) cout = printf("%s", origin); else if (options & INFO_TAG_NAME) cout = printf("%s", name); } /* Don't display a tab if quiet, retains compatibility. */ tab = quiet ? "" : "\t"; /* If we printed a tag, and there are no other items to print, then just return now. If there's only one single-line item to print, show it at column 32 on the same line. If there's one multi-line item to print, start a new line. If there is more than one item to print per pkg, use 'key : value' style to show on a new line. */ info_num = 0; for (opt = 0x1U; opt <= INFO_LASTFIELD; opt <<= 1) if ((opt & options) != 0) info_num++; if (info_num == 0 && cout > 0) { printf("\n"); return; } if (info_num == 1) { /* Only one item to print */ print_tag = false; if (!quiet) { if (options & INFO_MULTILINE) printf(":\n"); else { if (cout < 31) cout = 31 - cout; else cout = 1; printf("%*s", cout, " "); } } } else { /* Several items to print */ print_tag = true; if (!quiet) printf("\n"); } for (opt = 0x1; opt <= INFO_LASTFIELD; opt <<= 1) { if ((opt & options) == 0) continue; switch (opt) { case INFO_NAME: if (print_tag) printf("%-15s: ", "Name"); printf("%s\n", name); break; case INFO_VERSION: if (print_tag) printf("%-15s: ", "Version"); printf("%s\n", version); break; case INFO_ORIGIN: if (print_tag) printf("%-15s: ", "Origin"); printf("%s\n", origin); break; case INFO_PREFIX: if (print_tag) printf("%-15s: ", "Prefix"); printf("%s\n", prefix); break; case INFO_REPOSITORY: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Repository"); printf("%s [%s]\n", reponame, repourl); } else if (!print_tag) printf("\n"); break; case INFO_CATEGORIES: if (pkg_list_count(pkg, PKG_CATEGORIES) > 0) { if (print_tag) printf("%-15s: ", "Categories"); if (pkg_categories(pkg, &cat) == EPKG_OK) printf("%s", pkg_category_name(cat)); while (pkg_categories(pkg, &cat) == EPKG_OK) printf(" %s", pkg_category_name(cat)); printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_LICENSES: if (pkg_list_count(pkg, PKG_LICENSES) > 0) { if (print_tag) printf("%-15s: ", "Licenses"); if (pkg_licenses(pkg, &lic) == EPKG_OK) printf("%s", pkg_license_name(lic)); while (pkg_licenses(pkg, &lic) == EPKG_OK) { if (licenselogic != 1) printf(" %c", licenselogic); printf(" %s", pkg_license_name(lic)); } printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_MAINTAINER: if (print_tag) printf("%-15s: ", "Maintainer"); printf("%s\n", maintainer); break; case INFO_WWW: if (print_tag) printf("%-15s: ", "WWW"); printf("%s\n", www); break; case INFO_COMMENT: if (print_tag) printf("%-15s: ", "Comment"); printf("%s\n", comment); break; case INFO_OPTIONS: if (pkg_list_count(pkg, PKG_OPTIONS) > 0) { if (print_tag) printf("%-15s:\n", "Options"); while (pkg_options(pkg, &option) == EPKG_OK) printf("%s%-15s: %s\n", tab, pkg_option_opt(option), pkg_option_value(option)); } break; case INFO_SHLIBS_REQUIRED: if (pkg_list_count(pkg, PKG_SHLIBS_REQUIRED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs required"); while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_SHLIBS_PROVIDED: if (pkg_list_count(pkg, PKG_SHLIBS_PROVIDED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs provided"); while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_FLATSIZE: if (pkg_type(pkg) == PKG_INSTALLED || pkg_type(pkg) == PKG_FILE) humanize_number(size, sizeof(size), flatsize,"B", HN_AUTOSCALE, 0); else humanize_number(size, sizeof(size), newflatsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Flat size"); printf("%s\n", size); break; case INFO_PKGSIZE: /* Remote pkgs only */ if (pkg_type(pkg) == PKG_REMOTE) { humanize_number(size, sizeof(size), newpkgsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Pkg size"); printf("%s\n", size); } else if (!print_tag) printf("\n"); break; case INFO_DESCR: if (print_tag) printf("%-15s:\n", "Description"); printf("%s\n", desc); break; case INFO_MESSAGE: if (message) { if (print_tag) printf("%-15s:\n", "Message"); printf("%s\n", message); } break; case INFO_DEPS: if (pkg_list_count(pkg, PKG_DEPS) > 0) { if (print_tag) printf("%-15s:\n", "Depends on"); while (pkg_deps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_RDEPS: if (pkg_list_count(pkg, PKG_RDEPS) > 0) { if (print_tag) printf("%-15s:\n", "Required by"); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_FILES: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_FILES) > 0) { if (print_tag) printf("%-15s:\n", "Files"); while (pkg_files(pkg, &file) == EPKG_OK) printf("%s%s\n", tab, pkg_file_path(file)); } break; case INFO_DIRS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_DIRS) > 0) { if (print_tag) printf("%-15s:\n", "Directories"); while (pkg_dirs(pkg, &dir) == EPKG_OK) printf("%s%s\n", tab, pkg_dir_path(dir)); } break; case INFO_USERS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_USERS) > 0) { if (print_tag) printf("%-15s: ", "Users"); if (pkg_users(pkg, &user) == EPKG_OK) printf("%s", pkg_user_name(user)); while (pkg_users(pkg, &user) == EPKG_OK) printf(" %s", pkg_user_name(user)); printf("\n"); } break; case INFO_GROUPS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_GROUPS) > 0) { if (print_tag) printf("%-15s: ", "Groups"); if (pkg_groups(pkg, &group) == EPKG_OK) printf("%s", pkg_group_name(group)); while (pkg_groups(pkg, &group) == EPKG_OK) printf(" %s", pkg_group_name(group)); printf("\n"); } break; case INFO_ARCH: if (print_tag) printf("%-15s: ", "Architecture"); printf("%s\n", arch); break; case INFO_REPOURL: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Pkg URL"); if (repourl[strlen(repourl) -1] == '/') printf("%s%s\n", repourl, repopath); else printf("%s/%s\n", repourl, repopath); } else if (!print_tag) printf("\n"); break; case INFO_LOCKED: if (print_tag) printf("%-15s: ", "Locked"); printf("%s\n", locked ? "yes" : "no"); break; } } }
int print_info(struct pkg * const pkg, unsigned int opt) { struct pkg_dep *dep = NULL; struct pkg_file *file = NULL; struct pkg_category *cat = NULL; struct pkg_license *lic = NULL; struct pkg_option *option = NULL; bool multirepos_enabled = false; char *m; char size[7]; const char *name, *version, *prefix, *origin, *reponame, *repourl; const char *maintainer, *www, *comment, *desc; int64_t flatsize, newflatsize, newpkgsize; lic_t licenselogic; pkg_config_bool(PKG_CONFIG_MULTIREPOS, &multirepos_enabled); pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_PREFIX, &prefix, PKG_ORIGIN, &origin, PKG_REPONAME, &reponame, PKG_REPOURL, &repourl, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &newpkgsize, PKG_LICENSE_LOGIC, &licenselogic); if (opt & INFO_RAW) { pkg_emit_manifest(pkg, &m); printf("%s\n", m); free(m); } else if (opt & INFO_FULL) { printf("%-15s: %s\n", "Name", name); printf("%-15s: %s\n", "Version", version); printf("%-15s: %s\n", "Origin", origin); printf("%-15s: %s\n", "Prefix", prefix); if ((pkg_type(pkg) == PKG_REMOTE) && multirepos_enabled) printf("%-15s: %s [%s]\n", "Repository", reponame, repourl); if (!pkg_list_is_empty(pkg, PKG_CATEGORIES)) { printf("%-15s:", "Categories"); while (pkg_categories(pkg, &cat) == EPKG_OK) printf(" %s", pkg_category_name(cat)); printf("\n"); } if (!pkg_list_is_empty(pkg, PKG_LICENSES)) { printf("%-15s:", "Licenses"); while (pkg_licenses(pkg, &lic) == EPKG_OK) { printf(" %s", pkg_license_name(lic)); if (licenselogic != 1) printf(" %c", licenselogic); else printf(" "); } printf("\b \n"); } printf("%-15s: %s\n", "Maintainer", maintainer); printf("%-15s: %s\n", "WWW", www); printf("%-15s: %s\n", "Comment", comment); if (!pkg_list_is_empty(pkg, PKG_OPTIONS)) { printf("%-15s: \n", "Options"); while (pkg_options(pkg, &option) == EPKG_OK) printf("\t%s: %s\n", pkg_option_opt(option), pkg_option_value(option)); } if (pkg_type(pkg) == PKG_INSTALLED || pkg_type(pkg) == PKG_FILE) { humanize_number(size, sizeof(size), flatsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Flat size", size); } else { humanize_number(size, sizeof(size), newflatsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Flat size", size); humanize_number(size, sizeof(size), newpkgsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Pkg size", size); } printf("%-15s: \n%s\n", "Description", desc); printf("\n"); } else if (opt & INFO_PRINT_DEP) { if (!(opt & INFO_QUIET)) printf("%s-%s depends on:\n", name, version); while (pkg_deps(pkg, &dep) == EPKG_OK) { printf("%s-%s\n", pkg_dep_get(dep, PKG_DEP_NAME), pkg_dep_get(dep, PKG_DEP_VERSION)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_PRINT_RDEP) { if (!(opt & INFO_QUIET)) printf("%s-%s is required by:\n", name, version); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { printf("%s-%s\n", pkg_dep_get(dep, PKG_DEP_NAME), pkg_dep_get(dep, PKG_DEP_VERSION)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_LIST_FILES) { if (!(opt & INFO_QUIET)) printf("%s-%s owns the following files:\n", name, version); while (pkg_files(pkg, &file) == EPKG_OK) { printf("%s\n", pkg_file_get(file, PKG_FILE_PATH)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_SIZE) { if (pkg_type(pkg) == PKG_INSTALLED) { humanize_number(size, sizeof(size), flatsize, "B", HN_AUTOSCALE, 0); printf("%s-%s size is: %s\n", name, version, size); } else { humanize_number(size, sizeof(size), newflatsize, "B", HN_AUTOSCALE, 0); printf("%s-%s flat size is: %s\n", name, version, size); humanize_number(size, sizeof(size), newpkgsize, "B", HN_AUTOSCALE, 0); printf("%s-%s package size is: %s\n", name, version, size); } } else if (opt & INFO_ORIGIN) { if (opt & INFO_QUIET) printf("%s\n", origin); else printf("%s-%s: %s\n", name, version, origin); } else if (opt & INFO_PREFIX) { if (opt & INFO_QUIET) printf("%s\n", prefix); else printf("%s-%s: %s\n", name, version, prefix); } else { if (opt & INFO_QUIET) printf("%s-%s\n", name, version); else { if ((pkg_type(pkg) == PKG_REMOTE) && multirepos_enabled) printf("%s-%s [repository: %s]: %s\n", name, version, reponame, comment); else printf("%s-%s: %s\n", name, version, comment); } } return (0); }
static int pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archive) { char fpath[MAXPATHLEN]; struct pkg_file **files; struct pkg_script **scripts; char *m; int i; const char *scriptname = NULL; pkg_emit_manifest(pkg, &m); packing_append_buffer(pkg_archive, m, "+MANIFEST", strlen(m)); free(m); packing_append_buffer(pkg_archive, pkg_get(pkg, PKG_DESC), "+DESC", strlen(pkg_get(pkg, PKG_DESC))); packing_append_buffer(pkg_archive, pkg_get(pkg, PKG_MTREE), "+MTREE_DIRS", strlen(pkg_get(pkg, PKG_MTREE))); if ((scripts = pkg_scripts(pkg)) != NULL) { for (i = 0; scripts[i] != NULL; i++) { switch (pkg_script_type(scripts[i])) { case PKG_SCRIPT_PRE_INSTALL: scriptname = "+PRE_INSTALL"; break; case PKG_SCRIPT_POST_INSTALL: scriptname = "+POST_INSTALL"; break; case PKG_SCRIPT_INSTALL: scriptname = "+INSTALL"; break; case PKG_SCRIPT_PRE_DEINSTALL: scriptname = "+PRE_DEINSTALL"; break; case PKG_SCRIPT_POST_DEINSTALL: scriptname = "+POST_DEINSTALL"; break; case PKG_SCRIPT_DEINSTALL: scriptname = "+DEINSTALL"; break; case PKG_SCRIPT_PRE_UPGRADE: scriptname = "+PRE_UPGRADE"; break; case PKG_SCRIPT_POST_UPGRADE: scriptname = "+POST_UPGRADE"; break; case PKG_SCRIPT_UPGRADE: scriptname = "+UPGRADE"; break; } packing_append_buffer(pkg_archive, pkg_script_data(scripts[i]), scriptname, strlen(pkg_script_data(scripts[i]))); } } if ((files = pkg_files(pkg)) != NULL) { for (i = 0; files[i] != NULL; i++) { if (root != NULL) snprintf(fpath, sizeof(MAXPATHLEN), "%s%s", root, pkg_file_path(files[i])); else strlcpy(fpath, pkg_file_path(files[i]), MAXPATHLEN); packing_append_file(pkg_archive, fpath, pkg_file_path(files[i])); } } return (EPKG_OK); }
static int pkg_create_from_dir(struct pkg *pkg, const char *root, struct packing *pkg_archive) { char fpath[MAXPATHLEN + 1]; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; char *m; int ret; const char *mtree; bool developer; struct stat st; char sha256[SHA256_DIGEST_LENGTH * 2 + 1]; if (pkg_is_valid(pkg) != EPKG_OK) { pkg_emit_error("the package is not valid"); return (EPKG_FATAL); } /* * if the checksum is not provided in the manifest recompute it */ while (pkg_files(pkg, &file) == EPKG_OK) { const char *pkg_path = pkg_file_path(file); const char *pkg_sum = pkg_file_cksum(file); if (root != NULL) snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_path); else strlcpy(fpath, pkg_path, sizeof(fpath)); if ((pkg_sum == NULL || pkg_sum[0] == '\0') && lstat(fpath, &st) == 0 && !S_ISLNK(st.st_mode)) { if (sha256_file(fpath, sha256) != EPKG_OK) return (EPKG_FATAL); strlcpy(file->sum, sha256, sizeof(file->sum)); } } /* * Register shared libraries used by the package if SHLIBS * enabled in conf. Deletes shlib info if not. */ pkg_register_shlibs(pkg); pkg_emit_manifest(pkg, &m); packing_append_buffer(pkg_archive, m, "+MANIFEST", strlen(m)); free(m); pkg_get(pkg, PKG_MTREE, &mtree); if (mtree != NULL) packing_append_buffer(pkg_archive, mtree, "+MTREE_DIRS", strlen(mtree)); while (pkg_files(pkg, &file) == EPKG_OK) { const char *pkg_path = pkg_file_path(file); if (root != NULL) snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_path); else strlcpy(fpath, pkg_path, sizeof(fpath)); ret = packing_append_file_attr(pkg_archive, fpath, pkg_path, file->uname, file->gname, file->perm); pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer); if (developer && ret != EPKG_OK) return (ret); } while (pkg_dirs(pkg, &dir) == EPKG_OK) { const char *pkg_path = pkg_dir_path(dir); if (root != NULL) snprintf(fpath, sizeof(fpath), "%s%s", root, pkg_path); else strlcpy(fpath, pkg_dir_path(dir), sizeof(fpath)); ret = packing_append_file_attr(pkg_archive, fpath, pkg_path, dir->uname, dir->gname, dir->perm); pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &developer); if (developer && ret != EPKG_OK) return (ret); } return (EPKG_OK); }