#include "logging.h"
#include "misc.h"
#include "repomd.h"
+#include "compression_wrapper.h"
#define DEFAULT_CHECKSUM "sha256"
#define DEFAULT_CHECKSUM_ENUM_VAL PKG_CHECKSUM_SHA256
-#define GZ_BUFFER_SIZE 131072 // 1024*128
-
+#define BUFFER_SIZE 131072 // 1024 * 128
#define RPM_NS "http://linux.duke.edu/metadata/rpm"
#define XMLNS_NS "http://linux.duke.edu/metadata/repo"
-contentStat *get_gz_compressed_content_stat(const char *filename, ChecksumType checksum_type)
+contentStat *get_compressed_content_stat(const char *filename, ChecksumType checksum_type)
{
if (!g_file_test(filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
return NULL;
// Open compressed file
- gzFile gzfile;
- if (!(gzfile = gzopen(filename, "rb"))) {
+ CW_FILE *cwfile;
+ if (!(cwfile = cw_open(filename, CW_MODE_READ, AUTO_DETECT_COMPRESSION))) {
return NULL;
}
- gzbuffer(gzfile, GZ_BUFFER_SIZE);
// Create checksum structure
long size = 0;
long readed;
- unsigned char buffer[GZ_BUFFER_SIZE];
+ unsigned char buffer[BUFFER_SIZE];
do {
- readed = gzread(gzfile, (void *) buffer, GZ_BUFFER_SIZE);
+ readed = cw_read(cwfile, (void *) buffer, BUFFER_SIZE);
g_checksum_update (checksum, buffer, readed);
size += readed;
- } while (readed == GZ_BUFFER_SIZE);
+ } while (readed == BUFFER_SIZE);
// Create result structure
// Clean up
g_checksum_free(checksum);
- gzclose(gzfile);
+ cw_close(cwfile);
return result;
}
// Compute checksum of non compressed content and its size
if (!md->checksum_open_type || !md->checksum_open || !md->size_open) {
- if (g_str_has_suffix(path, ".gz") || g_str_has_suffix(path, ".gzip")) {
- // File compressed by gzip
+ if (detect_compression(path) != UNKNOWN_COMPRESSION &&
+ detect_compression(path) != NO_COMPRESSION)
+ {
+ // File compressed by supported algorithm
contentStat *open_stat = NULL;
- open_stat = get_gz_compressed_content_stat(path, checksum_t);
+ open_stat = get_compressed_content_stat(path, checksum_t);
md->checksum_open_type = g_string_chunk_insert(md->chunk, checksum_str);
md->checksum_open = g_string_chunk_insert(md->chunk, open_stat->checksum);
if (!md->size_open) {
g_free(open_stat->checksum);
g_free(open_stat);
} else {
- // Unknown suffix -> unknown compression
+ // Unknown compression
g_warning( "File \"%s\" compressed by an unsupported type of compression", path);
md->checksum_open_type = g_string_chunk_insert(md->chunk, "UNKNOWN");
md->checksum_open = g_string_chunk_insert(md->chunk, "file_compressed_by_an_unsupported_type_of_compression");