Commit Graph

9075 Commits

Author SHA1 Message Date
Ignacy Kuchciński
181992ccb5 glocalfile: Verify deleting from trash beforehand
Verify that you can delete the file from the trash before moving it, if
the file is a directory owned by the user, recursively check for
non-empty directory not owned by he user.

Closes https://gitlab.gnome.org/GNOME/glib/-/issues/1665
2025-06-12 13:26:22 +02:00
Ignacy Kuchciński
2a7f28e88a glocalfile: Populate different statbuf for parent
Populate a different statbuf for the parent directory, so that we can
keep using file_state for the file we're removing later in the code.
2025-06-11 10:33:50 +02:00
Philip Withnall
b2f0bb9592 tests: Expand PATH for Python tests on Windows
This works around a Meson bug
(https://github.com/mesonbuild/meson/issues/4668).

If we have a Python test which spawns a built native binary, that binary is
listed in the `depends` argument of the `test()`. On Linux, this results in
the directories containing the built libraries which the binary depends on
being added to the `LD_LIBRARY_PATH` of the test invocation. On Windows,
however, Meson currently doesn’t add those directories to `PATH` (which is
the equivalent of `LD_LIBRARY_PATH`), so we have to do it manually.

This takes the same approach as Christoph Reiter did in
gobject-introspection
(13e8c7ff80/tests/meson.build (L2)).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-05-28 16:10:55 +01:00
Philip Withnall
ac2ecb5a43 tests: Add e flag to fdopen() calls in gsubprocess tests
Unlike the previous commit, there is no `g_fdopen()` wrapper where we
can add cross-platform support for this.

I’m not adding that now just for `O_CLOEXEC` support for these two
calls, so pass the flag locally for now.

If someone wanted to add a `g_fdopen()` wrapper in future, the
`GLIB_FD_CLOEXEC` here could be refactored easily.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-05-28 14:37:08 +01:00
Philip Withnall
f9a7ac11f5 gstdio: Add support for the e flag (O_CLOEXEC) to g_fopen()
This adds cross-platform support for it: on glibc, musl and BSD’s libc,
the flag is natively supported. On Windows, convert it to the `N` flag,
which similarly indicates that an open file shouldn’t be inherited by
child processes.

This allows us to unconditionally pass `e` to `g_fopen()` so `O_CLOEXEC`
can easily be set on its FDs.

Also do the same for `g_freopen()`, since it shares the same underlying
mode handling code.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-05-28 14:37:02 +01:00
fbrouille
281f30ef41 gio: add 'type filename' annotation for 'g_vfs_get_file_for_path'
Add the 'type filename' annotation on the parameter 'path'.
2025-05-21 16:08:52 +00:00
fbrouille
5a546d452e gio: add nullable annotation for 'g_file_monitor_emit_event'
Add the nullable annotation on the parameter 'other_file'
and fix the description.
2025-05-21 16:08:38 +00:00
Philip Withnall
fc79ee45ec Merge branch 'android_no_faccessat' into 'main'
glocalfile: Disable faccessat()-based query_exists on Android

See merge request GNOME/glib!4620
2025-05-20 15:14:40 +00:00
Philip Withnall
25677d10bf Merge branch '3616-action-map-docs' into 'main'
gactionmap: Fix broken link in documentation comment

Closes #3616

See merge request GNOME/glib!4505
2025-05-20 14:35:17 +00:00
Colin Kinloch
06602315c3 glocalfile: Disable faccessat()-based query_exists on Android
The bionic version of faccessat() returns EINVAL when flags are set.

See 35778253a5
2025-05-20 15:00:02 +01:00
Fina Wilke
b36e646b54 gdesktopappinfo: Prefer matches that occur earlier in the match string
Some apps names or keywords contain multiple words. For example 'LibreOffice
Calc' contains the word 'Calc'. This is rightfully detected as a prefix match,
however generally it is expected that searching for 'calc' would consistantly
return 'Calculator' in first position, instead of ranking them equally.

We now prioritise tokens that would otherwise rank equal based on where they
occur in the string, giving earlier occurences precedence.
2025-05-17 15:43:13 +02:00
Michael Catanzaro
290d90473d Merge branch 'gzlib-docs' into 'main'
gzlibcompressor: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4633
2025-05-14 11:35:03 -05:00
Philip Withnall
843779903c Merge branch 'socket_address_native_size' into 'main'
docs: Description of return value of get_native_size

Closes #2377

See merge request GNOME/glib!4625
2025-05-14 10:44:20 +00:00
Philip Withnall
13a73f9008 gzlibcompressor: Convert docs to gi-docgen linking syntax
Improve formatting while I’m there, and try and ensure all the docs in
these two files matches the
[guidelines](https://developer.gnome.org/documentation/guidelines/devel-docs.html#writing-api-references).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2025-05-14 11:38:05 +01:00
Benjamin Otte
f5b0415539 gio: Add GZlibCompressor:os property
The use case for exposing this field is GTK wanting reproducible
encoding output across different OSes.

I decided to expose the OS as an integer because zlib uses an int
in its header and does not make its OS codes available as a custom
type in its API.

I also decided to limit it to values between 0 and 255 because zlib
encodes the OS as a single byte.

Test included.

Fixes: #3663
2025-05-12 09:07:57 +02:00
marklkram
c0c0e212d9 docs: Description of return value of get_native_size
Specified that if the user passes an invalid address, the function returns -1.

closes #2377
2025-05-10 22:28:18 -04:00
marklkram
fdd41f9b65 docs: Description of return value of get_native_size
Specified that if the user passes an address that is not of type AF_INET or AF_INET6 ,
the function returns -1.

closes #2377
2025-05-07 15:58:50 -04:00
Gleb Popov
b479d14371 Fix GNetworkMonitorNetlink operation under a FreeBSD jail with shared network stack 2025-04-21 22:28:49 +00:00
Marvin W
cf44fb0d2a cocoa: add support for GBytesIcon in notification backend 2025-04-18 14:36:34 +02:00
Sergey Bugaev
bf266f4116 gtlsconnection: Fix annotation
The array is allocated by the *caller*, not the callee, and then filled
by the callee during the call.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2025-04-14 15:32:18 +03:00
Philip Withnall
2d66caf6cb Merge branch 'wsign-conversion' into 'main'
Various -Wsign-conversion warning fixes

See merge request GNOME/glib!4590
2025-04-11 13:35:16 +00:00
Philip Withnall
98ab3d7a87 xdgmime: Disable -Wsign-conversion warning inside xdgmime
The code wasn’t written for it, and we don’t want to diverge from
upstream for this, so disable -Wsign-conversion in case it was set for
the overall GLib build.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
2025-04-11 14:02:55 +01:00
Michael Catanzaro
defec7eef2 gthreadedresolver: fix crash in loopback interface check
It's expected that an interface may have a NULL socket address, so just
skip it and don't crash if so. In practice, this occurs for VPN
interfaces.

Fixes: fe0139ee98
2025-04-10 15:42:21 -05:00
Philip Withnall
a33df3d81e gfile: Expand documentation around file info for inaccessible files
Make it a bit clearer that a returned `GFileInfo` can be empty if
`stat()` fails (e.g. with `EACCES`), and that it’s the caller’s
responsibility to use `g_file_info_has_attribute()` before retrieving
attribute values.

This better documents what we implemented in, for example, !3336.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3658
2025-04-08 16:59:20 +01:00
Philip Withnall
9d466bddc2 gfile: Port the g_file_query_info() doc comment to gi-docgen
This doesn’t change its content.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3250
2025-04-08 16:54:19 +01:00
Julian Sparber
91a1ff3b5c gdbus-tool call: Allow handles inside nested containers
This recursively walks the entire input of `gdbus call` to find file
descriptor handles allowing to nest handles inside container types.

Closes: https://gitlab.gnome.org/GNOME/glib/-/issues/3624
2025-04-07 15:12:07 +02:00
Philip Withnall
1bf83890a0 Merge branch '1250-socket-listener-leak' into 'main'
gsocketlistener: Fix IPv4 listen() error handling

Closes #1250

See merge request GNOME/glib!643
2025-04-03 15:15:59 +00:00
Philip Withnall
f31c072005 Merge branch 'pgriffis/gresolver-onlyloopback' into 'main'
threadedresolver: Return valid addresses when only having loopback interfaces

Closes #3641

See merge request GNOME/glib!4566
2025-04-03 15:09:58 +00:00
Philip Withnall
56515e93a7 Merge branch '3527-Wshorten-64-to-32' into 'main'
Fix various -Wshorten-64-to-32 warnings

See merge request GNOME/glib!4387
2025-04-03 15:07:09 +00:00
Philip Withnall
29e27d8dcd Merge branch 'cancellable-connection-fixes' into 'main'
cancellable: Fix connect and disconnect references handling

Closes #3642 and #3643

See merge request GNOME/glib!4573
2025-04-03 13:55:49 +00:00
Marco Trevisan (Treviño)
a2f98c86ff gio/cancellable: Never call toggle notify callback in locked state
We had code to avoid that we could call a toggle "up" notification
callback in locked state, but this was not covering the case in which
the cancellable second to last reference was removed in its cancellation
callback.

In fact, in such case we end up going from 2 -> 1 references during the
signal callback call and this leads to calling the toggle notify
callback in locked state.

To prevent this, add an even further reference before calling the
callback (in locked state, but there's no risk that a toggle-up
notification happens now), and drop it once unlocked again.
2025-04-03 15:22:16 +02:00
Marco Trevisan (Treviño)
ec2fee555f gio/cancellable: Do not call data destroy function while locked
If when calling g_cancellable_connect() the cancellable was already
cancelled we could have ended up in calling the data cleanup
function while the cancellable lock was held.

This is likely not an issue, but it's still better not to do it,
so protect the code against it
2025-04-03 15:22:16 +02:00
Marco Trevisan (Treviño)
c6ace7aaf7 gio/cancellable: Fix comments for g_cancellable_connect()
We had wrong comments, in particular:

  @callback is called exactly once each time @cancellable is cancelled,
  either directly at the time of the connect if @cancellable is already
  cancelled, or when @cancellable is cancelled in some thread.
  In case the cancellable is reset via [method@Gio.Cancellable.reset]
  then the callback can be called again if the @cancellable is cancelled

This is not true if `@cancellable` is already cancelled because then the
callback will be thrown away, and will not be called for subsequent
cancellations.

  Since GLib 2.40, the lock protecting @cancellable is not held when
  @callback is invoked.  This lifts a restriction in place for
  earlier GLib versions which now makes it easier to write cleanup
  code that unconditionally invokes e.g. g_cancellable_cancel().

As per commit 3a07b2abd4 this section needs some amending since
it's not true anymore, as the GCancellable's mutex is held when `@callback` is
invoked. However this happens in a way that it's still safe to call most
of the GCancellable API.

Closes: #3642
2025-04-03 15:22:16 +02:00
Philip Withnall
7ea714e658 Merge branch 'wip/3v1n0/sanitizer-memory-fixes' into 'main'
Memory sanitizer fixes

See merge request GNOME/glib!4484
2025-04-03 13:04:05 +00:00
Marco Trevisan (Treviño)
49680afd5c gio/cancellable: Always add reference while emitting cancelled signal
When a non-cancelled cancellable ::cancelled signal callback is called
the cancellable has enough references so that it can be unreferenced on
the callback itself. However this doesn't happen if the cancellable has
been already cancelled at the moment we connect to it.

To prevent this, add a temporary reference before calling the signal
callback.

Note that we do this also if the callback has not been already cancelled
to prevent that we may end up calling a toggle-notify callback while we
are locked.

Add tests

Closes: #3643
2025-04-03 14:48:57 +02:00
Marco Trevisan (Treviño)
7432441581 test/cancellable: Check that a cancellable can be unreffed on callback
This works when the cancellable has not been cancelled yet.
2025-04-03 14:48:56 +02:00
Marco Trevisan (Treviño)
ea52feb658 gio/tests/gdbus-export: Ensure we call all the callbacks on return
Ensure we don't do an user-after-free access, as reported by ASAN:

  ==3704==ERROR: AddressSanitizer: stack-use-after-return on address
   0x70a58f8631c0 at pc 0x000000405144 bp 0x7fffff62c7a0 sp 0x7fffff62c798
   READ of size 4 at 0x70a58f8631c0 thread T0
    #0 0x405143 in on_object_unregistered ../../GNOME/glib/gio/tests/gdbus-export.c:597
    #1 0x70a592e858d8 in call_destroy_notify_data_in_idle ../../GNOME/glib/gio/gdbusconnection.c:244
    #2 0x70a5940016a4 in g_idle_dispatch ../../GNOME/glib/glib/gmain.c:6221
    #3 0x70a59401095b in g_main_dispatch ../../GNOME/glib/glib/gmain.c:3348
    #4 0x70a59401095b in g_main_context_dispatch_unlocked ../../GNOME/glib/glib/gmain.c:4197
    #5 0x70a59401ba17 in g_main_context_iterate_unlocked ../../GNOME/glib/glib/gmain.c:4262
    #6 0x70a59401cc73 in g_main_context_iteration ../../GNOME/glib/glib/gmain.c:4327
    #7 0x405658 in test_threaded_unregistration_iteration ../../GNOME/glib/gio/tests/gdbus-export.c:1878
    #8 0x405658 in test_threaded_unregistration ../../GNOME/glib/gio/tests/gdbus-export.c:1952
    #9 0x70a5940dfb04 in test_case_run ../../GNOME/glib/glib/gtestutils.c:2988
    #10 0x70a5940dfb04 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3090
    #11 0x70a5940df893 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3109
    #12 0x70a5940df893 in g_test_run_suite_internal ../../GNOME/glib/glib/gtestutils.c:3109
    #13 0x70a5940e0bc9 in g_test_run_suite ../../GNOME/glib/glib/gtestutils.c:3189
    #14 0x70a5940e0d1f in g_test_run ../../GNOME/glib/glib/gtestutils.c:2275
    #15 0x40eb72 in session_bus_run ../../GNOME/glib/gio/tests/gdbus-sessionbus.c:69
    #16 0x403a2c in main ../../GNOME/glib/gio/tests/gdbus-export.c:1990
    #17 0x70a591d9f149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
    #18 0x70a591d9f20a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 0d710e9d9dc10c500b8119c85da75004183618e2)
    #19 0x403b44 in _start (/tmp/_build/gio/tests/gdbus-export+0x403b44) (BuildId: f6312e919c3d94e4c49270b0dfc5c870e1ba550b)

Address 0x70a58f8631c0 is located in stack of thread T0 at offset 192 in frame
    #0 0x40525f in test_threaded_unregistration ../../GNOME/glib/gio/tests/gdbus-export.c:1936

  This frame has 7 object(s):
    [32, 40) 'local_error' (line 1835)
    [64, 72) 'unregister_thread' (line 1836)
    [96, 104) 'value' (line 1838)
    [128, 136) 'value_str' (line 1839)
    [160, 168) 'call_result' (line 1840)
    [192, 204) 'object_registration_data' (line 1834) <== Memory access at offset 192 is inside this variable
    [224, 240) 'data' (line 1833)
2025-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
6ed59a6f40 gio/tests/gdbus-connection: Fix typo 2025-04-03 13:58:15 +02:00
Marco Trevisan (Treviño)
7086823bb2 cancellable: Connect to cancelled signal using the ID
Avoid fetching the signal-ID by its name since we know it here
2025-04-02 21:28:03 +02:00
Emmanuele Bassi
93371e1f56 Merge branch 'dbus-name-owning-docs' into 'main'
gdbusnameowning: Convert docs to gi-docgen linking syntax

See merge request GNOME/glib!4562
2025-04-02 13:10:05 +00:00
Patrick Griffis
cce3001d5d threadedresolver: Cache network interface checks 2025-04-01 19:11:49 -05:00
Philip Withnall
585ec33763 gwin32appinfo: Clarify some variable names
See the previous commit. Clarify these variable names so it’s more
obvious they contain a size in bytes rather than a length in wide-chars.

This introduces no functional changes.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3649
2025-04-01 16:05:44 +01:00
Philip Withnall
6f9bb9b784 gwin32registrykey: Clarify that value sizes are in bytes
It can be confusing otherwise when getting string values: is the size in
bytes or wide-characters?

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3649
2025-04-01 16:04:01 +01:00
Philip Withnall
464dd6fb6b gwin32appinfo: Fix an incorrect size vs wide-length comparison
`value_size` is in bytes, whereas `ms_resource_prefix_len` is in wide
characters, so they cannot be compared directly. This meant that if
12 ≤ `value_size` < 24 then the call to `memcmp()` would read off the
end of `value`.

Fix it by using a wide-character and nul-aware comparison function and
operating only on wide-lengths. This is safe because
`g_win32_registry_key_get_value_w()` guarantees that string-typed return
values are nul-terminated.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3649
2025-04-01 15:50:00 +01:00
Patrick Griffis
fe0139ee98 threadedresolver: Return valid addresses when only having loopback interfaces
The AI_ADDRCONFIG flag filters out addresses for invalid interfaces. This causes it to resolve nothing when only having loopback interfaces.

So we can detect if you only have loopback interfaces, request all addresses, and filter out non-loopback results.

Closes #3641
2025-03-24 09:44:55 -05:00
Patrick Griffis
752b6447d8 socketaddress: Use more clear GSocketFamily type
The value of them should be identical, but it feels odd to
not pass the expected enum type.
2025-03-24 09:43:42 -05:00
Patrick Griffis
bbba92630b threadedresolver: Clean up variable scope
Keep the scope limited.
2025-03-24 09:43:42 -05:00
Philip Withnall
e7b820d66c tests: Move various test paths to g_get_tmp_dir()
Rather than creating files in the current directory. This is a bit
neater, and avoids races between parallel invocations of the unit tests
if the file names aren’t guaranteed to be unique (e.g. by using
`g_mkstemp()`).

Add `G_TEST_OPTION_ISOLATE_DIRS` too, to make sure we use a unique
subdirectory of `g_get_tmp_dir()`. This means that paths like
`g_get_tmp_dir() / some-file` are guaranteed to be race-free even if the
filename is not unique, because the test tmp dir now is.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:49 +00:00
Philip Withnall
4d2b873211 tests: Use g_build_filename() rather than g_strdup_printf()
In the `g-file-info-filesystem-readonly` test.

This doesn’t introduce any functional changes, but makes the code a
little easier to read (because the parts of the path are now in
hierarchical order) and makes it a bit clearer that we’re building a
path rather than an arbitrary string.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:45 +00:00
Philip Withnall
4345eb2756 tests: Only use g_mkstemp() in /tmp rather than current directory
It’s not entirely clear from the documentation, but `g_mkstemp()` (and
`g_mkdtemp()`) operate in the current directory, rather than the system
temporary directory.

This meant these tests were all writing files to the build directory.
This is messy, though thankfully not a correctness issue or a race
because `g_mkstemp()` guarantees to return a unique file for each
caller.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2025-03-21 14:02:36 +00:00