Skip to content

Commit

Permalink
libzstd disable support added.
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Nov 24, 2023
1 parent d2eb316 commit a3d769b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ yaml_dep = dependency('yaml-0.1')
xmlb_dep = dependency('xmlb', version: '>= 0.3.14',
fallback: ['libxmlb', 'libxmlb_dep'],
default_options: ['gtkdoc=false', 'introspection=false'])
zstd_dep = dependency('libzstd')
libsystemd_dep = dependency('libsystemd', required: get_option('systemd'))

if get_option('zstd')
zstd_dep = dependency('libzstd', required: get_option('zstd'))
else
add_project_arguments('-DNO_ZSTD', language: 'c')
endif

if get_option ('gir')
# ensure we have a version of GIR that isn't broken with Meson
# (prior versions failed when any non-GObject library was linked)
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ option('qt5',
value : false,
description: 'Build libappstream-qt5 for Qt5'
)
option('zstd',
type : 'boolean',
value : true,
description: 'Zstd support'
)
option('compose',
type : 'boolean',
value : false,
Expand Down
8 changes: 7 additions & 1 deletion src/as-metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
#include "as-release-list-private.h"
#include "as-context-private.h"
#include "as-desktop-entry.h"
#ifndef NO_ZSTD
#include "as-zstd-decompressor.h"
#endif

#include "as-xml.h"
#include "as-yaml.h"
Expand Down Expand Up @@ -750,14 +752,18 @@ as_metadata_parse_file (AsMetadata *metad, GFile *file, AsFormatKind format, GEr
g_propagate_error (error, tmp_error);
return FALSE;
}

#ifndef NO_ZSTD
if (as_str_equal0 (content_type, "application/zstd")) {
/* decompress the Zstd stream */
conv = G_CONVERTER (as_zstd_decompressor_new ());
stream_data = g_converter_input_stream_new (file_stream, conv);

} else if (as_str_equal0 (content_type, "application/gzip") ||
as_str_equal0 (content_type, "application/x-gzip")) {
#else
if (as_str_equal0 (content_type, "application/gzip") ||
as_str_equal0 (content_type, "application/x-gzip")) {
#endif
/* decompress the GZip stream */
conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
stream_data = g_converter_input_stream_new (file_stream, conv);
Expand Down
8 changes: 6 additions & 2 deletions src/as-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
#include "as-metadata.h"
#include "as-component-private.h"
#include "as-desktop-env-data.h"
#ifndef NO_ZSTD
#include "as-zstd-decompressor.h"

#endif
/**
* SECTION:as-utils
* @short_description: Helper functions that are used inside libappstream
Expand Down Expand Up @@ -2260,12 +2261,15 @@ as_utils_extract_tarball (const gchar *filename, const gchar *target_dir, GError
if (tarz_stream == NULL)
return FALSE;

#ifndef NO_ZSTD
if (g_str_has_suffix (filename, "tar.zst")) {
/* decompress the Zstd stream */
conv = G_CONVERTER (as_zstd_decompressor_new ());
tar_stream = g_converter_input_stream_new (tarz_stream, conv);

} else if (g_str_has_suffix (filename, "tar.gz")) {
#else
if (g_str_has_suffix (filename, "tar.gz")) {
#endif
/* decompress the GZip stream */
conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
tar_stream = g_converter_input_stream_new (tarz_stream, conv);
Expand Down
8 changes: 7 additions & 1 deletion src/as-validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
#include "as-yaml.h"
#include "as-desktop-entry.h"
#include "as-content-rating-private.h"
#ifndef NO_ZSTD
#include "as-zstd-decompressor.h"
#endif

typedef struct {
GHashTable *issue_tags; /* of utf8:AsValidatorIssueTag */
Expand Down Expand Up @@ -3531,14 +3533,18 @@ as_validator_validate_file (AsValidator *validator, GFile *metadata_file)
}
if (file_stream == NULL)
return FALSE;

#ifndef NO_ZSTD
if (as_str_equal0 (content_type, "application/zstd")) {
/* decompress the Zstd stream */
conv = G_CONVERTER (as_zstd_decompressor_new ());
stream_data = g_converter_input_stream_new (file_stream, conv);

} else if (as_str_equal0 (content_type, "application/gzip") ||
as_str_equal0 (content_type, "application/x-gzip")) {
#else
if (as_str_equal0 (content_type, "application/gzip") ||
as_str_equal0 (content_type, "application/x-gzip")) {
#endif
/* decompress the GZip stream */
conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP));
stream_data = g_converter_input_stream_new (file_stream, conv);
Expand Down
13 changes: 9 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ aslib_src = [
'as-tag.c',
'as-xml.c',
'as-yaml.c',
'as-zstd-decompressor.c',
# (mostly) public
'as-agreement.c',
'as-agreement-section.c',
Expand Down Expand Up @@ -137,7 +136,6 @@ aslib_priv_headers = [
'as-validator-issue-tag.h',
'as-xml.h',
'as-yaml.h',
'as-zstd-decompressor.h',
]

as_version_h = configure_file(
Expand Down Expand Up @@ -190,12 +188,19 @@ aslib_deps = [glib_dep,
xmlb_dep,
xml2_dep,
yaml_dep,
libsystemd_dep,
zstd_dep]
libsystemd_dep]
if get_option ('stemming')
aslib_deps += [stemmer_lib]
endif

if get_option ('zstd')
aslib_deps += [zstd_dep]
aslib_src += ['as-zstd-decompressor.c']
aslib_priv_headers += ['as-zstd-decompressor.h']
endif



appstream_lib = library ('appstream',
[aslib_src,
aslib_pub_headers,
Expand Down

0 comments on commit a3d769b

Please sign in to comment.