void add_dependencies(const PackageManifest& p, unsigned level, bool include_build, bool is_native) { for (const auto& dep : p.dependencies()) { if( dep.is_disabled() ) { continue ; } DEBUG(p.name() << ": Dependency " << dep.name()); add_package(dep.get_package(), level+1, include_build, is_native); } if( p.build_script() != "" && include_build ) { for(const auto& dep : p.build_dependencies()) { if( dep.is_disabled() ) { continue ; } DEBUG(p.name() << ": Build Dependency " << dep.name()); add_package(dep.get_package(), level+1, true, true); } } }
void use_package(char* name) { package_t* package; list_node* node; int got_one = 0; DEBUG(stderr, "using package `%s'...\n", name); for (node = head(the_packages) ; node ; node = next(node)) { package = (package_t*) get_value(node); if (package_matches(package, name, the_host_info.machine, the_host_info.sysname, the_host_info.release, the_host_info.nodename, the_shell)) { add_package(package); got_one = 1; } } if ((!silent) && (!got_one)) fprintf(stderr, "warning: no match for package `%s' on this host.\n", name); }
void create_packages_from_argv(int argc, char **argv, int *index) { char *cwd = getcwd(0, 0); package_ptr p; char file_buffer[256]; int i = *index - 1, c=0; while (i < argc && *argv[i] != '-') { p = alloc_package(); if (*argv[i] == '/') { strcpy(p->file, argv[i]); } else { snprintf(file_buffer, sizeof(file_buffer), "%s/%s", cwd, argv[i]); strcpy(p->file, file_buffer); } strcpy(p->package, argv[i]); add_package(&packages, p); (*index)++; i++; c++; } (*index)--; // for(p=packages; p!= NULL; p=p->next) // printf("%d package: %s %s\n", c, p->package, p->file); }
void FeedParser::parse_packages(XmlReader& xml, Package group) { while (xml.start_element()) { std::string name = xml.name(); std::string namespace_uri = xml.namespace_uri(); if (name == "group" && namespace_uri == project_ns) { parse_package_fields(xml, group); parse_packages(xml, group); } else if (name == "package" && namespace_uri == project_ns) { parse_package_fields(xml, group); add_package(group); } xml.skip(); } }
static int read_pkgdb_from_file(FILE *f, struct pkgdb *db) { char line[STRLEN]; while (fgets(line, STRLEN, f)) { char *p = line; char *name = NULL; char *inffile = NULL; char *description = NULL; char *time = NULL; name = strsep(&p, "\t\n"); inffile = strsep(&p, "\t\n"); description = strsep(&p, "\t\n"); time = strsep(&p, "\t\n"); if (name) { struct pkg *pkg = add_package(db, name, description); if (inffile) pkg->inffile = strdup(inffile); if (time) pkg->time = atoi(time); } } db->dirty = 0; return 0; }
void yf::LoadBalance::Impl::process(mp::Package &package) { bool is_closed_front = false; // checking for closed front end packages if (package.session().is_closed()) { is_closed_front = true; } Z_GDU *gdu_req = package.request().get(); // passing anything but z3950 packages if (gdu_req && gdu_req->which == Z_GDU_Z3950) { // target selecting only on Z39.50 init request if (gdu_req->u.z3950->which == Z_APDU_initRequest) { yazpp_1::GDU base_req(gdu_req); Z_APDU *apdu = base_req.get()->u.z3950; Z_InitRequest *org_init = base_req.get()->u.z3950->u.initRequest; mp::odr odr_en(ODR_ENCODE); std::list<std::string> vhosts; mp::util::remove_vhost_otherinfo(&(org_init->otherInfo), vhosts); // get lowest of all vhosts.. Remove them if individually if // they turn out to be bad.. while (1) { std::list<std::string>::iterator ivh = vhosts.begin(); std::list<std::string>::iterator ivh_pick = vhosts.end(); Package init_pkg(package.session(), package.origin()); init_pkg.copy_filter(package); unsigned int cost_i = std::numeric_limits<unsigned int>::max(); { boost::mutex::scoped_lock scoped_lock(m_mutex); for (; ivh != vhosts.end(); ivh++) { if ((*ivh).size() != 0) { unsigned int cost = yf::LoadBalance::Impl::cost(*ivh); std::ostringstream os; os << "LB" << " " << package << " " << "0.000000" << " " << "Consider " << *ivh << " cost=" << cost; yaz_log(YLOG_LOG, "%s", os.str().c_str()); if (cost_i > cost) { ivh_pick = ivh; cost_i = cost; } } } } if (ivh_pick == vhosts.end()) break; std::string target = *ivh_pick; vhosts.erase(ivh_pick); // copying new target into init package yazpp_1::GDU init_gdu(base_req); Z_InitRequest *init_req = init_gdu.get()->u.z3950->u.initRequest; mp::util::set_vhost_otherinfo(&(init_req->otherInfo), odr_en, target, 1); init_pkg.request() = init_gdu; // moving all package types init_pkg.move(); // checking for closed back end packages if (!init_pkg.session().is_closed()) { add_session(package.session().id(), target); package.response() = init_pkg.response(); return; } std::ostringstream os; os << "LB" << " " << package << " " << "0.000000" << " " << "Failed " << target; yaz_log(YLOG_LOG, "%s", os.str().c_str()); } mp::odr odr; package.response() = odr.create_initResponse( apdu, YAZ_BIB1_TEMPORARY_SYSTEM_ERROR, "load_balance: no available targets"); package.session().close(); return; } // frontend Z39.50 close request is added to statistics and marked else if (gdu_req->u.z3950->which == Z_APDU_close) { is_closed_front = true; boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); } // any other Z39.50 package is added to statistics else { boost::mutex::scoped_lock scoped_lock(m_mutex); add_package(package.session().id()); } } // moving all package types package.move(); bool is_closed_back = false; // checking for closed back end packages if (package.session().is_closed()) is_closed_back = true; Z_GDU *gdu_res = package.response().get(); // passing anything but z3950 packages if (gdu_res && gdu_res->which == Z_GDU_Z3950) { // session closing only on Z39.50 close response if (gdu_res->u.z3950->which == Z_APDU_close) { is_closed_back = true; boost::mutex::scoped_lock scoped_lock(m_mutex); remove_package(package.session().id()); } // any other Z39.50 package is removed from statistics else { boost::mutex::scoped_lock scoped_lock(m_mutex); remove_package(package.session().id()); } } // finally removing sessions and marking deads if (is_closed_back || is_closed_front) { boost::mutex::scoped_lock scoped_lock(m_mutex); // marking backend dead if backend closed without fronted close if (is_closed_front == false) add_dead(package.session().id()); remove_session(package.session().id()); // making sure that package is closed package.session().close(); } }
static int install_package(char *pkgname, struct pkgdb *db, int options) { char url[STRLEN]; FILE *f; int rc; char inffile[STRLEN]; struct section *manifest; struct section *dep; struct section *build; struct pkg *pkg; char *description; int time; // Check if package is already installed if (!(options & FROM_FILE)) { pkg = find_package(db, pkgname); if (pkg) { if (options & UPGRADE) { if (pkg->time == pkg->avail) return 0; } else if (options & DEPENDENCY) { return 0; } else if (options & UPDATE) { if (options & VERBOSE) printf("updating package %s\n", pkgname); } else { printf("package %s is already installed\n", pkgname); return 0; } } } // Open package file printf("Fetching %s\n", pkgname); if (options & FROM_FILE) { snprintf(url, sizeof(url), "file:///%s", pkgname); } else { snprintf(url, sizeof(url), "%s/%s.pkg", db->repo, pkgname); } if (options & VERBOSE) printf("fetching package %s from %s\n", pkgname, url); f = open_url(url, "pkg"); if (!f) return 1; // Extract file from package file time = 0; rc = extract_files(url, f, inffile, options & VERBOSE, &time); fclose(f); if (rc != 0) return rc; // Read manifest if (options & VERBOSE) printf("reading manifest from %s\n", inffile); manifest = read_properties(inffile); if (!manifest) { fprintf(stderr, "%s: unable to read manifest\n", inffile); return 1; } // Add package to package database pkgname = get_property(manifest, "package", "name", pkgname); description = get_property(manifest, "package", "description", NULL); pkg = find_package(db, pkgname); if (pkg) { if (options & VERBOSE) printf("updating package %s in database\n", pkgname); if (description) { free(pkg->description); pkg->description = strdup(description); db->dirty = 1; } if (pkg->manifest) free_properties(pkg->manifest); free(pkg->inffile); } else { if (options & VERBOSE) printf("adding package %s to database\n", pkgname); pkg = add_package(db, pkgname, description); } pkg->inffile = strdup(inffile); pkg->manifest = manifest; if (time != pkg->time) { pkg->time = time; db->dirty = 1; } // Install package dependencies dep = find_section(manifest, "dependencies"); if (dep) { struct property *p; for (p = dep->properties; p; p = p->next) { if (options & VERBOSE) printf("package %s depends on %s\n", pkgname, p->name); rc = install_package(p->name, db, options | DEPENDENCY); if (rc != 0) return rc; } } if ((options & ONLY_FETCH) && !(options & DEPENDENCY)) return 0; // Run package build/installation commands if (!(options & ONLY_FETCH) || (options & DEPENDENCY)) { build = find_section(manifest, (options & ONLY_BUILD) && !(options & DEPENDENCY) ? "build" : "install"); if (build) { struct property *p; printf((options & ONLY_BUILD) && !(options & DEPENDENCY) ? "Building %s\n" : "Installing %s\n", pkgname); for (p = build->properties; p; p = p->next) { if (options & VERBOSE) printf("%s\n", p->name); rc = system(p->name); if (rc != 0) { fprintf(stderr, "%s: build failed\n", pkgname); return rc; } } } } return 0; }
/** \brief Add a package by package name, and option version */ void package_list::add_package( const std::string& package, const std::string& version, const bool force_reinstall ) { const wpkg_filename::uri_filename pck(package); list_t::const_iterator item(find_package_item(pck)); if(item != f_packages.end()) { // the user is trying to install the same package twice // (ignore if that's exactly the same one) if(item->get_type() != package_item_t::package_type_explicit) { wpkg_output::log("package %1 defined twice on your command line using two different paths.") .quoted_arg(package) .level(wpkg_output::level_error) .module(wpkg_output::module_validate_installation) .package(package) .action("install-validation"); } } else { if( pck.extension() == "deb") { // this is an explicit package package_item_t package_item( f_manager, pck ); f_packages.push_back(package_item); } else { wpkgar_repository repository( f_manager ); typedef std::map<std::string,wpkgar_repository::package_item_t> version_package_map_t; version_package_map_t version_map; for( const auto& entry : repository.upgrade_list() ) { if( entry.get_name() == package ) { version_map[entry.get_version()] = entry; } } if( version_map.empty() ) { std::stringstream ss; ss << "Cannot install package '" << package << "' because it doesn't exist in the repository!"; throw std::runtime_error(ss.str()); } if( version.empty() ) { auto greatest_version( version_map.rbegin()->first ); if( version_map.size() > 1 ) { wpkg_output::log("package '%1' has multiple versions available in the selected repositories. Selected the greatest version '%2'.") .quoted_arg(package) .quoted_arg(greatest_version) .level(wpkg_output::level_warning) .module(wpkg_output::module_validate_installation) .package(package) .action("install-validation"); } // Select the greatest version // add_package( version_map.rbegin()->second, force_reinstall ); } else { add_package( version_map[version], force_reinstall ); } } } }
TEST(database, add_package){ TEST_ASSERT_EQUAL(SQLITE_OK,add_package(&package)); }