Skip to content
Browse files

Fix issue 237.

Properly set a clear error message when archive_{write,read}_set_options failed.
  • Loading branch information...
1 parent 1ecb1bb commit f30dc311bafff055bbcfcb272834566e15fce4dd @ggcueroad ggcueroad committed Feb 14, 2012
View
38 libarchive/archive_options.c
@@ -38,6 +38,7 @@ _archive_set_option(struct archive *a,
int magic, const char *fn, option_handler use_option)
{
const char *mp, *op, *vp;
+ int r;
archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn);
@@ -47,10 +48,24 @@ _archive_set_option(struct archive *a,
if (op == NULL && vp == NULL)
return (ARCHIVE_OK);
- if (op == NULL)
+ if (op == NULL) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC, "Empty option");
return (ARCHIVE_FAILED);
+ }
- return use_option(a, mp, op, vp);
+ r = use_option(a, mp, op, vp);
+ if (r == ARCHIVE_WARN - 1) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mp);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s%s%s%s'",
+ vp?"":"!", mp?mp:"", mp?":":"", op, vp?"=":"", vp?vp:"");
+ return (ARCHIVE_FAILED);
+ }
+ return (r);
}
int
@@ -102,6 +117,25 @@ _archive_set_options(struct archive *a, const char *options,
free(data);
return (ARCHIVE_FATAL);
}
+ if (r == ARCHIVE_FAILED && mod != NULL) {
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN - 1) {
+ /* The module name is wrong. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Unknown module name: `%s'", mod);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
+ if (r == ARCHIVE_WARN) {
+ /* The option name is wrong. No-one used this. */
+ archive_set_error(a, ARCHIVE_ERRNO_MISC,
+ "Undefined option: `%s%s%s'",
+ mod?mod:"", mod?":":"", opt);
+ free(data);
+ return (ARCHIVE_FAILED);
+ }
if (r == ARCHIVE_OK)
anyok = 1;
else
View
12 libarchive/archive_read_set_options.c
@@ -78,7 +78,7 @@ archive_set_format_option(struct archive *_a, const char *m, const char *o,
struct archive_read *a = (struct archive_read *)_a;
struct archive_format_descriptor *format;
size_t i;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) {
format = &a->formats[i];
@@ -102,6 +102,10 @@ archive_set_format_option(struct archive *_a, const char *m, const char *o,
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
@@ -112,7 +116,7 @@ archive_set_filter_option(struct archive *_a, const char *m, const char *o,
struct archive_read *a = (struct archive_read *)_a;
struct archive_read_filter *filter;
struct archive_read_filter_bidder *bidder;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (filter = a->filter; filter != NULL; filter = filter->upstream) {
bidder = filter->bidder;
@@ -135,6 +139,10 @@ archive_set_filter_option(struct archive *_a, const char *m, const char *o,
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
View
12 libarchive/archive_read_support_format_cab.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -478,11 +478,13 @@ archive_read_format_cab_options(struct archive_read *a,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "cab: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
14 libarchive/archive_read_support_format_cpio.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -325,7 +325,7 @@ archive_read_format_cpio_options(struct archive_read *a,
if (strcmp(key, "compat-2x") == 0) {
/* Handle filnames as libarchive 2.x */
cpio->init_default_conversion = (val != NULL)?1:0;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -339,11 +339,13 @@ archive_read_format_cpio_options(struct archive_read *a,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "cpio: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
12 libarchive/archive_read_support_format_lha.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2008-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2008-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -445,11 +445,13 @@ archive_read_format_lha_options(struct archive_read *a,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "lha: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
12 libarchive/archive_read_support_format_rar.c
@@ -757,11 +757,13 @@ archive_read_format_rar_options(struct archive_read *a,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "rar: unknown keyword ``%s''", key);
-
- return (ret);
+ return (ret);
+ }
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
14 libarchive/archive_read_support_format_tar.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -369,7 +369,7 @@ archive_read_format_tar_options(struct archive_read *a,
/* Handle UTF-8 filnames as libarchive 2.x */
tar->compat_2x = (val != NULL)?1:0;
tar->init_default_conversion = tar->compat_2x;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -383,11 +383,13 @@ archive_read_format_tar_options(struct archive_read *a,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "tar: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/* utility function- this exists to centralize the logic of tracking
View
14 libarchive/archive_read_support_format_zip.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2004 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -509,7 +509,7 @@ archive_read_format_zip_options(struct archive_read *a,
if (strcmp(key, "compat-2x") == 0) {
/* Handle filnames as libarchive 2.x */
zip->init_default_conversion = (val != NULL) ? 1 : 0;
- ret = ARCHIVE_OK;
+ return (ARCHIVE_OK);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0)
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -524,11 +524,13 @@ archive_read_format_zip_options(struct archive_read *a,
} else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "zip: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
3 libarchive/archive_write_add_filter_bzip2.c
@@ -216,6 +216,9 @@ archive_compressor_bzip2_options(struct archive_write_filter *f,
return (ARCHIVE_OK);
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
View
4 libarchive/archive_write_add_filter_gzip.c
@@ -230,6 +230,10 @@ archive_compressor_gzip_options(struct archive_write_filter *f, const char *key,
data->compression_level = value[0] - '0';
return (ARCHIVE_OK);
}
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
View
5 libarchive/archive_write_add_filter_xz.c
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 2009,2010 Michihiro NAKAJIMA
* Copyright (c) 2003-2010 Tim Kientzle
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -375,6 +375,9 @@ archive_compressor_xz_options(struct archive_write_filter *f,
return (ARCHIVE_OK);
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
return (ARCHIVE_WARN);
}
View
5 libarchive/archive_write_set_format_7zip.c
@@ -413,7 +413,10 @@ _7z_options(struct archive_write *a, const char *key, const char *value)
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
10 libarchive/archive_write_set_format_cpio.c
@@ -147,11 +147,13 @@ archive_write_cpio_options(struct archive_write *a, const char *key,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/*
View
10 libarchive/archive_write_set_format_cpio_newc.c
@@ -154,11 +154,13 @@ archive_write_newc_options(struct archive_write *a, const char *key,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static struct archive_string_conv *
View
15 libarchive/archive_write_set_format_gnutar.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Author: Jonas Gastal <jgastal@profusion.mobi>
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
*
* All rights reserved.
*
@@ -177,7 +177,8 @@ archive_write_set_format_gnutar(struct archive *_a)
gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar));
if (gnutar == NULL) {
- archive_set_error(&a->archive, ENOMEM, "Can't allocate gnutar data");
+ archive_set_error(&a->archive, ENOMEM,
+ "Can't allocate gnutar data");
return (ARCHIVE_FATAL);
}
a->format_data = gnutar;
@@ -213,11 +214,13 @@ archive_write_gnutar_options(struct archive_write *a, const char *key,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
7 libarchive/archive_write_set_format_iso9660.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1507,6 +1507,11 @@ iso9660_options(struct archive_write *a, const char *key, const char *value)
break;
}
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
+
invalid_value:
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Invalid value for option ``%s''", key);
View
7 libarchive/archive_write_set_format_mtree.c
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 2009,2011 Michihiro NAKAJIMA
* Copyright (c) 2008 Joerg Sonnenberger
+ * Copyright (c) 2009-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1222,7 +1222,10 @@ archive_write_mtree_options(struct archive_write *a, const char *key,
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
int
View
12 libarchive/archive_write_set_format_pax.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -187,11 +187,13 @@ archive_write_pax_options(struct archive_write *a, const char *key,
} else
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"pax: invalid charset name");
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "pax: unknown keyword ``%s''", key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
/*
View
12 libarchive/archive_write_set_format_ustar.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2003-2007 Tim Kientzle
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -224,11 +224,13 @@ archive_write_ustar_options(struct archive_write *a, const char *key,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
+ return (ret);
+ }
- return (ret);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
7 libarchive/archive_write_set_format_xar.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2010-2011 Michihiro NAKAJIMA
+ * Copyright (c) 2010-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -494,7 +494,10 @@ xar_options(struct archive_write *a, const char *key, const char *value)
return (ARCHIVE_OK);
}
- return (ARCHIVE_FAILED);
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
static int
View
14 libarchive/archive_write_set_format_zip.c
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2008 Anselm Strauss
* Copyright (c) 2009 Joerg Sonnenberger
- * Copyright (c) 2011 Michihiro NAKAJIMA
+ * Copyright (c) 2011-2012 Michihiro NAKAJIMA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -233,6 +233,7 @@ archive_write_zip_options(struct archive_write *a, const char *key,
zip->compression = COMPRESSION_STORE;
ret = ARCHIVE_OK;
}
+ return (ret);
} else if (strcmp(key, "hdrcharset") == 0) {
if (val == NULL || val[0] == 0) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -246,10 +247,13 @@ archive_write_zip_options(struct archive_write *a, const char *key,
else
ret = ARCHIVE_FATAL;
}
- } else
- archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
- "%s: unknown keyword ``%s''", a->format_name, key);
- return (ret);
+ return (ret);
+ }
+
+ /* Note: The "warn" return is just to inform the options
+ * supervisor that we didn't handle it. It will generate
+ * a suitable error if no one used this option. */
+ return (ARCHIVE_WARN);
}
int
View
12 libarchive/archive_write_set_options.c
@@ -79,10 +79,12 @@ archive_set_format_option(struct archive *_a, const char *m, const char *o,
if (a->format_name == NULL)
return (ARCHIVE_FAILED);
+ /* If the format name didn't match, return a special code for
+ * _archive_set_option[s]. */
if (m != NULL && strcmp(m, a->format_name) != 0)
- return (ARCHIVE_FAILED);
+ return (ARCHIVE_WARN - 1);
if (a->format_options == NULL)
- return (ARCHIVE_FAILED);
+ return (ARCHIVE_WARN);
return a->format_options(a, o, v);
}
@@ -92,7 +94,7 @@ archive_set_filter_option(struct archive *_a, const char *m, const char *o,
{
struct archive_write *a = (struct archive_write *)_a;
struct archive_write_filter *filter;
- int r, rv = ARCHIVE_FAILED;
+ int r, rv = ARCHIVE_WARN;
for (filter = a->filter_first; filter != NULL; filter = filter->next_filter) {
if (filter->options == NULL)
@@ -111,6 +113,10 @@ archive_set_filter_option(struct archive *_a, const char *m, const char *o,
if (r == ARCHIVE_OK)
rv = ARCHIVE_OK;
}
+ /* If the filter name didn't match, return a special code for
+ * _archive_set_option[s]. */
+ if (rv == ARCHIVE_WARN && m != NULL)
+ rv = ARCHIVE_WARN - 1;
return (rv);
}
View
57 libarchive/test/test_archive_read_set_options.c
@@ -33,14 +33,13 @@ static void
test(int pristine)
{
struct archive* a = archive_read_new();
- int halfempty_options_rv = pristine ? ARCHIVE_WARN : ARCHIVE_OK;
+ int halfempty_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
- int mixed_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_WARN;
if (!pristine) {
archive_read_support_filter_all(a);
archive_read_support_format_all(a);
- }
+ }
/* NULL and "" denote `no option', so they're ok no matter
* what, if any, formats are registered */
@@ -49,25 +48,73 @@ test(int pristine)
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "fubar:snafu");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "fubar:snafu=betcha");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "snafu");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "snafu=betcha");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
- /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_WARN otherwise */
+ /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_FAILED otherwise */
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "!joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, ARCHIVE_OK, ",");
should(a, ARCHIVE_OK, ",,");
should(a, halfempty_options_rv, ",joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, halfempty_options_rv, "joliet,");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
- should(a, mixed_options_rv, "joliet,snafu");
+ should(a, ARCHIVE_FAILED, "joliet,snafu");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
+ }
+
+ should(a, ARCHIVE_FAILED, "iso9660:snafu");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `iso9660:snafu'",
+ archive_error_string(a));
+ }
archive_read_finish(a);
}
View
57 libarchive/test/test_archive_write_set_options.c
@@ -33,14 +33,13 @@ static void
test(int pristine)
{
struct archive* a = archive_write_new();
- int halfempty_options_rv = pristine ? ARCHIVE_WARN : ARCHIVE_OK;
+ int halfempty_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
int known_option_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_OK;
- int mixed_options_rv = pristine ? ARCHIVE_FAILED : ARCHIVE_WARN;
if (!pristine) {
archive_write_set_compression_gzip(a);
archive_write_set_format_iso9660(a);
- }
+ }
/* NULL and "" denote `no option', so they're ok no matter
* what, if any, formats are registered */
@@ -49,25 +48,73 @@ test(int pristine)
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "fubar:snafu");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "fubar:snafu=betcha");
+ assertEqualString("Unknown module name: `fubar'",
+ archive_error_string(a));
/* unknown modules and options */
should(a, ARCHIVE_FAILED, "snafu");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
should(a, ARCHIVE_FAILED, "snafu=betcha");
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
- /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_WARN otherwise */
+ /* ARCHIVE_OK with iso9660 loaded, ARCHIVE_FAILED otherwise */
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "iso9660:joliet");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, known_option_rv, "!joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, ARCHIVE_OK, ",");
should(a, ARCHIVE_OK, ",,");
should(a, halfempty_options_rv, ",joliet");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
should(a, halfempty_options_rv, "joliet,");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ }
- should(a, mixed_options_rv, "joliet,snafu");
+ should(a, ARCHIVE_FAILED, "joliet,snafu");
+ if (pristine) {
+ assertEqualString("Undefined option: `joliet'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `snafu'",
+ archive_error_string(a));
+ }
+
+ should(a, ARCHIVE_FAILED, "iso9660:snafu");
+ if (pristine) {
+ assertEqualString("Unknown module name: `iso9660'",
+ archive_error_string(a));
+ } else {
+ assertEqualString("Undefined option: `iso9660:snafu'",
+ archive_error_string(a));
+ }
archive_write_finish(a);
}

0 comments on commit f30dc31

Please sign in to comment.
Something went wrong with that request. Please try again.