diff options
author | Simon McVittie <smcv@collabora.com> | 2024-05-01 13:57:41 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2024-05-01 18:33:37 +0100 |
commit | 8c533510ee73e4cc1d4b009e09881a82cb0e8ddd (patch) | |
tree | 6f570ecb4f284d9dfc30a4099cbb1a90d299a3f6 | |
parent | 4bd416f0ffb910843dcc670b579b34886ef5200b (diff) | |
download | glib-8c533510ee73e4cc1d4b009e09881a82cb0e8ddd.tar.gz |
gdocumentportal: Factor out opening_ro_might_succeed()
No functional change.
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | gio/gdocumentportal.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/gio/gdocumentportal.c b/gio/gdocumentportal.c index 382e2aab6..531156660 100644 --- a/gio/gdocumentportal.c +++ b/gio/gdocumentportal.c @@ -90,6 +90,24 @@ enum { XDP_ADD_FLAGS_FLAGS_ALL = ((1 << 3) - 1) }; +/* + * Assume that opening a file read/write failed with @saved_errno, + * and return TRUE if opening the same file read-only might succeed. + */ +static gboolean +opening_ro_might_succeed (int saved_errno) +{ + switch (saved_errno) + { + case EACCES: + case EISDIR: + return TRUE; + + default: + return FALSE; + } +} + GList * g_document_portal_add_documents (GList *uris, const char *app_id, @@ -131,7 +149,7 @@ g_document_portal_add_documents (GList *uris, int fd; fd = g_open (path, O_CLOEXEC | O_RDWR); - if (fd == -1 && (errno == EACCES || errno == EISDIR)) + if (fd == -1 && opening_ro_might_succeed (errno)) { /* If we don't have write access, fall back to read-only, * and stop requesting the write permission */ |