Merge branch 'wip/smcv/documents-portal-erofs' into 'main'

gdocumentportal: Handle EROFS and similar errors more gracefully

See merge request GNOME/glib!4031
This commit is contained in:
Philip Withnall 2024-05-02 11:30:52 +00:00
commit da9545baaf

View File

@ -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 */