archrelease: copy trunk to extra-x86_64
[arch-packages.git] / glib2 / trunk / 0002-glocalfile-Sum-apparent-size-only-for-files-and-syml.patch
blob8e96aaf3008a336166b545b102a1e2bcddf75d59
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Joan Bruguera <joanbrugueram@gmail.com>
3 Date: Thu, 23 Mar 2023 02:24:30 +0000
4 Subject: [PATCH] glocalfile: Sum apparent size only for files and symlinks
6 Since GNU Coreutils 9.2 (commit 110bcd28386b1f47a4cd876098acb708fdcbbb25),
7 `du --apparent-size` (including `du --bytes`) no longer counts all kinds of
8 files (directories, FIFOs, etc.), but only those for which `st_size` in
9 `struct stat` is defined by POSIX, namely regular files and symlinks
10 (and also rarely supported memory objects).
12 This aligns the behaviour of GLib's `G_FILE_MEASURE_APPARENT_SIZE` flag
13 with the new GNU Coreutils `du` and correct POSIX use.
15 Note that this may be a breaking change for some uses.
17 Link: https://lists.gnu.org/archive/html/bug-coreutils/2023-03/msg00007.html
18 Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2965
19 ---
20 gio/glocalfile.c | 21 +++++++++++++++++++++
21 1 file changed, 21 insertions(+)
23 diff --git a/gio/glocalfile.c b/gio/glocalfile.c
24 index 67d4b99fb741..e53216962faf 100644
25 --- a/gio/glocalfile.c
26 +++ b/gio/glocalfile.c
27 @@ -86,6 +86,9 @@
28 #define FILE_READ_ONLY_VOLUME 0x00080000
29 #endif
31 +#ifndef S_ISREG
32 +#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
33 +#endif
34 #ifndef S_ISDIR
35 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
36 #endif
37 @@ -2777,6 +2780,23 @@ g_local_file_measure_size_of_contents (gint fd,
38 MeasureState *state,
39 GError **error);
41 +inline static gboolean _g_stat_is_size_usable (const GLocalFileStat *buf)
43 +#ifndef HAVE_STATX
44 + // Memory objects are defined by POSIX, but are not supported by statx nor Windows
45 +#ifdef S_TYPEISSHM
46 + if (S_TYPEISSHM (buf))
47 + return TRUE;
48 +#endif
49 +#ifdef S_TYPEISTMO
50 + if (S_TYPEISTMO (buf))
51 + return TRUE;
52 +#endif
53 +#endif
55 + return S_ISREG (_g_stat_mode (buf)) || S_ISLNK (_g_stat_mode (buf));
58 static gboolean
59 g_local_file_measure_size_of_file (gint parent_fd,
60 GSList *name,
61 @@ -2836,6 +2856,7 @@ g_local_file_measure_size_of_file (gint parent_fd,
62 state->disk_usage += _g_stat_blocks (&buf) * G_GUINT64_CONSTANT (512);
63 else
64 #endif
65 + if (_g_stat_is_size_usable (&buf))
66 state->disk_usage += _g_stat_size (&buf);
68 if (S_ISDIR (_g_stat_mode (&buf)))