static inline int
iscompressed(const char *name)
{
- int l = strlen(name);
- return l > 3 && !strcmp(name + l - 3, ".gz") ? 1 : 0;
+ return solv_xfopen_iscompressed(name) != 0;
}
FILE *
curlfopen(struct repoinfo *cinfo, const char *file, int uncompress, const unsigned char *chksum, Id chksumtype, int *badchecksump)
{
+ FILE *fp;
pid_t pid;
int fd, l;
int status;
return 0;
if (file != cinfo->metalink && file != cinfo->mirrorlist)
{
- FILE *fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
unsigned char mlchksum[32];
+ fp = curlfopen(cinfo, cinfo->metalink ? cinfo->metalink : cinfo->mirrorlist, 0, 0, 0, 0);
Id mlchksumtype = 0;
if (!fp)
return 0;
close(fd);
return 0;
}
- if (uncompress)
- return solv_xfopen_fd(".gz", fd, "r");
fcntl(fd, F_SETFD, FD_CLOEXEC);
- return fdopen(fd, "r");
+ if (uncompress)
+ {
+ if (solv_xfopen_iscompressed(file) < 0)
+ {
+ printf("%s: unsupported compression\n", file);
+ if (badchecksump)
+ *badchecksump = 1;
+ close(fd);
+ return 0;
+ }
+ fp = solv_xfopen_fd(file, fd, "r");
+ }
+ else
+ fp = fdopen(fd, "r");
+ if (!fp)
+ close(fd);
+ return fp;
}
#ifndef DEBIAN
return myxzfopen(fn, mode);
if (suf && !strcmp(suf, ".lzma"))
return mylzfopen(fn, mode);
+#else
+ if (suf && !strcmp(suf, ".xz"))
+ return 0;
+ if (suf && !strcmp(suf, ".lzma"))
+ return 0;
#endif
#ifdef ENABLE_BZIP2_COMPRESSION
if (suf && !strcmp(suf, ".bz2"))
return mybzfopen(fn, mode);
+#else
+ if (suf && !strcmp(suf, ".bz2"))
+ return 0;
#endif
return fopen(fn, mode);
}
return myxzfdopen(fd, simplemode);
if (suf && !strcmp(suf, ".lzma"))
return mylzfdopen(fd, simplemode);
+#else
+ if (suf && !strcmp(suf, ".xz"))
+ return 0;
+ if (suf && !strcmp(suf, ".lzma"))
+ return 0;
#endif
#ifdef ENABLE_BZIP2_COMPRESSION
if (suf && !strcmp(suf, ".bz2"))
return mybzfdopen(fd, simplemode);
+#else
+ if (suf && !strcmp(suf, ".bz2"))
+ return 0;
#endif
return fdopen(fd, mode);
}
+int
+solv_xfopen_iscompressed(const char *fn)
+{
+ const char *suf = fn ? strrchr(fn, '.') : 0;
+ if (!suf)
+ return 0;
+ if (!strcmp(suf, ".gz"))
+ return 1;
+ if (!strcmp(suf, ".xz") || !strcmp(suf, ".lzma"))
+#ifdef ENABLE_LZMA_COMPRESSION
+ return 1;
+#else
+ return -1;
+#endif
+ if (!strcmp(suf, ".bz2"))
+#ifdef ENABLE_BZIP2_COMPRESSION
+ return 1;
+#else
+ return -1;
+#endif
+ return 0;
+}
+
struct bufcookie {
char **bufp;
size_t *buflp;
extern FILE *solv_xfopen(const char *fn, const char *mode);
extern FILE *solv_xfopen_fd(const char *fn, int fd, const char *mode);
extern FILE *solv_xfopen_buf(const char *fn, char **bufp, size_t *buflp, const char *mode);
+extern int solv_xfopen_iscompressed(const char *fn);
#endif