diff options
author | Michael Schroeder <mls@suse.de> | 2012-11-12 15:45:31 +0100 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2012-11-12 15:45:31 +0100 |
commit | bed337587c8e10acd0a3bcd7b2d43dc747a0b290 (patch) | |
tree | d374b58619db52bacbeb043ac186180a72024e24 /tools | |
parent | daad86c69b2709ffa1613e2dbea4a3c309e2c0fc (diff) | |
download | libsolv-bed337587c8e10acd0a3bcd7b2d43dc747a0b290.tar.gz libsolv-bed337587c8e10acd0a3bcd7b2d43dc747a0b290.tar.bz2 libsolv-bed337587c8e10acd0a3bcd7b2d43dc747a0b290.zip |
add deb2solv for completeness
Diffstat (limited to 'tools')
-rw-r--r-- | tools/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tools/deb2solv.c | 132 |
2 files changed, 139 insertions, 0 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9fca9c6..60406df 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -68,6 +68,13 @@ TARGET_LINK_LIBRARIES (comps2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIE SET (tools_list ${tools_list} comps2solv) ENDIF (ENABLE_COMPS) +IF (ENABLE_DEBIAN) +ADD_EXECUTABLE (deb2solv deb2solv.c) +TARGET_LINK_LIBRARIES (deb2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES}) + +SET (tools_list ${tools_list} deb2solv) +ENDIF (ENABLE_DEBIAN) + IF (ENABLE_MDKREPO) ADD_EXECUTABLE (mdk2solv mdk2solv.c) TARGET_LINK_LIBRARIES (mdk2solv toolstuff libsolvext libsolv ${SYSTEM_LIBRARIES}) diff --git a/tools/deb2solv.c b/tools/deb2solv.c new file mode 100644 index 0000000..0d22f24 --- /dev/null +++ b/tools/deb2solv.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2007, Novell Inc. + * + * This program is licensed under the BSD license, read LICENSE.BSD + * for further information + */ + +/* + * deb2solv - create a solv file from one or multiple debs + * + */ + +#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_deb.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 **debs = 0; + char *manifest = 0; + int manifest0 = 0; + int c, i, res, ndebs = 0; + Pool *pool = pool_create(); + Repo *repo; + FILE *fp; + char buf[4096], *p; + const char *basefile = 0; + + while ((c = getopt(argc, argv, "0b:m:")) >= 0) + { + switch(c) + { + case 'b': + basefile = optarg; + break; + case 'm': + manifest = optarg; + break; + case '0': + manifest0 = 1; + 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; + } + debs = solv_extend(debs, ndebs, 1, sizeof(char *), 15); + debs[ndebs++] = strdup(buf); + } + if (fp != stdin) + fclose(fp); + } + while (optind < argc) + { + debs = solv_extend(debs, ndebs, 1, sizeof(char *), 15); + debs[ndebs++] = strdup(argv[optind++]); + } + repo = repo_create(pool, "deb2solv"); + repo_add_repodata(repo, 0); + res = 0; + for (i = 0; i < ndebs; i++) + { + if (repo_add_deb(repo, debs[i], REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE) == 0) + { + fprintf(stderr, "deb2solv: %s\n", pool_errstr(pool)); + res = 1; + } + } + repo_internalize(repo); + tool_write(repo, basefile, 0); + pool_free(pool); + for (c = 0; c < ndebs; c++) + free((char *)debs[c]); + solv_free(debs); + exit(res); +} + |