Skip to content

Commit e9edb6c

Browse files
authored
Merge pull request #277 from sgallagher/mbs_fixes
Assorted fixes for MBS
2 parents 12c111f + 8614a66 commit e9edb6c

File tree

7 files changed

+137
-17
lines changed

7 files changed

+137
-17
lines changed

modulemd/v2/include/modulemd-2.0/modulemd-module-stream.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ modulemd_module_stream_new (guint64 mdversion,
107107
* modulemd_module_stream_read_file:
108108
* @path: (in): The path to a YAML document containing a module stream
109109
* definition.
110+
* @strict: (in): Whether the parser should return failure if it encounters an
111+
* unknown mapping key or if it should ignore it.
110112
* @module_name: (in) (nullable): An optional module name to override the
111113
* document on disk. Mostly useful in cases where the name is being
112114
* auto-detected from git.
113115
* @module_stream: (in) (nullable): An optional module stream name to override
114116
* the document on disk. Mostly useful in cases where the name is being
115117
* auto-detected from git.
116-
* @strict: (in): Whether the parser should return failure if it encounters an
117-
* unknown mapping key or if it should ignore it.
118118
* @error: (out): A #GError that will return the reason for a failed read.
119119
*
120120
* Create a #ModulemdModuleStream object from a YAML file.
@@ -139,14 +139,14 @@ modulemd_module_stream_read_file (const gchar *path,
139139
* modulemd_module_stream_read_string:
140140
* @yaml_string: (in): A YAML document string containing a module stream
141141
* definition.
142+
* @strict: (in): Whether the parser should return failure if it encounters an
143+
* unknown mapping key or if it should ignore it.
142144
* @module_name: (in) (nullable): An optional module name to override the
143145
* document on disk. Mostly useful in cases where the name is being
144146
* auto-detected from git.
145147
* @module_stream: (in) (nullable): An optional module stream name to override
146148
* the document on disk. Mostly useful in cases where the name is being
147149
* auto-detected from git.
148-
* @strict: (in): Whether the parser should return failure if it encounters an
149-
* unknown mapping key or if it should ignore it.
150150
* @error: (out): A #GError that will return the reason for a failed read.
151151
*
152152
* Create a #ModulemdModuleStream object from a YAML string.
@@ -171,14 +171,14 @@ modulemd_module_stream_read_string (const gchar *yaml_string,
171171
* modulemd_module_stream_read_stream: (skip)
172172
* @stream: (in): A YAML document as a FILE * containing a module stream
173173
* definition.
174+
* @strict: (in): Whether the parser should return failure if it encounters an
175+
* unknown mapping key or if it should ignore it.
174176
* @module_name: (in) (nullable): An optional module name to override the
175177
* document on disk. Mostly useful in cases where the name is being
176178
* auto-detected from git.
177179
* @module_stream: (in) (nullable): An optional module stream name to override
178180
* the document on disk. Mostly useful in cases where the name is being
179181
* auto-detected from git.
180-
* @strict: (in): Whether the parser should return failure if it encounters an
181-
* unknown mapping key or if it should ignore it.
182182
* @error: (out): A #GError that will return the reason for a failed read.
183183
*
184184
* Create a #ModulemdModuleStream object from a YAML file.

modulemd/v2/modulemd-module-stream-v1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ modulemd_module_stream_v1_set_xmd (ModulemdModuleStreamV1 *self, GVariant *xmd)
861861
g_return_if_fail (MODULEMD_IS_MODULE_STREAM_V1 (self));
862862

863863
g_clear_pointer (&self->xmd, g_variant_unref);
864-
self->xmd = xmd;
864+
self->xmd = modulemd_variant_deep_copy (xmd);
865865
}
866866

867867
GVariant *
@@ -1069,7 +1069,7 @@ modulemd_module_stream_v1_copy (ModulemdModuleStream *self,
10691069
copy, v1_self, servicelevels, modulemd_module_stream_v1_add_servicelevel);
10701070

10711071
if (v1_self->xmd != NULL)
1072-
modulemd_module_stream_v1_set_xmd (copy, g_variant_ref (v1_self->xmd));
1072+
modulemd_module_stream_v1_set_xmd (copy, v1_self->xmd);
10731073

10741074
return MODULEMD_MODULE_STREAM (g_steal_pointer (&copy));
10751075
}
@@ -1421,7 +1421,7 @@ modulemd_module_stream_v1_parse_yaml (ModulemdSubdocumentInfo *subdoc,
14211421
return NULL;
14221422
}
14231423
modulemd_module_stream_v1_set_xmd (modulestream, xmd);
1424-
xmd = NULL;
1424+
g_clear_pointer (&xmd, g_variant_unref);
14251425
}
14261426

14271427
/* Dependencies */

modulemd/v2/modulemd-util.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,25 @@ modulemd_hash_table_unref (void *table)
271271
g_hash_table_unref ((GHashTable *)table);
272272
}
273273

274+
275+
static void
276+
destroy_variant_data (gpointer data)
277+
{
278+
g_free (data);
279+
}
280+
281+
274282
GVariant *
275283
modulemd_variant_deep_copy (GVariant *variant)
276284
{
277285
const GVariantType *data_type = g_variant_get_type (variant);
278286
gsize data_size = g_variant_get_size (variant);
279-
gconstpointer data = g_variant_get_data (variant);
287+
gpointer data = g_malloc0 (data_size);
288+
289+
g_variant_store (variant, data);
280290

281-
return g_variant_ref_sink (
282-
g_variant_new_from_data (data_type, data, data_size, TRUE, NULL, NULL));
291+
return g_variant_ref_sink (g_variant_new_from_data (
292+
data_type, data, data_size, FALSE, destroy_variant_data, data));
283293
}
284294

285295

modulemd/v2/modulemd-yaml-util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,8 @@ modulemd_yaml_emit_variant (yaml_emitter_t *emitter,
957957
g_set_error (error,
958958
MODULEMD_YAML_ERROR,
959959
MODULEMD_YAML_ERROR_EMIT,
960-
"Unhandled variant type");
960+
"Unhandled variant type: \"%s\"",
961+
g_variant_get_type_string (variant));
961962
return FALSE;
962963
}
963964
return TRUE;

modulemd/v2/tests/ModulemdTests/modulestream.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,10 @@ def test_xmd(self):
528528

529529
xmd_copy = stream.get_xmd()
530530
assert xmd_copy
531-
assert 'outer_key' in xmd
532-
assert 'scalar' in xmd['outer_key']
533-
assert 'inner_key' in xmd['outer_key'][1]
534-
assert xmd['outer_key'][1]['inner_key'] == 'another_scalar'
531+
assert 'outer_key' in xmd_copy
532+
assert 'scalar' in xmd_copy['outer_key']
533+
assert 'inner_key' in xmd_copy['outer_key'][1]
534+
assert xmd_copy['outer_key'][1]['inner_key'] == 'another_scalar'
535535

536536
def test_upgrade(self):
537537
v1_stream = Modulemd.ModuleStreamV1.new("SuperModule", "latest")
@@ -1129,6 +1129,38 @@ def test_validate_buildafter(self):
11291129
"%s/modulemd/v2/tests/test_data/buildafter/invalid_key.yaml" %
11301130
(os.getenv('MESON_SOURCE_ROOT')), True)
11311131

1132+
def test_unicode_desc(self):
1133+
# Test a valid module stream with unicode in the description
1134+
stream = Modulemd.ModuleStream.read_file(
1135+
"%s/modulemd/v2/tests/test_data/stream_unicode.yaml" %
1136+
(os.getenv('MESON_SOURCE_ROOT')), True, '', '')
1137+
1138+
self.assertIsNotNone(stream)
1139+
self.assertTrue(stream.validate())
1140+
1141+
def test_xmd_issue_274(self):
1142+
# Test a valid module stream with unicode in the description
1143+
stream = Modulemd.ModuleStream.read_file(
1144+
"%s/modulemd/v2/tests/test_data/stream_unicode.yaml" %
1145+
(os.getenv('MESON_SOURCE_ROOT')), True, '', '')
1146+
1147+
# In this bug, we were getting a traceback attemping to call
1148+
# get_xmd() more than once on the same stream. There were subtle
1149+
# memory issues at play here.
1150+
if '_overrides_module' in dir(Modulemd):
1151+
# The XMD python tests can only be run against the installed lib
1152+
# because the overrides that translate between python and GVariant
1153+
# must be installed in /usr/lib/python*/site-packages/gi/overrides
1154+
# or they are not included when importing Modulemd
1155+
1156+
xmd = stream.get_xmd()
1157+
mbs_xmd = stream.get_xmd()['mbs']
1158+
mbs_xmd2 = stream.get_xmd()['mbs']
1159+
1160+
else:
1161+
stream.get_xmd()
1162+
stream.get_xmd()
1163+
11321164

11331165
if __name__ == '__main__':
11341166
unittest.main()

modulemd/v2/tests/test-modulemd-modulestream.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,52 @@ module_stream_v2_test_rpm_map (ModuleStreamFixture *fixture,
911911
g_assert_true (modulemd_rpm_map_entry_equals (entry, retrieved_entry));
912912
}
913913

914+
static void
915+
module_stream_v2_test_unicode_desc (void)
916+
{
917+
g_autoptr (ModulemdModuleStream) stream = NULL;
918+
g_autofree gchar *path = NULL;
919+
g_autoptr (GError) error = NULL;
920+
921+
/* Test a module stream with unicode in description */
922+
path = g_strdup_printf ("%s/modulemd/v2/tests/test_data/stream_unicode.yaml",
923+
g_getenv ("MESON_SOURCE_ROOT"));
924+
g_assert_nonnull (path);
925+
926+
stream = modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
927+
g_assert_nonnull (stream);
928+
g_assert_no_error (error);
929+
}
930+
931+
932+
static void
933+
module_stream_v2_test_xmd_issue_274 (void)
934+
{
935+
g_autoptr (ModulemdModuleStream) stream = NULL;
936+
g_autofree gchar *path = NULL;
937+
g_autoptr (GError) error = NULL;
938+
GVariant *xmd1 = NULL;
939+
GVariant *xmd2 = NULL;
940+
941+
path = g_strdup_printf ("%s/modulemd/v2/tests/test_data/stream_unicode.yaml",
942+
g_getenv ("MESON_SOURCE_ROOT"));
943+
g_assert_nonnull (path);
944+
945+
stream = modulemd_module_stream_read_file (path, TRUE, NULL, NULL, &error);
946+
g_assert_nonnull (stream);
947+
g_assert_no_error (error);
948+
g_assert_cmpint (modulemd_module_stream_get_mdversion (stream),
949+
==,
950+
MD_MODULESTREAM_VERSION_ONE);
951+
952+
xmd1 =
953+
modulemd_module_stream_v1_get_xmd (MODULEMD_MODULE_STREAM_V1 (stream));
954+
xmd2 =
955+
modulemd_module_stream_v1_get_xmd (MODULEMD_MODULE_STREAM_V1 (stream));
956+
957+
g_assert_true (xmd1 == xmd2);
958+
}
959+
914960

915961
int
916962
main (int argc, char *argv[])
@@ -1012,6 +1058,11 @@ main (int argc, char *argv[])
10121058
module_stream_v2_test_rpm_map,
10131059
NULL);
10141060

1061+
g_test_add_func ("/modulemd/v2/modulestream/v2/unicode/description",
1062+
module_stream_v2_test_unicode_desc);
1063+
1064+
g_test_add_func ("/modulemd/v2/modulestream/v2/xmd/issue274",
1065+
module_stream_v2_test_xmd_issue_274);
10151066

10161067
return g_test_run ();
10171068
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
document: modulemd
2+
version: 1
3+
data:
4+
description: Fedora 28 traditional base ’
5+
name: platform
6+
license:
7+
module: [MIT]
8+
profiles:
9+
buildroot:
10+
rpms: [bash, bzip2, coreutils, cpio, diffutils, fedora-release, findutils, gawk,
11+
gcc, gcc-c++, grep, gzip, info, make, patch, redhat-rpm-config, rpm-build,
12+
sed, shadow-utils, tar, unzip, util-linux, which, xz]
13+
srpm-buildroot:
14+
rpms: [bash, fedora-release, fedpkg-minimal, gnupg2, redhat-rpm-config, rpm-build,
15+
shadow-utils]
16+
stream: f28
17+
summary: Fedora 28 traditional base
18+
version: 3
19+
context: 00000000
20+
xmd:
21+
mbs:
22+
buildrequires: {}
23+
commit: virtual
24+
requires: {}
25+
mse: true
26+
koji_tag: module-f28-build

0 commit comments

Comments
 (0)