]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
solv: add plaindir repo support
authorLudwig Nussel <ludwig.nussel@suse.de>
Tue, 12 Jul 2022 12:58:13 +0000 (14:58 +0200)
committerLudwig Nussel <ludwig.nussel@suse.de>
Wed, 13 Jul 2022 14:17:25 +0000 (16:17 +0200)
examples/solv/CMakeLists.txt
examples/solv/repoinfo.c
examples/solv/repoinfo_download.c
examples/solv/repoinfo_type_plaindir.c [new file with mode: 0644]
examples/solv/repoinfo_type_plaindir.h [new file with mode: 0644]

index 0f3bd4770de3b3f0c66e2a123341b6280e175f9f..72deb4a9478be40075a341fdcc37051c466a852e 100644 (file)
@@ -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
 )
 
index 62739728034f05fff5d756e8f57e0102914e76a9..f7c33460e3e40916e940da41ce0dea0a54d2d2d3 100644 (file)
@@ -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);
index f5ba8b9020adcad7261dad4f235d65385ef24393..2a2662982e2c7ec258de96bade90bb00ef788d46 100644 (file)
@@ -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 (file)
index 0000000..9c53e27
--- /dev/null
@@ -0,0 +1,79 @@
+#if defined(ENABLE_RPMDB) || defined(ENABLE_RPMPKG)
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#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 (file)
index 0000000..15fa7c7
--- /dev/null
@@ -0,0 +1 @@
+extern int plaindir_load(struct repoinfo *cinfo, Pool **sigpoolp);