#include "repo.h"
#include "repo_rpmmd.h"
#include "common_write.h"
+#include "solv_xfopen.h"
-static ssize_t
-cookie_gzread(void *cookie, char *buf, size_t nbytes)
-{
- return gzread((gzFile *)cookie, buf, nbytes);
-}
-
-static int
-cookie_gzclose(void *cookie)
-{
- return gzclose((gzFile *)cookie);
-}
-
-FILE *
-myfopen(const char *fn)
-{
- cookie_io_functions_t cio;
- char *suf;
- gzFile *gzf;
-
- if (!fn)
- return 0;
- suf = strrchr(fn, '.');
- if (!suf || strcmp(suf, ".gz") != 0)
- return fopen(fn, "r");
- gzf = gzopen(fn, "r");
- if (!gzf)
- return 0;
- memset(&cio, 0, sizeof(cio));
- cio.read = cookie_gzread;
- cio.close = cookie_gzclose;
- return fopencookie(gzf, "r", cio);
-}
-
static void
usage(int status)
{
int l;
char *fnp;
l = strlen(dir) + 128;
- fnp = sat_malloc(l+1);
+ fnp = solv_malloc(l+1);
snprintf(fnp, l, "%s/primary.xml.gz", dir);
- if (!(fp = myfopen(fnp)))
+ if (!(fp = solv_xfopen(fnp, 0)))
{
perror(fnp);
exit(1);
}
- repo_add_rpmmd(repo, fp, 0, flags);
+ if (repo_add_rpmmd(repo, fp, 0, flags))
+ {
+ fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+ exit(1);
+ }
fclose(fp);
snprintf(fnp, l, "%s/diskusagedata.xml.gz", dir);
- if ((fp = myfopen(fnp)))
+ if ((fp = solv_xfopen(fnp, 0)))
{
- repo_add_rpmmd(repo, fp, 0, flags);
+ if (repo_add_rpmmd(repo, fp, 0, flags))
+ {
+ fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+ exit(1);
+ }
fclose(fp);
}
if (locale)
fprintf(stderr, "-l parameter too long\n");
exit(1);
}
- while (!(fp = myfopen(fnp)))
+ while (!(fp = solv_xfopen(fnp, 0)))
{
fprintf(stderr, "not opened %s\n", fnp);
if (strlen(locale) > 2)
fprintf(stderr, "-l parameter too long\n");
exit(1);
}
- if ((fp = myfopen(fnp)))
+ if ((fp = solv_xfopen(fnp, 0)))
break;
}
perror(fnp);
exit(1);
}
fprintf(stderr, "opened %s\n", fnp);
- repo_add_rpmmd(repo, fp, 0, flags);
+ if (repo_add_rpmmd(repo, fp, 0, flags))
+ {
+ fprintf(stderr, "rpmmd2solv: %s: %s\n", fnp, pool_errstr(pool));
+ exit(1);
+ }
fclose(fp);
}
- sat_free(fnp);
+ solv_free(fnp);
}
else
- repo_add_rpmmd(repo, stdin, 0, flags);
+ {
+ if (repo_add_rpmmd(repo, stdin, 0, flags))
+ {
+ fprintf(stderr, "rpmmd2solv: %s\n", pool_errstr(pool));
+ exit(1);
+ }
+ }
tool_write(repo, basefile, attrname);
pool_free(pool);
exit(0);