diff options
author | rbuj <[email protected]> | 2020-01-18 16:07:38 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2020-02-15 17:39:05 +0100 |
commit | 25b2bdbcfb95c91a33fd62370cac28a863567c3f (patch) | |
tree | 973e1f247834b90c927a573b924bb9faa7ab2441 | |
parent | f4658da2bcdc2f858434091c0cc121b82adcee5e (diff) | |
download | engrampa-25b2bdbcfb95c91a33fd62370cac28a863567c3f.tar.bz2 engrampa-25b2bdbcfb95c91a33fd62370cac28a863567c3f.tar.xz |
autoconf: get zstd mime type using libmagic if enabled
-rw-r--r-- | caja/caja-engrampa.c | 2 | ||||
-rw-r--r-- | configure.ac | 46 | ||||
-rw-r--r-- | data/engrampa.desktop.in.in | 2 | ||||
-rw-r--r-- | src/fr-command-cfile.c | 12 | ||||
-rw-r--r-- | src/fr-init.c | 4 |
5 files changed, 56 insertions, 10 deletions
diff --git a/caja/caja-engrampa.c b/caja/caja-engrampa.c index b464192..af19d25 100644 --- a/caja/caja-engrampa.c +++ b/caja/caja-engrampa.c @@ -191,7 +191,7 @@ static struct { { "application/x-zip", TRUE }, { "application/x-zip-compressed", TRUE }, { "application/x-zoo", TRUE }, - { "application/x-zstd", TRUE }, + { ZSTD_MIME_TYPE, TRUE }, { "application/x-zstd-compressed-tar", TRUE }, { "application/zip", TRUE }, { "multipart/x-zip", TRUE }, diff --git a/configure.ac b/configure.ac index 22146e0..cdd7081 100644 --- a/configure.ac +++ b/configure.ac @@ -141,6 +141,7 @@ AC_ARG_ENABLE([magic], AS_HELP_STRING([--enable-magic], [use libmagic to detect file type]),, [enable_magic=no]) +zstd_mime_type="application/zstd" if test x"$enable_magic" = x"yes" ; then save_LIBS="$LIBS" LIBS="$LIBS -lmagic" @@ -152,6 +153,48 @@ int main () { magic_t m = magic_open(MAGIC_NONE); } [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) AC_MSG_ERROR([libmagic is needed for magic])]) + + dnl ******************************************* + dnl This check can be removed with file >= 5.38 + dnl ******************************************* + AC_MSG_CHECKING([for zstd mime type]) + AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h> +#include <string.h> +#include <magic.h>]], + [[ + FILE *fptr; + char *test_file = "test.zst"; + char *default_mime_type = "application/zstd"; + int status = 0; + if ((fptr = fopen (test_file,"wb")) == NULL) { + status = 1; + } else { + const unsigned char data[5] = "\x28\xb5\x2f\xfd\0"; + int i; + for (i = 0; i < strlen (data); i++) + fwrite (&data[i], 1, 1, fptr); + fclose (fptr); + magic_t magic_cookie = magic_open (MAGIC_MIME_TYPE); + if (magic_cookie == NULL) { + status = 1; + } else { + if (magic_load (magic_cookie, NULL) != 0) { + status = 1; + } else { + const char *mime = magic_file (magic_cookie, test_file); + status = (strcmp (default_mime_type, mime) == 0); + } + magic_close(magic_cookie); + } + remove (test_file); + } + return status;]])], + [zstd_mime_type="application/x-zstd"], + [zstd_mime_type="application/zstd"] + ) + AC_MSG_RESULT($zstd_mime_type) + dnl ******************************************* + LIBS="$save_LIBS" MAGIC_CFLAGS= @@ -164,6 +207,9 @@ int main () { magic_t m = magic_open(MAGIC_NONE); } fi AM_CONDITIONAL(ENABLE_MAGIC, test x"$enable_magic" != x"no") +ZSTD_MIME_TYPE="$zstd_mime_type" +AC_SUBST(ZSTD_MIME_TYPE) +AC_DEFINE_UNQUOTED(ZSTD_MIME_TYPE, "$zstd_mime_type", [define zstd mime type]) AC_ARG_VAR([CPIO], [Path to the `cpio` command]) AC_PATH_PROGS(CPIO, gcpio cpio, cpio) diff --git a/data/engrampa.desktop.in.in b/data/engrampa.desktop.in.in index dde5812..59295fd 100644 --- a/data/engrampa.desktop.in.in +++ b/data/engrampa.desktop.in.in @@ -11,7 +11,7 @@ Type=Application Icon=engrampa # Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! Categories=GTK;Utility;Archiving;Compression; -MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-arj;application/x-brotli;application/x-brotli-compressed-tar;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/vnd.debian.binary-package;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lzh-compressed;application/x-lrzip;application/x-lrzip-compressed-tar;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-ms-wim;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-source-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;application/x-zstd;application/x-zstd-compressed-tar;application/zip;application/x-archive;application/vnd.ms-cab-compressed; +MimeType=application/x-7z-compressed;application/x-7z-compressed-tar;application/x-ace;application/x-alz;application/x-arj;application/x-brotli;application/x-brotli-compressed-tar;application/x-bzip;application/x-bzip-compressed-tar;application/x-bzip1;application/x-bzip1-compressed-tar;application/x-cabinet;application/x-cbr;application/x-cbz;application/x-cd-image;application/x-compress;application/x-compressed-tar;application/x-cpio;application/vnd.debian.binary-package;application/x-ear;application/x-ms-dos-executable;application/x-gtar;application/x-gzip;application/x-gzpostscript;application/x-java-archive;application/x-lha;application/x-lzh-compressed;application/x-lrzip;application/x-lrzip-compressed-tar;application/x-lzip;application/x-lzip-compressed-tar;application/x-lzma;application/x-lzma-compressed-tar;application/x-lzop;application/x-lzop-compressed-tar;application/x-ms-wim;application/x-rar;application/x-rar-compressed;application/x-rpm;application/x-source-rpm;application/x-rzip;application/x-tar;application/x-tarz;application/x-stuffit;application/x-war;application/x-xz;application/x-xz-compressed-tar;application/x-zip;application/x-zip-compressed;application/x-zoo;@ZSTD_MIME_TYPE@;application/x-zstd-compressed-tar;application/zip;application/x-archive;application/vnd.ms-cab-compressed; # Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! Keywords=MATE;archive;manager;compression; X-MATE-DocPath=engrampa/engrampa.xml diff --git a/src/fr-command-cfile.c b/src/fr-command-cfile.c index 697d8ab..a914abe 100644 --- a/src/fr-command-cfile.c +++ b/src/fr-command-cfile.c @@ -301,7 +301,7 @@ fr_command_cfile_add (FrCommand *comm, compressed_filename = g_strconcat (filename, ".rz", NULL); } - else if (is_mime_type (comm->mime_type, "application/x-zstd")) { + else if (is_mime_type (comm->mime_type, ZSTD_MIME_TYPE)) { fr_process_begin_command (comm->process, "zstd"); fr_process_set_working_dir (comm->process, temp_dir); fr_process_add_arg (comm->process, filename); @@ -446,7 +446,7 @@ fr_command_cfile_extract (FrCommand *comm, fr_process_end_command (comm->process); } - else if (is_mime_type (comm->mime_type, "application/x-zstd")) { + else if (is_mime_type (comm->mime_type, ZSTD_MIME_TYPE)) { fr_process_begin_command (comm->process, "zstd"); fr_process_add_arg (comm->process, "-f"); fr_process_add_arg (comm->process, "-d"); @@ -515,7 +515,7 @@ fr_command_cfile_test (FrCommand *comm) else if (is_mime_type (comm->mime_type, "application/x-lzop")) { compress_cmd = "lzop"; } - else if (is_mime_type (comm->mime_type, "application/x-zstd")) { + else if (is_mime_type (comm->mime_type, ZSTD_MIME_TYPE)) { compress_cmd = "zstd"; fr_process_begin_command (comm->process, compress_cmd); fr_process_add_arg (comm->process, "-v"); @@ -542,7 +542,7 @@ const char *cfile_mime_type[] = { "application/x-gzip", "application/x-lzop", "application/x-rzip", "application/x-xz", - "application/x-zstd", + ZSTD_MIME_TYPE, NULL }; @@ -599,7 +599,7 @@ fr_command_cfile_get_capabilities (FrCommand *comm, if (is_program_available ("rzip", check_command)) capabilities |= FR_COMMAND_CAN_READ_WRITE; } - else if (is_mime_type (mime_type, "application/x-zstd")) { + else if (is_mime_type (mime_type, ZSTD_MIME_TYPE)) { if (is_program_available ("zstd", check_command)) capabilities |= FR_COMMAND_CAN_READ_WRITE; } @@ -642,7 +642,7 @@ fr_command_cfile_get_packages (FrCommand *comm, return PACKAGES ("lzop"); else if (is_mime_type (mime_type, "application/x-rzip")) return PACKAGES ("rzip"); - else if (is_mime_type (mime_type, "application/x-zstd")) + else if (is_mime_type (mime_type, ZSTD_MIME_TYPE)) return PACKAGES ("zstd"); return NULL; diff --git a/src/fr-init.c b/src/fr-init.c index e09f463..67393f1 100644 --- a/src/fr-init.c +++ b/src/fr-init.c @@ -108,7 +108,7 @@ FrMimeTypeDescription mime_type_desc[] = { { "application/x-xz", ".xz", N_("Xz compressed file"), 0 }, { "application/x-xz-compressed-tar", ".tar.xz", N_("Tar compressed with xz"), 0 }, { "application/x-zoo", ".zoo", N_("Zoo"), 0 }, - { "application/x-zstd", ".zst", N_("Zstandard compressed file"), 0 }, + { ZSTD_MIME_TYPE, ".zst", N_("Zstandard compressed file"), 0 }, { "application/x-zstd-compressed-tar", ".tar.zst", N_("Tar compressed with zstd"), 0 }, { "application/zip", ".zip", N_("Zip"), 0 }, { NULL, NULL, NULL, 0 } @@ -181,7 +181,7 @@ FrExtensionType file_ext_type[] = { { ".Z", "application/x-compress" }, { ".zip", "application/zip" }, { ".zoo", "application/x-zoo" }, - { ".zst", "application/x-zstd" }, + { ".zst", ZSTD_MIME_TYPE }, { NULL, NULL } }; |