static void test_cr_compression_type(void) { cr_CompressionType type; type = cr_compression_type(NULL); g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION); type = cr_compression_type(""); g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION); type = cr_compression_type("foo"); g_assert_cmpint(type, ==, CR_CW_UNKNOWN_COMPRESSION); type = cr_compression_type("gz"); g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION); type = cr_compression_type("gzip"); g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION); type = cr_compression_type("GZ"); g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION); type = cr_compression_type("Gz"); g_assert_cmpint(type, ==, CR_CW_GZ_COMPRESSION); type = cr_compression_type("bz2"); g_assert_cmpint(type, ==, CR_CW_BZ2_COMPRESSION); type = cr_compression_type("bzip2"); g_assert_cmpint(type, ==, CR_CW_BZ2_COMPRESSION); type = cr_compression_type("xz"); g_assert_cmpint(type, ==, CR_CW_XZ_COMPRESSION); }
/** * Check parsed arguments and fill some other attributes * of option struct accordingly. */ static gboolean check_arguments(SqliterepoCmdOptions *options, GError **err) { // --compress-type if (options->compress_type) { options->compression_type = cr_compression_type(options->compress_type); if (options->compression_type == CR_CW_UNKNOWN_COMPRESSION) { g_set_error(err, CREATEREPO_C_ERROR, CRE_ERROR, "Unknown compression type \"%s\"", options->compress_type); return FALSE; } } // --checksum if (options->chcksum_type) { cr_ChecksumType type; type = cr_checksum_type(options->chcksum_type); if (type == CR_CHECKSUM_UNKNOWN) { g_set_error(err, CREATEREPO_C_ERROR, CRE_BADARG, "Unknown/Unsupported checksum type \"%s\"", options->chcksum_type); return FALSE; } options->checksum_type = type; } // --xz if (options->xz_compression) options->compression_type = CR_CW_XZ_COMPRESSION; return TRUE; }
static gboolean check_arguments(RawCmdOptions *options, GError **err) { // --no-compress if (options->no_compress) { options->compress = FALSE; if (options->compress_type) { g_warning("Use --compress-type simultaneously with --no-compress " "doesn't make a sense"); } } // --compress-type if (options->compress_type && cr_compression_type(options->compress_type) == \ CR_CW_UNKNOWN_COMPRESSION) { g_set_error(err, ERR_DOMAIN, CRE_ERROR, "Unknown compression type \"%s\"", options->compress_type); return FALSE; } // -s/--checksum if (options->checksum && cr_checksum_type(options->checksum) == CR_CHECKSUM_UNKNOWN) { g_set_error(err, ERR_DOMAIN, CRE_ERROR, "Unknown checksum type \"%s\"", options->checksum); return FALSE; } // --unique_md_filenames && --simple_md_filenames if (options->simple_md_filenames) { options->unique_md_filenames = FALSE; } // -f/--batchfile if (options->batchfile && !g_file_test(options->batchfile, G_FILE_TEST_IS_REGULAR)) { g_set_error(err, ERR_DOMAIN, CRE_ERROR, "File \"%s\" doesn't exist", options->batchfile); return FALSE; } // Zchunk options if (options->zck_dict_dir && !options->zck) { g_set_error(err, ERR_DOMAIN, CRE_ERROR, "Cannot use --zck-dict-dir without setting --zck"); return FALSE; } if (options->zck_dict_dir) options->zck_dict_dir = cr_normalize_dir_path(options->zck_dict_dir); return TRUE; }
static gboolean cmd_options_to_task(GSList **modifyrepotasks, RawCmdOptions *options, gchar *metadatapath, GError **err) { assert(modifyrepotasks); assert(!err || *err == NULL); if (!options) return TRUE; //assert(metadatapath || options->remove); if (options->remove) g_debug("Preparing remove-task for: %s", options->remove); else g_debug("Preparing task for: %s", metadatapath); if (metadatapath && !g_file_test(metadatapath, G_FILE_TEST_IS_REGULAR)) { g_set_error(err, ERR_DOMAIN, CRE_ERROR, "File \"%s\" is not regular file or doesn't exists", metadatapath); return FALSE; } if (options->remove) metadatapath = options->remove; cr_ModifyRepoTask *task = cr_modifyrepotask_new(); task->path = cr_safe_string_chunk_insert_null(task->chunk, metadatapath); task->type = cr_safe_string_chunk_insert_null(task->chunk, options->mdtype); task->remove = (options->remove) ? TRUE : FALSE; task->compress = options->compress; task->compress_type = cr_compression_type(options->compress_type); task->unique_md_filenames = options->unique_md_filenames; task->checksum_type = cr_checksum_type(options->checksum); task->new_name = cr_safe_string_chunk_insert_null(task->chunk, options->new_name); task->zck = options->zck; task->zck_dict_dir = options->zck_dict_dir; *modifyrepotasks = g_slist_append(*modifyrepotasks, task); g_debug("Task: [path: %s, type: %s, remove: %d, compress: %d, " "compress_type: %d (%s), unique_md_filenames: %d, " "checksum_type: %d (%s), new_name: %s]", task->path, task->type, task->remove, task->compress, task->compress_type, cr_compression_suffix(task->compress_type), task->unique_md_filenames, task->checksum_type, cr_checksum_name_str(task->checksum_type), task->new_name); return TRUE; }
static gboolean check_arguments(RawCmdOptions *options, GError **err) { // --no-compress if (options->no_compress) { options->compress = FALSE; if (options->compress_type) { g_warning("Use --compress-type simultaneously with --no-compress " "doesn't make a sense"); } } // --compress-type if (options->compress_type && cr_compression_type(options->compress_type) == \ CR_CW_UNKNOWN_COMPRESSION) { g_set_error(err, CR_MODIFYREPO_ERROR, CRE_ERROR, "Unknown compression type \"%s\"", options->compress_type); return FALSE; } // -s/--checksum if (options->checksum && cr_checksum_type(options->checksum) == CR_CHECKSUM_UNKNOWN) { g_set_error(err, CR_MODIFYREPO_ERROR, CRE_ERROR, "Unknown checksum type \"%s\"", options->checksum); return FALSE; } // --unique_md_filenames && --simple_md_filenames if (options->simple_md_filenames) { options->unique_md_filenames = FALSE; } // -f/--batchfile if (options->batchfile && !g_file_test(options->batchfile, G_FILE_TEST_IS_REGULAR)) { g_set_error(err, CR_MODIFYREPO_ERROR, CRE_ERROR, "File \"%s\" doesn't exist", options->batchfile); return FALSE; } return TRUE; }