diff options
author | Michael Schroeder <mls@suse.de> | 2012-03-30 14:12:54 +0200 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2012-03-30 14:12:54 +0200 |
commit | 26e6c508d2a971dd8f16e6ba984e76cbe1f82a55 (patch) | |
tree | ee8151ffb27aed33c98dbe9a7852262bcf47c0ef /tools | |
parent | c36ef29531924b0a2ec37cdac57211dac32837b1 (diff) | |
download | libsolv-26e6c508d2a971dd8f16e6ba984e76cbe1f82a55.tar.gz libsolv-26e6c508d2a971dd8f16e6ba984e76cbe1f82a55.tar.bz2 libsolv-26e6c508d2a971dd8f16e6ba984e76cbe1f82a55.zip |
- add support for archlinux packages/repos
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tools/archpkgs2solv.c | 129 | ||||
-rw-r--r-- | tools/archrepo2solv.c | 68 | ||||
-rw-r--r-- | tools/mdk2solv.c | 2 |
4 files changed, 208 insertions, 1 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 86f804d..d5173ae 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -69,6 +69,16 @@ TARGET_LINK_LIBRARIES (mdk2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES} SET (tools_list ${tools_list} mdk2solv) ENDIF (ENABLE_MDKREPO) +IF (ENABLE_ARCHREPO) +ADD_EXECUTABLE (archpkgs2solv archpkgs2solv.c) +TARGET_LINK_LIBRARIES (archpkgs2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES}) + +ADD_EXECUTABLE (archrepo2solv archrepo2solv.c) +TARGET_LINK_LIBRARIES (archrepo2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES}) + +SET (tools_list ${tools_list} archpkgs2solv archrepo2solv) +ENDIF (ENABLE_ARCHREPO) + ADD_EXECUTABLE (installcheck installcheck.c) TARGET_LINK_LIBRARIES (installcheck libsolvext libsolv ${SYSTEM_LIBRARIES}) diff --git a/tools/archpkgs2solv.c b/tools/archpkgs2solv.c new file mode 100644 index 0000000..d2e19c6 --- /dev/null +++ b/tools/archpkgs2solv.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2012, Novell Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +/* + * archpkgs2solv - create a solv file from multiple arch packages + * + */ + +#include <sys/types.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include "util.h" +#include "pool.h" +#include "repo.h" +#include "repo_arch.h" +#include "repo_solv.h" +#include "common_write.h" + +static char * +fgets0(char *s, int size, FILE *stream) +{ + char *p = s; + int c; + + while (--size > 0) + { + c = getc(stream); + if (c == EOF) + { + if (p == s) + return 0; + c = 0; + } + *p++ = c; + if (!c) + return s; + } + *p = 0; + return s; +} + +int +main(int argc, char **argv) +{ + const char **pkgs = 0; + char *manifest = 0; + int manifest0 = 0; + int i, c, npkgs = 0; + Pool *pool = pool_create(); + Repo *repo; + FILE *fp; + char buf[4096], *p; + const char *basefile = 0; + int flags = 0; + + while ((c = getopt(argc, argv, "0b:m:i")) >= 0) + { + switch(c) + { + case 'b': + basefile = optarg; + break; + case 'm': + manifest = optarg; + break; + case '0': + manifest0 = 1; + break; + case 'i': + flags |= ARCH_ADD_WITH_PKGID; + break; + default: + exit(1); + } + } + if (manifest) + { + if (!strcmp(manifest, "-")) + fp = stdin; + else if ((fp = fopen(manifest, "r")) == 0) + { + perror(manifest); + exit(1); + } + for (;;) + { + if (manifest0) + { + if (!fgets0(buf, sizeof(buf), fp)) + break; + } + else + { + if (!fgets(buf, sizeof(buf), fp)) + break; + if ((p = strchr(buf, '\n')) != 0) + *p = 0; + } + pkgs = solv_extend(pkgs, npkgs, 1, sizeof(char *), 15); + pkgs[npkgs++] = strdup(buf); + } + if (fp != stdin) + fclose(fp); + } + while (optind < argc) + { + pkgs = solv_extend(pkgs, npkgs, 1, sizeof(char *), 15); + pkgs[npkgs++] = solv_strdup(argv[optind++]); + } + repo = repo_create(pool, "archpkgs2solv"); + repo_add_repodata(repo, 0); + for (i = 0; i < npkgs; i++) + repo_add_arch_pkg(repo, pkgs[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|flags); + repo_internalize(repo); + tool_write(repo, basefile, 0); + pool_free(pool); + for (c = 0; c < npkgs; c++) + solv_free((char *)pkgs[c]); + solv_free(pkgs); + exit(0); +} + diff --git a/tools/archrepo2solv.c b/tools/archrepo2solv.c new file mode 100644 index 0000000..e671c49 --- /dev/null +++ b/tools/archrepo2solv.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012, Novell Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +/* + * archrepo2solv.c + * + * parse archlinux repo file + * + * reads from stdin + * writes to stdout + */ + +#include <sys/types.h> +#include <limits.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#include "pool.h" +#include "repo.h" +#include "repo_arch.h" +#include "solv_xfopen.h" +#include "common_write.h" + + +static void +usage(int status) +{ + fprintf(stderr, "\nUsage:\n" + "archrepo2solv\n" + " reads a repository from <stdin> and writes a .solv file to <stdout>\n" + " -h : print help & exit\n" + ); + exit(status); +} + +int +main(int argc, char **argv) +{ + Pool *pool; + Repo *repo; + int c; + + while ((c = getopt(argc, argv, "h")) >= 0) + { + switch(c) + { + case 'h': + usage(0); + break; + default: + usage(1); + break; + } + } + pool = pool_create(); + repo = repo_create(pool, "<stdin>"); + repo_add_arch_repo(repo, stdin, 0); + tool_write(repo, 0, 0); + pool_free(pool); + exit(0); +} diff --git a/tools/mdk2solv.c b/tools/mdk2solv.c index db6c97b..cec705e 100644 --- a/tools/mdk2solv.c +++ b/tools/mdk2solv.c @@ -49,7 +49,7 @@ main(int argc, char **argv) char *infofile; int c; - while ((c = getopt(argc, argv, "i:")) >= 0) + while ((c = getopt(argc, argv, "hi:")) >= 0) { switch(c) { |