Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetRealPath to document portal #1269

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions data/org.freedesktop.portal.Documents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,17 @@
<arg type='s' name='app_id' direction='in'/>
<arg type='a{say}' name='docs' direction='out'/>
</method>

<!--
GetRealPath:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GetRealPath:
GetRealPaths:

@doc_id: the ID of the file in the document store
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@doc_id: the ID of the file in the document store
@doc_id: the IDs of the files in the document store

@path: the path for the file in the host filesystem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@path: the path for the file in the host filesystem
@path: a dictionary mapping application IDs to the paths in the host filesystem


Gets the filesystem path for a document store entry.
grulja marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@grulja grulja May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Gets the filesystem path for a document store entry.
Gets the filesystem paths for document store entries.

-->
<method name="GetRealPath">
grulja marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<method name="GetRealPath">
<method name="GetRealPaths">

<arg type='s' name='doc_id' direction='in'/>
<arg type='s' name='path' direction='out'/>
</method>
</interface>
</node>
63 changes: 63 additions & 0 deletions document-portal/document-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,68 @@ portal_list (GDBusMethodInvocation *invocation,
return TRUE;
}

static gboolean
portal_get_real_path (GDBusMethodInvocation *invocation,
GVariant *parameters,
XdpAppInfo *app_info)
{
const char *id = NULL;
g_autoptr(PermissionDbEntry) entry = NULL;

g_variant_get (parameters, "(&s)", &id);

XDP_AUTOLOCK (db);

entry = permission_db_lookup (db, id);

if (!entry)
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid ID passed");
return TRUE;
}

if (!xdp_app_info_is_host (app_info))
{
g_autofree const char **apps = NULL;
g_autofree const char *app_id = NULL;
grulja marked this conversation as resolved.
Show resolved Hide resolved
gboolean id_found = FALSE;
int i;

app_id = xdp_app_info_get_id(app_info);

apps = permission_db_entry_list_apps (entry);
for (i = 0; apps[i] != NULL; i++)
{
if (g_strcmp0 (app_id, apps[i]) == 0)
{
id_found = TRUE;
break;
}
}

if (!id_found)
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT,
"Invalid ID passed");
JakobDev marked this conversation as resolved.
Show resolved Hide resolved
return TRUE;
}
}

g_autoptr (GVariant) data = permission_db_entry_get_data (entry);
const char *path;

g_variant_get (data, "(^&ayttu)", &path, NULL, NULL, NULL);

g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(@s)",
g_variant_new_string (path)));

return TRUE;
}

static void
peer_died_cb (const char *name)
{
Expand Down Expand Up @@ -1445,6 +1507,7 @@ on_bus_acquired (GDBusConnection *connection,
g_signal_connect_swapped (dbus_api, "handle-lookup", G_CALLBACK (handle_method), portal_lookup);
g_signal_connect_swapped (dbus_api, "handle-info", G_CALLBACK (handle_method), portal_info);
g_signal_connect_swapped (dbus_api, "handle-list", G_CALLBACK (handle_method), portal_list);
g_signal_connect_swapped (dbus_api, "handle-get-real-path", G_CALLBACK (handle_method), portal_get_real_path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
g_signal_connect_swapped (dbus_api, "handle-get-real-path", G_CALLBACK (handle_method), portal_get_real_path);
g_signal_connect_swapped (dbus_api, "handle-get-real-paths", G_CALLBACK (handle_method), portal_get_real_paths);


file_transfer = file_transfer_create ();
g_dbus_interface_skeleton_set_flags (file_transfer,
Expand Down
Loading