Whamcloud - gitweb
Decouple --without-libarchive and HAVE_ARCHIVE_H
authorJohannes Schauer Marin Rodrigues <josch@mister-muffin.de>
Tue, 3 Sep 2024 11:15:33 +0000 (13:15 +0200)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 2 Dec 2024 13:07:33 +0000 (08:07 -0500)
To aid bootstrapping, it would be useful to be able to build e2fsprogs
without archive.h as otherwise there is a build dependency loop with
libarchive. If archive.h is not present, add the missing forward
declarations (as opaque structs) and preprocessor definitions and
typedefs. Since this allows building e2fsprogs with libarchive support
even without the archive.h header present on the system, we cannot check
HAVE_ARCHIVE_H anymore to decide whether to build with libarchive
support or not. So if --without-libarchive is passed to ./configure,
CONFIG_DISABLE_LIBARCHIVE gets set and later checked to decide about
libarchive support.

Addresses-Debian-Bug: #1078693
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
configure
configure.ac
debian/control
lib/config.h.in
misc/create_inode_libarchive.c

index e299be0..f9a7aa4 100755 (executable)
--- a/configure
+++ b/configure
@@ -13750,6 +13750,9 @@ then
        try_libarchive=""
        { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Disabling libarchive support" >&5
 printf "%s\n" "Disabling libarchive support" >&6; }
+
+printf "%s\n" "#define CONFIG_DISABLE_LIBARCHIVE 1" >>confdefs.h
+
 elif test "$withval" = "direct"
 then
        try_libarchive="direct"
index 9a3dff1..1f67604 100644 (file)
@@ -1312,6 +1312,8 @@ AS_HELP_STRING([--without-libarchive],[disable use of libarchive]),
 then
        try_libarchive=""
        AC_MSG_RESULT([Disabling libarchive support])
+       AC_DEFINE(CONFIG_DISABLE_LIBARCHIVE, 1,
+               [Define to 1 to completely disable libarchive])
 elif test "$withval" = "direct"
 then
        try_libarchive="direct"
index bc582cd..2d1cfd8 100644 (file)
@@ -2,7 +2,7 @@ Source: e2fsprogs
 Section: admin
 Priority: required
 Maintainer: Theodore Y. Ts'o <tytso@mit.edu>
-Build-Depends: dpkg-dev (>= 1.22.5), gettext, texinfo, pkgconf, libarchive-dev, libfuse3-dev [linux-any kfreebsd-any] <!pkg.e2fsprogs.no-fuse2fs>, debhelper-compat (= 12), dh-exec, libblkid-dev, uuid-dev, m4, udev [linux-any], systemd [linux-any], systemd-dev [linux-any], cron [linux-any], dh-sequence-movetousr
+Build-Depends: dpkg-dev (>= 1.22.5), gettext, texinfo, pkgconf, libarchive-dev <!nocheck>, libfuse3-dev [linux-any kfreebsd-any] <!pkg.e2fsprogs.no-fuse2fs>, debhelper-compat (= 12), dh-exec, libblkid-dev, uuid-dev, m4, udev [linux-any], systemd [linux-any], systemd-dev [linux-any], cron [linux-any], dh-sequence-movetousr
 Rules-Requires-Root: no
 Standards-Version: 4.7.0
 Homepage: http://e2fsprogs.sourceforge.net
index 04cec72..819c433 100644 (file)
@@ -12,6 +12,9 @@
 /* Define to 1 for features for use by ext4 developers */
 #undef CONFIG_DEVELOPER_FEATURES
 
+/* Define to 1 to completely disable libarchive */
+#undef CONFIG_DISABLE_LIBARCHIVE
+
 /* Define to 1 if using dlopen to access libarchive */
 #undef CONFIG_DLOPEN_LIBARCHIVE
 
index ff697f4..d14efe8 100644 (file)
 #define _GNU_SOURCE 1
 
 #include "config.h"
-#include <ext2fs/ext2_types.h>
 #include "create_inode.h"
 #include "create_inode_libarchive.h"
 #include "support/nls-enable.h"
 
-#ifdef HAVE_ARCHIVE_H
+#ifdef CONFIG_DISABLE_LIBARCHIVE
+
+/* If ./configure was run with --without-libarchive, then only
+ * __populate_fs_from_tar() remains in this file and will return an error. */
+errcode_t __populate_fs_from_tar(ext2_filsys, ext2_ino_t, const char *,
+                                 ext2_ino_t, struct hdlinks_s *,
+                                 struct file_info *,
+                                 struct fs_ops_callbacks *) {
+  com_err(__func__, 0,
+          _("you need to compile e2fsprogs without --without-libarchive"
+            "be able to process tarballs"));
+  return 1;
+}
+
+#else
+
+/* If ./configure was NOT run with --without-libarchive, then build with
+ * support for dlopen()-ing libarchive at runtime. This will also work even
+ * if archive.h is not available at compile-time. See the comment below. */
 
 /* 64KiB is the minimum blksize to best minimize system call overhead. */
 //#define COPY_FILE_BUFLEN 65536
 //#define COPY_FILE_BUFLEN 1048576
 #define COPY_FILE_BUFLEN 16777216
 
+/* If archive.h was found, include it as usual. To support easier
+ * bootstrapping, also allow compilation without archive.h present by
+ * declaring the necessary opaque structs and preprocessor definitions. */
+#ifdef HAVE_ARCHIVE_H
 #include <archive.h>
 #include <archive_entry.h>
+#else
+struct archive;
+struct archive_entry;
+#define        ARCHIVE_EOF       1     /* Found end of archive. */
+#define        ARCHIVE_OK        0     /* Operation was successful. */
+#include <unistd.h>  /* ssize_t */
+typedef ssize_t la_ssize_t;
+#endif /* HAVE_ARCHIVE_H */
+
 #include <libgen.h>
 #include <locale.h>
 
@@ -175,7 +205,7 @@ static int libarchive_available(void)
 
        return 1;
 }
-#endif
+#endif /* CONFIG_DLOPEN_LIBARCHIVE */
 
 static errcode_t __find_path(ext2_filsys fs, ext2_ino_t root, const char *name,
                             ext2_ino_t *inode)
@@ -541,7 +571,6 @@ static errcode_t handle_entry(ext2_filsys fs, ext2_ino_t root_ino,
        }
        return 0;
 }
-#endif
 
 errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
                                 const char *source_tar, ext2_ino_t root,
@@ -549,12 +578,6 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
                                 struct file_info *target,
                                 struct fs_ops_callbacks *fs_callbacks)
 {
-#ifndef HAVE_ARCHIVE_H
-       com_err(__func__, 0,
-               _("you need to compile e2fsprogs with libarchive to "
-                 "be able to process tarballs"));
-       return 1;
-#else
        char *path2, *path3, *dir, *name;
        unsigned int dir_exists;
        struct archive *a;
@@ -700,5 +723,6 @@ out:
        uselocale(old_locale);
        freelocale(archive_locale);
        return retval;
-#endif
 }
+
+#endif /* CONFIG_DISABLE_LIBARCHIVE */