Commit Graph

21975 Commits

Author SHA1 Message Date
Philip Withnall
24ed91ce33 gfileutils: Add a mode argument to g_file_set_contents_full()
This is used when creating the temporary file, or new file from scratch.

I wondered about also allowing the file owner and group to be set, but
that’s not as generally applicable — if your process is operating across
multiple user IDs then it likely has some fairly OS-specific
requirements and will need tighter control of its syscalls anyway.

(Eventually, support for setting the file owner and group atomically
could be added by writing out a file using `O_TMPFILE` so it’s not
addressable, and then linking it into the file system in place of the
old file using something like `renameat2(AT_EMPTY_PATH)` or `linkat()`.
That’s currently not possible without patching the kernel with
https://marc.info/?l=linux-fsdevel&m=152472898003523&w=2, as far as I
know at the moment.)

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1203
2020-07-26 21:37:46 +01:00
Philip Withnall
f3cea1c464 gfileutils: Implement GFileSetContentsFlags
This moves `write_to_temp_file()` into `g_file_set_contents_full()` and
coalesces its handling of `do_fsync` with the `rename_file()` call. It
adds support for `G_FILE_SET_CONTENTS_DURABLE` and
`G_FILE_SET_CONTENTS_NONE` — previously only
`G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING` was
supported.

In the case that `G_FILE_SET_CONTENTS_CONSISTENT |
G_FILE_SET_CONTENTS_DURABLE` is set, an additional `fsync()` is now done
on the directory after renaming the temporary file.

In the case that `G_FILE_SET_CONTENTS_ONLY_EXISTING` isn’t set, the
`fsync()` after writing the temporary file will always be done (unless
the file system guarantees it never needs to be done).

In the case that only `G_FILE_SET_CONTENTS_DURABLE` is set, the
destination file will be written to directly (using this mode is not
really advised).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1302
2020-07-26 21:37:46 +01:00
Philip Withnall
387c159862 gfileutils: Tidy up types of length arguments in helper functions
We can guarantee that they’re non-negative.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Philip Withnall
e4e618c604 gfileutils: Factor out fsync calculation
This introduces no functional changes, just makes the code a bit more
modular and reusable.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Philip Withnall
00c17de72e gfileutils: Split out write_to_file() helper function
This introduces no functional changes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Philip Withnall
554107c23c gfileutils: Add g_file_set_contents_full() and GFileSetContentsFlags
This is a new version of the g_file_set_contents() API which will allow
its safety to be controlled by some flags, allowing the user to choose
their preferred tradeoff between safety (`fsync()` calls) and speed.

Currently, the flags do nothing and the new API behaves like the old
API. This will change in the following commits.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:37:46 +01:00
Marc-André Lureau
5b49df3b9f Merge branch 'uri-non-utf8' into 'master'
Fix non-utf8 URI pct-decoding / unescape regression

Closes #2165

See merge request GNOME/glib!1569
2020-07-26 14:24:53 +00:00
Philip Withnall
c60d6599c9 Merge branch 'mach_monotonic_time_use_timebase_struct' into 'master'
gmain: fix fetching timebase on non-Intel Darwin

Closes #858

See merge request GNOME/glib!1566
2020-07-26 13:22:48 +00:00
Marc-André Lureau
22fe3b0224 uri: fix regression in g_uri_unescape_segment/string
The previous implementation of g_uri_unescape_segment() allowed non-utf8
decoded characters. uri_decoder() allows it too with FLAGS_ENCODED (I
think it's abusing a bit the user-facing flags for some internal
decoding behaviour)

However, it didn't allow \0 in the decoded string. Let's have an extra
check for that, outside of uri_decoder().

Fixes: d83d68d64c
Reported-by: Matthias Clasen <mclasen@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-26 17:19:43 +04:00
Marc-André Lureau
ea395e3fdd uri: add a GError to the new g_uri_unescape_bytes()
Suggested-by: Matthias Clasen <mclasen@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-26 17:19:37 +04:00
Philip Withnall
d5513ef72c Merge branch 'giomodule-cache' into 'master'
Fix giomodule.cache being wrongly considered stale

Closes #2127

See merge request GNOME/glib!1560
2020-07-25 23:10:25 +00:00
Philip Withnall
41ffa411e8 Merge branch '2132-quark-ctor-supp' into 'master'
glib.supp: Generalise some g_quark_init() suppressions

Closes #2132

See merge request GNOME/glib!1543
2020-07-25 20:16:03 +00:00
Philip Withnall
0b75a92823 Merge branch '2129-tz-slim-tests' into 'master'
tests: Add tests for RFC 8536 v3 parsing of time zones

See merge request GNOME/glib!1578
2020-07-25 18:44:29 +00:00
Philip Withnall
060fda09eb Merge branch 'task-set-name-version' into 'master'
gtask: Only override g_task_set_source_tag() for GLib ≥ 2.60

See merge request GNOME/glib!1576
2020-07-25 17:16:44 +00:00
Philip Withnall
50f8a9d32a Merge branch '422-xattr-binary-data' into 'master'
Fix support for binary xattrs

Closes #422

See merge request GNOME/glib!1568
2020-07-25 17:13:55 +00:00
Philip Withnall
c05252b4f1 Merge branch 'uri-illegal' into 'master'
uri: add illegal_characters argument to unescape_bytes

See merge request GNOME/glib!1577
2020-07-25 14:49:28 +00:00
Philip Withnall
b80b864fe3 tests: Add a test for getting/setting xattrs on a local file
Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #422
2020-07-24 23:43:01 +01:00
Emmanuele Bassi
221e32d9ac Merge branch 'g-getenv-everywhere' into 'master'
glib: Use g_getenv everywhere instead of getenv

See merge request GNOME/glib!1579
2020-07-23 12:34:31 +00:00
Nirbheek Chauhan
c3c2c31335 glib: Use g_getenv everywhere instead of getenv
`getenv()` doesn't work well on Windows, f.ex., it can't fetch env
vars set with `SetEnvironmentVariable()`. This also means that it
doesn't work at all when targeting UWP since that's the only way to
set env vars in that case.
2020-07-23 13:57:59 +05:30
Philip Withnall
98a7d6e389 tests: Add tests for RFC 8536 v3 parsing of time zones
This adds really basic validation that `GTimeZone` can successfully
parse a ‘slim’ format timezone file.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #2129
2020-07-17 15:08:59 +01:00
Philip Withnall
e18a6a28db tests: Incorporate bug base into g_test_bug() calls in gdatetime tests
This will allow the following commit to refer to GitLab in its
`g_test_bug()` call.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-17 15:08:59 +01:00
Philip Withnall
f5b4a6b9cc Merge branch 'GDateTime-TZif' into 'master'
GDateTime fixes to handle TZif footers

Closes #2129

See merge request GNOME/glib!1533
2020-07-17 13:54:48 +00:00
Paul Eggert
4408e69a0f gtimezone: add FIXME comments 2020-07-16 12:44:25 -07:00
Paul Eggert
7414dc2cb3 Clarify memset in set_tz_name
* glib/gtimezone.c (set_tz_name): Use size, not NAME_SIZE,
to clear the buffer.  Suggested by Philip Withnall in:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1533#note_867859
2020-07-16 12:44:25 -07:00
Paul Eggert
25d950b61f gtimezone: support footers in TZif files
Since tzcode95f (1995), TZif files have had a trailing
TZ string, used for timestamps after the last transition.
This string is specified in Internet RFC 8536 section 3.3.
init_zone_from_iana_info has ignored this string, causing it
to mishandle timestamps past the year 2038.  With zic's new -b
slim flag, init_zone_from_iana_info would even mishandle current
timestamps.  Fix this by parsing the trailing TZ string and adding
its transitions.

Closes #2129
2020-07-16 12:44:25 -07:00
Paul Eggert
68978631e5 gtimezone: add support for RFC 8536 time zone transitions
Time zone transition times can range from -167:59:59 through
+167:59:59, according to Internet RFC 8536 section 3.3.1;
this is an extension to POSIX.  It is needed for proper
support of TZif version 3 files.
2020-07-16 12:44:25 -07:00
Paul Eggert
325d17c49f gtimezone: allow hh to be 24, as per POSIX
POSIX allows hh to be 24; see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
2020-07-16 12:44:25 -07:00
Paul Eggert
bc78f0ad27 gtimezone: support POSIX 1003.1-2001 quoted TZ abbreviations
TZ strings like '<-03>3' were introduced in POSIX 1003.1-2001 and
are currently specified in:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
2020-07-16 12:44:25 -07:00
Paul Eggert
21b000356e gtimezone: get 64-bit data from version-3 TZif files
Version 3 was introduced in tzdb 2013e (2013).
See Internet RFC 8536 section 3.1 under "ver(sion)".
2020-07-16 12:44:25 -07:00
Florentina Mușat
d992b900fb Update Romanian translation 2020-07-16 11:18:24 +00:00
Yuri Chornoivan
5ab6a30226 Update Ukrainian translation 2020-07-16 05:50:01 +00:00
Marc-André Lureau
4c6654dcd4 uri: add illegal_characters argument to unescape_bytes
It's not clear to me why this argument was excluded in the first place,
and Dan doesn't remember either. At least for consistency with
unescape_string, add it.

See also:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1574#note_867283

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-15 22:03:28 +04:00
Philip Withnall
bd75c185a1 gtask: Only override g_task_set_source_tag() for GLib ≥ 2.60
g_task_set_name() was added in GLib 2.60, so only use it in the
overridden definition of g_task_set_source_tag() if the user has said
that they require GLib ≥ 2.60.

This is a follow up to commit b08bd04abe.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-15 17:08:47 +01:00
Philip Withnall
5ca8e51ae4 Merge branch 'uri-illegal' into 'master'
uri: fix g_uri_unescape_string() regression

Closes #2160

See merge request GNOME/glib!1574
2020-07-15 15:47:06 +00:00
Marc-André Lureau
4433a46e06 uri: fix g_uri_unescape_string() regression
The illegal character set used to be applied only to the decoded
characters.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2160

Fixes: d83d68d64c ("guri: new URI parsing and generating functions")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-15 19:13:52 +04:00
Philip Withnall
1135ca25fd Merge branch 'analyzer-noreturn' into 'master'
gtestutils: Mark that g_assert_whatever() macros do not normally return

Closes #1200 and #1288

See merge request GNOME/glib!1553
2020-07-15 12:31:56 +00:00
Philip Chimento
6bdf640f51 gtestutils: Mark that g_assert_whatever() macros do not normally return
g_assert_true(), g_assert_cmpint(), and friends, can return to the
caller if test_nonfatal_assertions is set, but this is normally not the
case. In particular, for the purposes of static analysis, we
specifically don't want to assume that they might return. Clang has an
analyzer_noreturn attribute for this exact purpose, which conveniently
already has a macro in gmacros.h.

Fixes: #1288
Fixes: #1200
2020-07-15 12:45:56 +01:00
Philip Withnall
f5fc9cab96 Merge branch 'wip/wjt/2159-thread-unsafe-initialization-in-gportalsupport-c' into 'master'
portal: Read /.flatpak-info in thread-safe fashion

Closes #2159

See merge request GNOME/glib!1573
2020-07-15 11:37:12 +00:00
holin
eb3409a9c9
gmain: fix fetching timebase on non-Intel Darwin
Co-authored-by: Misty De Meo <mistydemeo@gmail.com>
2020-07-13 10:25:20 -07:00
Will Thompson
4b3183435b portal: Read /.flatpak-info in thread-safe fashion
There is no guarantee that this function would not be called
concurrently. Particularly since flatpak_info_read was set to TRUE
before /.flatpak-info is actually read from disk, there is a potential
race where a second thread would return default values for the various
flags set from that file.

Fixes #2159
2020-07-13 16:26:44 +01:00
Jordi Mas
10f2d10f1c Update Catalan translation 2020-07-12 22:59:33 +02:00
Aurimas Černius
8b8470fea9 Updated Lithuanian translation 2020-07-12 20:30:41 +03:00
Florentina Mușat
570f27a90a Update Romanian translation 2020-07-09 09:33:06 +00:00
Yuri Chornoivan
ed70742813 Update Ukrainian translation 2020-07-09 09:23:54 +00:00
Sergio Gelato
63b329fb81 glocalfileinfo: Correct an off-by-one error when unescaping hex
Correct an off-by-one error in hex_unescape_string()'s computation of
the output string length.

(Turned into a git-format patch by Philip Withnall. Original patch
submitted on the Debian bug tracker, bug#962912.)
2020-07-08 12:47:21 +01:00
Sergio Gelato
8049535ffe glocalfileinfo: Handle arbitrary binary data in extended attribute values
It's safe to assume an escaped string doesn't contain embedded null bytes,
but raw memory buffers (as returned by getxattr()) require more care.

If the length of the data to be escaped is known, use that knowledge instead
of invoking strlen().

(Turned into a git-format patch by Philip Withnall. One minor formatting
tweak. Original patch submitted on the Debian bug tracker, bug#962912.)

Fixes: #422
2020-07-08 12:46:45 +01:00
Philip Withnall
735c80dc5b Merge branch 'uri-parse-params' into 'master'
A few g_uri_parse_params() improvements

See merge request GNOME/glib!1557
2020-07-08 10:53:11 +00:00
Philip Withnall
3cabce39e8 Merge branch 'tests-limit-threads' into 'master'
tests: limit number of threads to something reasonable.

See merge request GNOME/glib!1564
2020-07-07 13:15:54 +00:00
Harald van Dijk
05d65aec12
tests: limit number of threads to something reasonable.
Creating 1000 threads with the default stack size of 8 MiB will fail on
architectures with a 32-bit address space. Move up the existing THREADS
macro and use that instead, but change its definition to 1000 if
pointers are larger than 32 bits.

Signed-off-by: Harald van Dijk <harald@gigawatt.nl>
2020-07-07 13:37:30 +01:00
Marc-André Lureau
3f72a95925 uri: make g_uri_parse_params() take an error
This should be more future-proof.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-07 15:20:57 +04:00