]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
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 e299be0281f5f110abfddca0f191fbbd6ad045c0..f9a7aa4e2e864cae9d871cc9911777a6b299e0a3 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 9a3dff1cf05623e2477aa0df93c26373877cf9ee..1f67604036b5281a5147aa4351f8f44d6b085a6f 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 bc582cd8a3081c1c31e8807e1c0ec125a5316e4c..2d1cfd88fbb93217d2909cd12279dc399d8d4594 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 04cec72b84b5a0ea071fca4cbe2bb07617f1bb30..819c433137924771819f26d77fd745512ae94c64 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 ff697f4c81ddd0c0d0ccd770b16892a20f6c7124..d14efe81dd859779b30f3f51074664c6d16ca855 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 */