archrelease: copy trunk to extra-x86_64
[arch-packages.git] / glib2 / trunk / 0003-tests-file-Do-not-rely-on-du-bytes-behaviour.patch
blob5c9c53da8c9e6524477129d99b8f14fba0054a7c
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Joan Bruguera <joanbrugueram@gmail.com>
3 Date: Thu, 23 Mar 2023 02:19:03 +0000
4 Subject: [PATCH] tests/file: Do not rely on du --bytes behaviour
6 As explained in the previous commit, GNU Coreutils 9.2 changes the behaviour
7 of `du --bytes` to only count regular files and symlinks.
9 The previous commit makes the test pass with GNU Coreutils >=9.2, but the
10 machine running the tests may have an older version, or perhaps even a
11 reimplementation such as uutils. So we can't rely on the size returned by `du`
12 to be the consistent across systems any more.
14 However, the plus side of the new behaviour is that the size reported by `du`
15 / `G_FILE_MEASURE_APPARENT_SIZE` is now well-defined across filesystems
16 (as the sum of the sizes of regular files & symlinks), so we can hardcode it.
18 Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2965
19 ---
20 gio/tests/file.c | 85 ++----------------------------------------------
21 1 file changed, 3 insertions(+), 82 deletions(-)
23 diff --git a/gio/tests/file.c b/gio/tests/file.c
24 index d16eda5c0b8c..ad2f945f9397 100644
25 --- a/gio/tests/file.c
26 +++ b/gio/tests/file.c
27 @@ -2515,105 +2515,33 @@ test_copy_preserve_mode (void)
28 #endif
31 -static gchar *
32 -splice_to_string (GInputStream *stream,
33 - GError **error)
35 - GMemoryOutputStream *buffer = NULL;
36 - char *ret = NULL;
38 - buffer = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
39 - if (g_output_stream_splice ((GOutputStream*)buffer, stream, 0, NULL, error) < 0)
40 - goto out;
42 - if (!g_output_stream_write ((GOutputStream*)buffer, "\0", 1, NULL, error))
43 - goto out;
45 - if (!g_output_stream_close ((GOutputStream*)buffer, NULL, error))
46 - goto out;
48 - ret = g_memory_output_stream_steal_data (buffer);
49 - out:
50 - g_clear_object (&buffer);
51 - return ret;
54 -static gboolean
55 -get_size_from_du (const gchar *path, guint64 *size)
57 - GSubprocess *du;
58 - gboolean ok;
59 - gchar *result;
60 - gchar *endptr;
61 - GError *error = NULL;
62 - gchar *du_path = NULL;
64 -#ifndef __APPLE__
65 - du_path = g_find_program_in_path ("du");
66 -#endif
68 - /* If we can’t find du, don’t try and run the test. */
69 - if (du_path == NULL)
70 - return FALSE;
72 - g_free (du_path);
74 - du = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE,
75 - &error,
76 - "du", "--bytes", "-s", path, NULL);
77 - g_assert_no_error (error);
79 - result = splice_to_string (g_subprocess_get_stdout_pipe (du), &error);
80 - g_assert_no_error (error);
82 - *size = g_ascii_strtoll (result, &endptr, 10);
84 - g_subprocess_wait (du, NULL, &error);
85 - g_assert_no_error (error);
87 - ok = g_subprocess_get_successful (du);
89 - g_object_unref (du);
90 - g_free (result);
92 - return ok;
95 static void
96 test_measure (void)
98 GFile *file;
99 - guint64 size;
100 guint64 num_bytes;
101 guint64 num_dirs;
102 guint64 num_files;
103 GError *error = NULL;
104 gboolean ok;
105 gchar *path;
107 path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL);
108 file = g_file_new_for_path (path);
110 - if (!get_size_from_du (path, &size))
112 - g_test_message ("du not found or fail to run, skipping byte measurement");
113 - size = 0;
116 ok = g_file_measure_disk_usage (file,
117 G_FILE_MEASURE_APPARENT_SIZE,
118 NULL,
119 NULL,
120 NULL,
121 &num_bytes,
122 &num_dirs,
123 &num_files,
124 &error);
125 g_assert_true (ok);
126 g_assert_no_error (error);
128 - if (size > 0)
129 - g_assert_cmpuint (num_bytes, ==, size);
130 + g_assert_cmpuint (num_bytes, ==, 74478);
131 g_assert_cmpuint (num_dirs, ==, 6);
132 g_assert_cmpuint (num_files, ==, 32);
134 @@ -2665,8 +2593,7 @@ measure_done (GObject *source,
135 g_assert_true (ok);
136 g_assert_no_error (error);
138 - if (data->expected_bytes > 0)
139 - g_assert_cmpuint (data->expected_bytes, ==, num_bytes);
140 + g_assert_cmpuint (data->expected_bytes, ==, num_bytes);
141 g_assert_cmpuint (data->expected_dirs, ==, num_dirs);
142 g_assert_cmpuint (data->expected_files, ==, num_files);
144 @@ -2695,15 +2622,9 @@ test_measure_async (void)
146 path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL);
147 file = g_file_new_for_path (path);
149 - if (!get_size_from_du (path, &data->expected_bytes))
151 - g_test_message ("du not found or fail to run, skipping byte measurement");
152 - data->expected_bytes = 0;
155 g_free (path);
157 + data->expected_bytes = 74478;
158 data->expected_dirs = 6;
159 data->expected_files = 32;