summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2015-08-27 10:38:22 +0200
committerAlexander Larsson <alexl@redhat.com>2015-08-27 10:38:22 +0200
commitb6355e1acb4ec5edd8bdc194770c46140e0c6aa0 (patch)
tree30da05961c6d45fa2e903272f419f01db4cc562f
parent0c253766576e072418baf4eaf7e89d8d5cfec992 (diff)
downloadxdg-app-b6355e1acb4ec5edd8bdc194770c46140e0c6aa0.tar.gz
Document portal: Store paths, not uris
There is no way to do this for generic uris anyway, lets not pretend we're solving a larger problem.
-rw-r--r--data/org.freedesktop.portal.documents.xml2
-rw-r--r--document-portal/xdp-fuse.c22
-rw-r--r--document-portal/xdp-main.c27
-rw-r--r--document-portal/xdp-util.c21
-rw-r--r--document-portal/xdp-util.h3
5 files changed, 32 insertions, 43 deletions
diff --git a/data/org.freedesktop.portal.documents.xml b/data/org.freedesktop.portal.documents.xml
index 647930f..6b01077 100644
--- a/data/org.freedesktop.portal.documents.xml
+++ b/data/org.freedesktop.portal.documents.xml
@@ -29,7 +29,7 @@
<arg type='ay' name='path' direction='out'/>
</method>
<method name="Add">
- <arg type='s' name='uri' direction='in'/>
+ <arg type='ay' name='path' direction='in'/>
<arg type='s' name='doc_id' direction='out'/>
</method>
<method name="AddLocal">
diff --git a/document-portal/xdp-fuse.c b/document-portal/xdp-fuse.c
index fca65c7..6e8a403 100644
--- a/document-portal/xdp-fuse.c
+++ b/document-portal/xdp-fuse.c
@@ -312,7 +312,7 @@ xdp_stat (fuse_ino_t ino,
XdpInodeClass class = get_class (ino);
guint64 class_ino = get_class_ino (ino);
g_autoptr (XdgAppDbEntry) entry = NULL;
- g_autofree char *path = NULL;
+ const char *path = NULL;
struct stat tmp_stbuf;
XdpTmp *tmp;
@@ -377,7 +377,7 @@ xdp_stat (fuse_ino_t ino,
stbuf->st_nlink = DOC_FILE_NLINK;
- path = xdp_dup_path (entry);
+ path = xdp_get_path (entry);
if (stat (path, &tmp_stbuf) != 0)
return ENOENT;
@@ -705,7 +705,7 @@ dirbuf_add_doc_file (fuse_req_t req,
guint32 doc_id)
{
struct stat tmp_stbuf;
- g_autofree char *path = xdp_dup_path (entry);
+ const char *path = xdp_get_path (entry);
g_autofree char *basename = xdp_dup_basename (entry);
if (stat (path, &tmp_stbuf) == 0)
dirbuf_add (req, b, basename,
@@ -966,7 +966,7 @@ xdp_fuse_open (fuse_req_t req,
guint64 class_ino = get_class_ino (ino);
struct stat stbuf = {0};
g_autoptr (XdgAppDbEntry) entry = NULL;
- g_autofree char *path = NULL;
+ const char *path = NULL;
XdpTmp *tmp;
int fd, res;
XdpFh *fh;
@@ -990,7 +990,7 @@ xdp_fuse_open (fuse_req_t req,
g_autofree char *write_path = NULL;
int write_fd = -1;
- path = xdp_dup_path (entry);
+ path = xdp_get_path (entry);
if ((fi->flags & 3) != O_RDONLY)
{
@@ -1019,7 +1019,7 @@ xdp_fuse_open (fuse_req_t req,
fh = xdp_fh_new (ino, fi, fd, NULL);
fh->trunc_fd = write_fd;
fh->trunc_path = g_steal_pointer (&write_path);
- fh->real_path = g_steal_pointer (&path);
+ fh->real_path = g_strdup (path);
if (fuse_reply_open (req, fi))
xdp_fh_free (fh);
}
@@ -1053,7 +1053,7 @@ xdp_fuse_create (fuse_req_t req,
XdpFh *fh;
g_autoptr(XdgAppDbEntry) entry = NULL;
g_autofree char *basename = NULL;
- g_autofree char *path = NULL;
+ const char *path = NULL;
XdpTmp *tmpfile;
int fd, res;
@@ -1092,7 +1092,7 @@ xdp_fuse_create (fuse_req_t req,
return;
}
- path = xdp_dup_path (entry);
+ path = xdp_get_path (entry);
fd = open (path, O_CREAT|O_EXCL|O_RDONLY);
if (fd < 0)
@@ -1110,7 +1110,7 @@ xdp_fuse_create (fuse_req_t req,
fh->truncated = TRUE;
fh->trunc_fd = write_fd;
fh->trunc_path = g_steal_pointer (&write_path);
- fh->real_path = g_steal_pointer (&path);
+ fh->real_path = g_strdup (path);
if (xdp_fstat (fh, &e.attr) != 0)
{
@@ -1317,7 +1317,7 @@ xdp_fuse_rename (fuse_req_t req,
if (strcmp (newname, basename) == 0)
{
- g_autofree char *real_path = xdp_dup_path (entry);
+ const char *real_path = xdp_get_path (entry);
/* Rename tmpfile to regular file */
/* Stop writes to all outstanding fds to the temp file */
@@ -1588,7 +1588,7 @@ xdp_fuse_unlink (fuse_req_t req,
basename = xdp_dup_basename (entry);
if (strcmp (name, basename) == 0)
{
- g_autofree char *real_path = xdp_dup_path (entry);
+ const char *real_path = xdp_get_path (entry);
if (unlink (real_path) != 0)
{
diff --git a/document-portal/xdp-main.c b/document-portal/xdp-main.c
index e3a2e29..b01de15 100644
--- a/document-portal/xdp-main.c
+++ b/document-portal/xdp-main.c
@@ -223,11 +223,10 @@ portal_delete (GDBusMethodInvocation *invocation,
}
char *
-do_create_doc (const char *uri)
+do_create_doc (const char *path)
{
- g_autoptr(GVariant) data = g_variant_ref_sink (g_variant_new_string (uri));
+ g_autoptr(GVariant) data = g_variant_ref_sink (g_variant_new_bytestring (path));
g_autofree char *existing_id = NULL;
- g_autoptr (GVariant) uri_v = NULL;
g_autoptr (XdgAppDbEntry) entry = NULL;
g_autofree char *new_id = NULL;
glnx_strfreev char **ids = NULL;
@@ -236,7 +235,7 @@ do_create_doc (const char *uri)
ids = xdg_app_db_list_ids_by_value (db, data);
if (ids[0] != NULL)
- return g_strdup (ids[0]); /* Reuse pre-existing entry with same uri */
+ return g_strdup (ids[0]); /* Reuse pre-existing entry with same path */
while (TRUE)
{
@@ -268,7 +267,7 @@ portal_add (GDBusMethodInvocation *invocation,
GVariant *parameters,
const char *app_id)
{
- const char *uri;
+ const char *path;
g_autofree char *id = NULL;
if (app_id[0] != '\0')
@@ -280,9 +279,16 @@ portal_add (GDBusMethodInvocation *invocation,
return;
}
- g_variant_get (parameters, "(&s)", &uri);
+ g_variant_get (parameters, "(^ay)", &path);
+ if (!g_path_is_absolute (path))
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XDP_ERROR, XDP_ERROR_INVALID_ARGUMENT,
+ "Document paths must be absolute");
+ return;
+ }
- id = do_create_doc (uri);
+ id = do_create_doc (path);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(s)", id));
@@ -297,11 +303,9 @@ portal_add_local (GDBusMethodInvocation *invocation,
GUnixFDList *fd_list;
g_autofree char *id = NULL;
g_autofree char *proc_path = NULL;
- g_autofree char *uri = NULL;
int fd_id, fd, fds_len, fd_flags;
const int *fds;
char path_buffer[PATH_MAX+1];
- g_autoptr(GFile) file = NULL;
ssize_t symlink_size;
struct stat st_buf, real_st_buf;
@@ -351,10 +355,7 @@ portal_add_local (GDBusMethodInvocation *invocation,
return;
}
- file = g_file_new_for_path (path_buffer);
- uri = g_file_get_uri (file);
-
- id = do_create_doc (uri);
+ id = do_create_doc (path_buffer);
if (app_id[0] != '\0')
{
diff --git a/document-portal/xdp-util.c b/document-portal/xdp-util.c
index aa2d5a5..016c687 100644
--- a/document-portal/xdp-util.c
+++ b/document-portal/xdp-util.c
@@ -88,39 +88,28 @@ xdp_name_from_id (guint32 doc_id)
}
const char *
-xdp_get_uri (XdgAppDbEntry *entry)
+xdp_get_path (XdgAppDbEntry *entry)
{
g_autoptr(GVariant) v = xdg_app_db_entry_get_data (entry);
- return g_variant_get_string (v, NULL);
-}
-
-char *
-xdp_dup_path (XdgAppDbEntry *entry)
-{
- const char *uri = xdp_get_uri (entry);
- g_autoptr(GFile) file = g_file_new_for_uri (uri);
-
- return g_file_get_path (file);
+ return g_variant_get_bytestring (v);
}
char *
xdp_dup_basename (XdgAppDbEntry *entry)
{
- const char *uri = xdp_get_uri (entry);
- g_autoptr(GFile) file = g_file_new_for_uri (uri);
+ const char *path = xdp_get_path (entry);
- return g_file_get_basename (file);
+ return g_path_get_basename (path);
}
char *
xdp_dup_dirname (XdgAppDbEntry *entry)
{
- g_autofree char *path = xdp_dup_path (entry);
+ const char *path = xdp_get_path (entry);
return g_path_get_dirname (path);
}
-
static GHashTable *app_ids;
typedef struct {
diff --git a/document-portal/xdp-util.h b/document-portal/xdp-util.h
index efb5b7b..3fa8de1 100644
--- a/document-portal/xdp-util.h
+++ b/document-portal/xdp-util.h
@@ -14,8 +14,7 @@ XdpPermissionFlags xdp_get_permissions (XdgAppDbEntry *entry,
gboolean xdp_has_permissions (XdgAppDbEntry *entry,
const char *app_id,
XdpPermissionFlags perms);
-const char * xdp_get_uri (XdgAppDbEntry *entry);
-char * xdp_dup_path (XdgAppDbEntry *entry);
+const char * xdp_get_path (XdgAppDbEntry *entry);
char * xdp_dup_basename (XdgAppDbEntry *entry);
char * xdp_dup_dirname (XdgAppDbEntry *entry);
guint32 xdp_id_from_name (const char *name);