mirror of
https://github.com/openSUSE/libsolv.git
synced 2026-02-05 12:45:46 +01:00
solv: add plaindir repo support
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
79
examples/solv/repoinfo_type_plaindir.c
Normal file
79
examples/solv/repoinfo_type_plaindir.c
Normal file
@@ -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
|
||||
1
examples/solv/repoinfo_type_plaindir.h
Normal file
1
examples/solv/repoinfo_type_plaindir.h
Normal file
@@ -0,0 +1 @@
|
||||
extern int plaindir_load(struct repoinfo *cinfo, Pool **sigpoolp);
|
||||
Reference in New Issue
Block a user