TEST(database, find_package){ Package* p=find_package("gcc"); TEST_ASSERT_TRUE(p); TEST_ASSERT_EQUAL_STRING(package.name, p->name); TEST_ASSERT_EQUAL_STRING(package.description, p->description); TEST_ASSERT_EQUAL_STRING(package.section, p->section); TEST_ASSERT_EQUAL(package.size, p->size); TEST_ASSERT_EQUAL(package.version, p->version); TEST_ASSERT_EQUAL_STRING(package.web, p->web); TEST_ASSERT_EQUAL_STRING(package.maintainer, p->maintainer); TEST_ASSERT_EQUAL_STRING(package.checksum, p->checksum); free(p); p=find_package("unwanted_package"); TEST_ASSERT_FALSE(p); }
static void fast_read_package(lref_t reader, lref_t * package) { lref_t name; fast_read(reader, &name, false); if (!STRINGP(name)) vmerror_fast_read("packages must have string names", reader, name); *package = find_package(name); if (FALSEP(*package)) vmerror_fast_read("package not found", reader, name); }
BObjectImp* PolSystemExecutorModule::mf_GetPackageByName() { const String* pkgname; if ( !getStringParam(0, pkgname) ) return new BError("Invalid parameter type."); //pkgname->toLower(); Package* pkg = find_package(pkgname->value()); if ( !pkg ) return new BError("No package found by that name."); else return new PackageObjImp(PackagePtrHolder(pkg)); }
Symbol parse_symbol(char *token, Package pkg) { char *pkg_name, *sym_name; token = toupper_string(token); if (is_keyword_token(token)) return gen_keyword(token + 1); if (is_qualified(token, &pkg_name, &sym_name)) { Package pkg; pkg = find_package(pkg_name); return gen_symbol(sym_name, pkg); } else return gen_symbol(token, pkg); }
static int retrieve_package_timestamps(struct pkgdb *db, char *repo) { char url[STRLEN]; FILE *f; struct pkgdb rdb; struct pkg *pkg; struct pkg *rpkg; snprintf(url, sizeof(url), "%s/db", repo); f = open_url(url, "pkg"); if (!f) return 1; memset(&rdb, 0, sizeof(struct pkgdb)); read_pkgdb_from_file(f, &rdb); fclose(f); for (pkg = db->head; pkg; pkg = pkg->next) { rpkg = find_package(&rdb, pkg->name); if (rpkg) pkg->avail = rpkg->time; } delete_pkgdb(&rdb); return 0; }
static int remove_package(char *pkgname, struct pkgdb *db, int options) { struct pkg *pkg; struct section *files; // Find package and load manifest pkg = find_package(db, pkgname); if (!pkg) { fprintf(stderr, "%s: package not found\n", pkgname); return 1; } if (pkg->removed) return 0; if (!pkg->manifest) { if (options & VERBOSE) printf("reading manifest from %s\n", pkg->inffile); pkg->manifest = read_properties(pkg->inffile); if (!pkg->manifest) { fprintf(stderr, "%s: unable to read manifest\n", pkg->inffile); return 1; } } // Remove package files files = find_section(pkg->manifest, "files"); if (files) { struct property *p; for (p = files->properties; p; p = p->next) { remove_path(p->name, options); } } // Remove manifest file unlink(pkg->inffile); // Remove package from package database pkg->removed = 1; db->dirty = 1; return 0; }
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; }