]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Unify unsupported entry file type error message in writer
authorMartin Matuska <martin@matuska.org>
Sat, 25 Jan 2020 13:26:59 +0000 (14:26 +0100)
committerMartin Matuska <martin@matuska.org>
Sat, 25 Jan 2020 13:26:59 +0000 (14:26 +0100)
Closes #1320

15 files changed:
Makefile.am
libarchive/CMakeLists.txt
libarchive/archive_write_set_format.c
libarchive/archive_write_set_format_7zip.c
libarchive/archive_write_set_format_ar.c
libarchive/archive_write_set_format_cpio.c
libarchive/archive_write_set_format_cpio_newc.c
libarchive/archive_write_set_format_gnutar.c
libarchive/archive_write_set_format_pax.c
libarchive/archive_write_set_format_private.h [new file with mode: 0644]
libarchive/archive_write_set_format_shar.c
libarchive/archive_write_set_format_ustar.c
libarchive/archive_write_set_format_v7tar.c
libarchive/archive_write_set_format_warc.c
libarchive/archive_write_set_format_zip.c

index ea31c52704e4d534dcf238a9ef0cdc98bb0a5258..06c26442087fb0dbeff14384b3a39e3059b0c495 100644 (file)
@@ -228,6 +228,7 @@ libarchive_la_SOURCES= \
        libarchive/archive_write_set_format_iso9660.c \
        libarchive/archive_write_set_format_mtree.c \
        libarchive/archive_write_set_format_pax.c \
+       libarchive/archive_write_set_format_private.h \
        libarchive/archive_write_set_format_raw.c \
        libarchive/archive_write_set_format_shar.c \
        libarchive/archive_write_set_format_ustar.c \
index ec775bb49939e67523f95bfdff7ebcd6739488fd..9389bbc9a95bfada064617f8a114491d89d0eb22 100644 (file)
@@ -150,6 +150,7 @@ SET(libarchive_SOURCES
   archive_write_set_format_iso9660.c
   archive_write_set_format_mtree.c
   archive_write_set_format_pax.c
+  archive_write_set_format_private.h
   archive_write_set_format_raw.c
   archive_write_set_format_shar.c
   archive_write_set_format_ustar.c
index 0f706231add1ef8fb735efc586240ccbc333bcd7..12de080775345c13aa902cc5866904ece30589f4 100644 (file)
@@ -36,6 +36,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-1
 
 #include "archive.h"
 #include "archive_private.h"
+#include "archive_write_set_format_private.h"
 
 /* A table that maps format codes to functions. */
 static const
@@ -76,3 +77,47 @@ archive_write_set_format(struct archive *a, int code)
        archive_set_error(a, EINVAL, "No such format");
        return (ARCHIVE_FATAL);
 }
+
+void
+__archive_write_entry_filetype_unsupported(struct archive *a,
+    struct archive_entry *entry, const char *format)
+{
+       char *name = NULL;
+
+       switch (archive_entry_filetype(entry)) {
+       /*
+        * All formats should be able to archive regular files (AE_IFREG)
+        */
+       case AE_IFDIR:
+               name = "directories";
+               break;
+       case AE_IFLNK:
+               name = "symbolic links";
+               break;
+       case AE_IFCHR:
+               name = "character devices";
+               break;
+       case AE_IFBLK:
+               name = "block devices";
+               break;
+       case AE_IFIFO:
+               name = "named pipes";
+               break;
+       case AE_IFSOCK:
+               name = "sockets";
+               break;
+       default:
+               break;
+       }
+
+       if (name != NULL) {
+               archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+                   "%s: %s format cannot archive %s",
+                   archive_entry_pathname(entry), format, name);
+       } else {
+               archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT,
+                   "%s: %s format cannot archive files with mode 0%lo",
+                   archive_entry_pathname(entry), format,
+                   (unsigned long)archive_entry_mode(entry));
+       }
+}
index e577704b16ad466ea9ed54e8ac1bb6425c50de2b..fb7697f659ca7d899a3c85a725c6d82a31c93644 100644 (file)
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
 #include "archive_rb.h"
 #include "archive_string.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 /*
  * Codec ID
index 253cac82efe6a304642a1024a69f30bf691e4f35..fc0de1e9f6f0bd3ac2f1293970734f0d1847987d 100644 (file)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ar.c 201108 200
 #include "archive_entry.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct ar_w {
        uint64_t         entry_bytes_remaining;
index 16cefad7b5b326cb26a9059043be9ef76b9f7829..729f9c7755915febbb64e6d2c376c27d94b572d2 100644 (file)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 static ssize_t archive_write_cpio_data(struct archive_write *,
                    const void *buff, size_t s);
index 2d923cc33061fa4855a6fdbe69e90b898616d81a..172fda62f0bb71d6fc0876c0f09441292e2e8644 100644 (file)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 static ssize_t archive_write_newc_data(struct archive_write *,
                    const void *buff, size_t s);
index e7757c22badd50e0888a9a8ddfa011d499d1f0bc..ec29c5c418e4e482cb32dbc0694d957704718bc5 100644 (file)
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_gnu_tar.c 19157
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct gnutar {
        uint64_t        entry_bytes_remaining;
@@ -534,17 +535,9 @@ archive_write_gnutar_header(struct archive_write *a,
                case AE_IFBLK: tartype = '4' ; break;
                case AE_IFDIR: tartype = '5' ; break;
                case AE_IFIFO: tartype = '6' ; break;
-               case AE_IFSOCK:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive socket");
-                       ret = ARCHIVE_FAILED;
-                       goto exit_write_header;
-               default:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive this (mode=0%lo)",
-                           (unsigned long)archive_entry_mode(entry));
+               default: /* AE_IFSOCK and unknown */
+                       __archive_write_entry_filetype_unsupported(
+                            &a->archive, entry, "gnutar");
                        ret = ARCHIVE_FAILED;
                        goto exit_write_header;
                }
index 7c5e63bb3a233e1e71d66f61fa3c33a22125398e..584f46ae020201d9cc2b2b617d27d07aaab940dd 100644 (file)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_pax.c 201162 20
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct sparse_block {
        struct sparse_block     *next;
@@ -713,17 +714,9 @@ archive_write_pax_header(struct archive_write *a,
                        }
                        break;
                }
-               case AE_IFSOCK:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive socket");
-                       return (ARCHIVE_FAILED);
-               default:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive this (type=0%lo)",
-                           (unsigned long)
-                           archive_entry_filetype(entry_original));
+               default: /* AE_IFSOCK and unknown */
+                       __archive_write_entry_filetype_unsupported(
+                           &a->archive, entry_original, "pax");
                        return (ARCHIVE_FAILED);
                }
        }
diff --git a/libarchive/archive_write_set_format_private.h b/libarchive/archive_write_set_format_private.h
new file mode 100644 (file)
index 0000000..e200227
--- /dev/null
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2020 Martin Matuska
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef ARCHIVE_WRITE_SET_FORMAT_PRIVATE_H_INCLUDED
+#define ARCHIVE_WRITE_SET_FORMAT_PRIVATE_H_INCLUDED
+
+#ifndef __LIBARCHIVE_BUILD
+#ifndef __LIBARCHIVE_TEST
+#error This header is only to be used internally to libarchive.
+#endif
+#endif
+
+#include "archive.h"
+#include "archive_entry.h"
+
+void __archive_write_entry_filetype_unsupported(struct archive *a,
+    struct archive_entry *entry, const char *format);
+#endif
index 600c88257a0cef1f5925eec8fefdda3d46e30b91..9e4931c95c1fa573ca4495df1229d9cee19d4cd9 100644 (file)
@@ -42,6 +42,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_shar.c 189438 2
 #include "archive_entry.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct shar {
        int                      dump;
@@ -194,8 +195,8 @@ archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
                archive_entry_set_size(entry, 0);
                if (archive_entry_hardlink(entry) == NULL &&
                    archive_entry_symlink(entry) == NULL) {
-                       archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-                           "shar format cannot archive this");
+                       __archive_write_entry_filetype_unsupported(
+                           &a->archive, entry, "shar");
                        return (ARCHIVE_WARN);
                }
        }
index ad4ccb77ea53a6c09dcd2fcab710e185c89cd68c..e1fe974a12eeead3a9996ed0b4527a5ca0a19956 100644 (file)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ustar.c 191579
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct ustar {
        uint64_t        entry_bytes_remaining;
@@ -609,16 +610,9 @@ __archive_write_format_header_ustar(struct archive_write *a, char h[512],
                case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break;
                case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break;
                case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break;
-               case AE_IFSOCK:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive socket");
-                       return (ARCHIVE_FAILED);
-               default:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive this (mode=0%lo)",
-                           (unsigned long)archive_entry_mode(entry));
+               default: /* AE_IFSOCK and unknown */
+                       __archive_write_entry_filetype_unsupported(
+                           &a->archive, entry, "ustar");
                        ret = ARCHIVE_FAILED;
                }
        }
index 1fdaafd2a93911faa01b2a14487b7c421c8cdacf..599407144121197b6b2f7ae50c1c0f112123576f 100644 (file)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include "archive_entry_locale.h"
 #include "archive_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct v7tar {
        uint64_t        entry_bytes_remaining;
@@ -491,31 +492,11 @@ format_header_v7tar(struct archive_write *a, char h[512],
                case AE_IFLNK:
                        h[V7TAR_typeflag_offset] = '2';
                        break;
-               case AE_IFCHR:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive character device");
-                       return (ARCHIVE_FAILED);
-               case AE_IFBLK:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive block device");
-                       return (ARCHIVE_FAILED);
-               case AE_IFIFO:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive fifo");
-                       return (ARCHIVE_FAILED);
-               case AE_IFSOCK:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive socket");
-                       return (ARCHIVE_FAILED);
                default:
-                       archive_set_error(&a->archive,
-                           ARCHIVE_ERRNO_FILE_FORMAT,
-                           "tar format cannot archive this (mode=0%lo)",
-                           (unsigned long)archive_entry_mode(entry));
+                       /* AE_IFBLK, AE_IFCHR, AE_IFIFO, AE_IFSOCK
+                        * and unknown */
+                       __archive_write_entry_filetype_unsupported(
+                           &a->archive, entry, "v7tar");
                        ret = ARCHIVE_FAILED;
                }
        }
index 00f15ff9d2625b701480c820480cf1064210403e..46b05734121c348c06d6b9177d8cfccfcb5d5421 100644 (file)
@@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
 #include "archive_private.h"
 #include "archive_random_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 struct warc_s {
        unsigned int omit_warcinfo:1;
@@ -259,10 +260,8 @@ _warc_header(struct archive_write *a, struct archive_entry *entry)
                return (ARCHIVE_OK);
        }
        /* just resort to erroring as per Tim's advice */
-       archive_set_error(
-               &a->archive,
-               ARCHIVE_ERRNO_FILE_FORMAT,
-               "WARC can only process regular files");
+       __archive_write_entry_filetype_unsupported(
+           &a->archive, entry, "WARC");
        return (ARCHIVE_FAILED);
 }
 
index 917350d569e77b1bfd3ef5482239e85fbe81f32e..6d485295d50ff1bac6f4fe915a6fcf95a4d4e7c1 100644 (file)
@@ -57,6 +57,7 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_zip.c 201168 20
 #include "archive_private.h"
 #include "archive_random_private.h"
 #include "archive_write_private.h"
+#include "archive_write_set_format_private.h"
 
 #ifndef HAVE_ZLIB_H
 #include "archive_crc32.h"
@@ -526,8 +527,8 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
        /* Ignore types of entries that we don't support. */
        type = archive_entry_filetype(entry);
        if (type != AE_IFREG && type != AE_IFDIR && type != AE_IFLNK) {
-               archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-                   "Filetype not supported");
+               __archive_write_entry_filetype_unsupported(
+                   &a->archive, entry, "zip");
                return ARCHIVE_FAILED;
        };