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.
tingping/wmclass
Alexander Larsson 2015-08-27 10:38:22 +02:00
parent 0c25376657
commit b6355e1acb
5 changed files with 32 additions and 43 deletions

View File

@ -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">

View File

@ -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)
{

View File

@ -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')
{

View File

@ -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 {

View File

@ -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);