diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2024-05-02 11:30:52 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2024-05-02 11:30:52 +0000 |
commit | da9545baaf6542aac19279ca2b8dc55c670fe1ee (patch) | |
tree | 591dea942b7c3b70b4ff9784a332f0cf4bc1f01e | |
parent | 4bd416f0ffb910843dcc670b579b34886ef5200b (diff) | |
parent | 43c5af517c5662907d696273830e5336ff4f2a7b (diff) | |
download | glib-da9545baaf6542aac19279ca2b8dc55c670fe1ee.tar.gz |
Merge branch 'wip/smcv/documents-portal-erofs' into 'main'
gdocumentportal: Handle EROFS and similar errors more gracefully
See merge request GNOME/glib!4031
-rw-r--r-- | gio/gdocumentportal.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/gio/gdocumentportal.c b/gio/gdocumentportal.c index 382e2aab6..0b55c3ef9 100644 --- a/gio/gdocumentportal.c +++ b/gio/gdocumentportal.c @@ -90,6 +90,33 @@ 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: +#ifdef EPERM + case EPERM: +#endif +#ifdef EROFS + case EROFS: +#endif +#ifdef ETXTBSY + case ETXTBSY: +#endif + return TRUE; + + default: + return FALSE; + } +} + GList * g_document_portal_add_documents (GList *uris, const char *app_id, @@ -131,7 +158,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 */ |