diff --git a/gio/gdocumentportal.c b/gio/gdocumentportal.c index 56378b1e6..154cc74df 100644 --- a/gio/gdocumentportal.c +++ b/gio/gdocumentportal.c @@ -31,9 +31,6 @@ #include "gunixfdlist.h" #endif -#ifndef O_PATH -#define O_PATH 0 -#endif #ifndef O_CLOEXEC #define O_CLOEXEC 0 #else @@ -92,76 +89,6 @@ init_document_portal (void) return (documents != NULL && documents_mountpoint != NULL); } -char * -g_document_portal_add_document (GFile *file, - GError **error) -{ - char *doc_path, *basename; - char *doc_id = NULL; - char *doc_uri = NULL; - char *path = NULL; - GUnixFDList *fd_list = NULL; - int fd, fd_in, errsv; - gboolean ret; - - if (!init_document_portal ()) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED, - "Document portal is not available"); - goto out; - } - - path = g_file_get_path (file); - fd = g_open (path, O_PATH | O_CLOEXEC); - errsv = errno; - - if (fd == -1) - { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), - "Failed to open %s", path); - goto out; - } - -#ifndef HAVE_O_CLOEXEC - fcntl (fd, F_SETFD, FD_CLOEXEC); -#endif - - fd_list = g_unix_fd_list_new (); - fd_in = g_unix_fd_list_append (fd_list, fd, error); - g_close (fd, NULL); - - if (fd_in == -1) - goto out; - - ret = gxdp_documents_call_add_sync (documents, - g_variant_new_handle (fd_in), - TRUE, - TRUE, - fd_list, - &doc_id, - NULL, - NULL, - error); - - if (!ret) - goto out; - - basename = g_path_get_basename (path); - doc_path = g_build_filename (documents_mountpoint, doc_id, basename, NULL); - g_free (basename); - - doc_uri = g_filename_to_uri (doc_path, NULL, NULL); - g_free (doc_path); - - out: - if (fd_list) - g_object_unref (fd_list); - g_free (path); - g_free (doc_id); - - return doc_uri; -} - /* Flags accepted by org.freedesktop.portal.Documents.AddFull */ enum { XDP_ADD_FLAGS_REUSE_EXISTING = (1 << 0), @@ -210,7 +137,14 @@ g_document_portal_add_documents (GList *uris, { int fd; - fd = g_open (path, O_CLOEXEC | O_PATH); + fd = g_open (path, O_CLOEXEC | O_RDWR); + if (fd == -1 && (errno == EACCES || errno == EISDIR)) + { + /* If we don't have write access, fall back to read-only, + * and stop requesting the write permission */ + fd = g_open (path, O_CLOEXEC | O_RDONLY); + permissions[1] = NULL; + } if (fd >= 0) { #ifndef HAVE_O_CLOEXEC diff --git a/gio/gdocumentportal.h b/gio/gdocumentportal.h index adb1b974e..82d32640e 100644 --- a/gio/gdocumentportal.h +++ b/gio/gdocumentportal.h @@ -23,9 +23,6 @@ G_BEGIN_DECLS -char * g_document_portal_add_document (GFile *file, - GError **error); - GList * g_document_portal_add_documents (GList *uris, const char *app_id, GError **error); diff --git a/gio/gopenuriportal.c b/gio/gopenuriportal.c index 38d60bf68..b798d7cd1 100644 --- a/gio/gopenuriportal.c +++ b/gio/gopenuriportal.c @@ -31,9 +31,6 @@ #include "gunixfdlist.h" #endif -#ifndef O_PATH -#define O_PATH 0 -#endif #ifndef O_CLOEXEC #define O_CLOEXEC 0 #else @@ -107,7 +104,7 @@ g_openuri_portal_open_uri (const char *uri, path = g_file_get_path (file); - fd = g_open (path, O_PATH | O_CLOEXEC); + fd = g_open (path, O_RDONLY | O_CLOEXEC); errsv = errno; if (fd == -1) { @@ -318,7 +315,7 @@ g_openuri_portal_open_uri_async (const char *uri, g_object_set_data (G_OBJECT (task), "open-file", GINT_TO_POINTER (TRUE)); path = g_file_get_path (file); - fd = g_open (path, O_PATH | O_CLOEXEC); + fd = g_open (path, O_RDONLY | O_CLOEXEC); errsv = errno; if (fd == -1) {