From af500cd09d5331898452c7951a557e316e9a10de Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Tue, 12 Jul 2022 14:58:13 +0200 Subject: [PATCH] solv: add plaindir repo support --- examples/solv/CMakeLists.txt | 1 + examples/solv/repoinfo.c | 6 ++ examples/solv/repoinfo_download.c | 4 ++ examples/solv/repoinfo_type_plaindir.c | 79 ++++++++++++++++++++++++++ examples/solv/repoinfo_type_plaindir.h | 1 + 5 files changed, 91 insertions(+) create mode 100644 examples/solv/repoinfo_type_plaindir.c create mode 100644 examples/solv/repoinfo_type_plaindir.h diff --git a/examples/solv/CMakeLists.txt b/examples/solv/CMakeLists.txt index 0f3bd477..72deb4a9 100644 --- a/examples/solv/CMakeLists.txt +++ b/examples/solv/CMakeLists.txt @@ -18,6 +18,7 @@ repoinfo_system_rpm.c repoinfo_type_debian.c repoinfo_type_mdk.c repoinfo_type_rpmmd.c +repoinfo_type_plaindir.c repoinfo_type_susetags.c ) diff --git a/examples/solv/repoinfo.c b/examples/solv/repoinfo.c index 62739728..f7c33460 100644 --- a/examples/solv/repoinfo.c +++ b/examples/solv/repoinfo.c @@ -47,6 +47,7 @@ #ifdef ENABLE_MDKREPO #include "repoinfo_type_mdk.h" #endif +#include "repoinfo_type_plaindir.h" static int repoinfos_sort_cmp(const void *ap, const void *bp) @@ -252,6 +253,11 @@ read_repos(Pool *pool, struct repoinfo *repoinfos, int nrepoinfos) switch (cinfo->type) { +#if defined(ENABLE_RPMDB) || defined(ENABLE_RPMPKG) + case TYPE_PLAINDIR: + plaindir_load(cinfo, &sigpool); + break; +#endif #ifdef ENABLE_RPMMD case TYPE_RPMMD: repomd_load(cinfo, &sigpool); diff --git a/examples/solv/repoinfo_download.c b/examples/solv/repoinfo_download.c index f5ba8b90..2a266298 100644 --- a/examples/solv/repoinfo_download.c +++ b/examples/solv/repoinfo_download.c @@ -194,6 +194,10 @@ downloadpackage(Solvable *s, const char *loc) const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR); loc = pool_tmpjoin(s->repo->pool, datadir ? datadir : "suse", "/", loc); } + else if (cinfo->type == TYPE_PLAINDIR) + { + return fopen(loc, "r"); + } #endif chksumtype = 0; chksum = solvable_lookup_bin_checksum(s, SOLVABLE_CHECKSUM, &chksumtype); diff --git a/examples/solv/repoinfo_type_plaindir.c b/examples/solv/repoinfo_type_plaindir.c new file mode 100644 index 00000000..9c53e277 --- /dev/null +++ b/examples/solv/repoinfo_type_plaindir.c @@ -0,0 +1,79 @@ +#if defined(ENABLE_RPMDB) || defined(ENABLE_RPMPKG) + +#include +#include +#include +#include +#include + +#include "pool.h" +#include "repo.h" + +#ifdef SUSE +#include "repo_autopattern.h" +#endif +#include "repoinfo.h" +#include "repoinfo_cache.h" +#include "repoinfo_download.h" +#include "repoinfo_type_rpmmd.h" +#include "ext/repo_rpmdb.h" + +static inline int endswith(const char* str, const char* suf) +{ + if (strlen(str) < strlen(suf)) + return 0; + return strcmp(str + strlen(str) - strlen(suf), suf) == 0; +} + +int +plaindir_load(struct repoinfo *cinfo, Pool **sigpoolp) +{ + Repo *repo = cinfo->repo; + Repodata *data; + DIR *dp; + struct dirent *de; + struct stat stb; + + printf("plaindir repo '%s':", cinfo->alias); + fflush(stdout); + if (stat(cinfo->path, &stb)) + { + perror(cinfo->path); + return -1; + } + calc_cookie_stat(&stb, REPOKEY_TYPE_SHA256, NULL, cinfo->cookie); + cinfo->cookieset = 1; + if (usecachedrepo(cinfo, 0, 1)) + { + printf(" cached\n"); + return 1; + } + printf(" reading\n"); + if ((dp = opendir(cinfo->path)) == 0) + { + perror(cinfo->path); + return -1; + } + while ((de = readdir(dp)) != 0) + { + if (de->d_name[0] == 0 || de->d_name[0] == '.') + continue; + if (!endswith(de->d_name, ".rpm") || endswith(de->d_name, ".delta.rpm") || endswith(de->d_name, ".patch.rpm")) + continue; + char* fn = solv_dupjoin(cinfo->path, "/", de->d_name); + repo_add_rpm(repo, fn, 0); + solv_free(fn); + } + closedir(dp); + +#ifdef SUSE + repo_add_autopattern(repo, 0); +#endif + data = repo_add_repodata(repo, 0); + repodata_internalize(data); + writecachedrepo(cinfo, 0, 0); + repodata_create_stubs(repo_last_repodata(repo)); + return 1; +} + +#endif diff --git a/examples/solv/repoinfo_type_plaindir.h b/examples/solv/repoinfo_type_plaindir.h new file mode 100644 index 00000000..15fa7c7c --- /dev/null +++ b/examples/solv/repoinfo_type_plaindir.h @@ -0,0 +1 @@ +extern int plaindir_load(struct repoinfo *cinfo, Pool **sigpoolp); -- 2.47.2