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 all 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
16 changes: 16 additions & 0 deletions data/org.freedesktop.portal.Documents.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,21 @@
<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.


This call is available inside the sandbox, if the application has the permission for the document.

This method was added in version 5 of this interface.
-->
<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='as' name='doc_id' direction='in'/>
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
<arg type='as' name='doc_id' direction='in'/>
<arg type='as' name='doc_ids' direction='in'/>

<arg type='aay' name='path' direction='out'/>
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
<arg type='aay' name='path' direction='out'/>
<arg type='a{say}' name='paths' direction='out'/>

</method>
</interface>
</node>
87 changes: 86 additions & 1 deletion document-portal/document-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,90 @@ portal_list (GDBusMethodInvocation *invocation,
return TRUE;
}

const char *
get_real_path_internal (GDBusMethodInvocation *invocation,
XdpAppInfo *app_info,
const char *id)
{
g_autoptr(PermissionDbEntry) entry = NULL;

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,
g_strdup_printf("Invalid ID passed (%s)", id));
return NULL;
}

if (!xdp_app_info_is_host (app_info))
{
g_autofree const char **apps = NULL;
const char *app_id = NULL;
gboolean app_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)
{
app_found = TRUE;
break;
}
}

if (!app_found)
{
g_dbus_method_invocation_return_error (invocation,
XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_NOT_ALLOWED,
"Not enough permissions");
return NULL;
}
}

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

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

return path;
}

static gboolean
portal_get_real_path (GDBusMethodInvocation *invocation,
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
portal_get_real_path (GDBusMethodInvocation *invocation,
portal_get_real_paths (GDBusMethodInvocation *invocation,

GVariant *parameters,
XdpAppInfo *app_info)
{
g_autofree const char **id_list = NULL;
const char *path;
int i;

g_variant_get (parameters, "(^a&s)", &id_list);

GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aay"));
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
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aay"));
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("a{say}"));


for (i = 0; id_list[i]; i++)
{
path = get_real_path_internal(invocation, app_info, id_list[i]);
if (path == NULL)
{
return FALSE;
}

g_variant_builder_add (&builder, "^ay", 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_variant_builder_add (&builder, "^ay", path);
g_variant_builder_add (&builder, "{s@ay}", id_list[i], g_variant_new_bytestring(path));

}

g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aay)", &builder));
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_dbus_method_invocation_return_value (invocation, g_variant_new ("(aay)", &builder));
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(@a{say})", g_variant_builder_end(&builder)));


return TRUE;
}

static void
peer_died_cb (const char *name)
{
Expand All @@ -1432,7 +1516,7 @@ on_bus_acquired (GDBusConnection *connection,

dbus_api = xdp_dbus_documents_skeleton_new ();

xdp_dbus_documents_set_version (XDP_DBUS_DOCUMENTS (dbus_api), 4);
xdp_dbus_documents_set_version (XDP_DBUS_DOCUMENTS (dbus_api), 5);

g_signal_connect_swapped (dbus_api, "handle-get-mount-point", G_CALLBACK (handle_get_mount_point), NULL);
g_signal_connect_swapped (dbus_api, "handle-add", G_CALLBACK (handle_method), portal_add);
Expand All @@ -1445,6 +1529,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
35 changes: 34 additions & 1 deletion tests/test-doc-portal.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,38 @@ test_add_named (void)
assert_doc_not_exist (id1, basename1, "com.test.App2");
}

static void
test_get_real_path (void)
{
g_autofree char *doc_id = NULL;
g_autofree char *expected_real_path = NULL;
g_autofree char *real_path = NULL;
const char *basename = "real-path";
g_autoptr(GVariant) reply = NULL;
GError *error = NULL;

if (!check_fuse_or_skip_test ())
return;

doc_id = export_new_file (basename, "content", FALSE);

reply = g_dbus_connection_call_sync (session_bus,
"org.freedesktop.portal.Documents",
"/org/freedesktop/portal/documents",
"org.freedesktop.portal.Documents",
"GetRealPath",
g_variant_new ("(s)", doc_id),
G_VARIANT_TYPE ("(s)"),
0, -1,
NULL,
&error);

g_assert_no_error (error);
g_variant_get (reply, "(s)", &real_path);
expected_real_path = g_build_filename (outdir, basename, NULL);
g_assert_cmpstr (real_path, ==, expected_real_path);
}

static void
global_setup (void)
{
Expand Down Expand Up @@ -853,7 +885,7 @@ test_version (void)
if (!check_fuse_or_skip_test ())
return;

g_assert_cmpint (xdp_dbus_documents_get_version (documents), ==, 4);
g_assert_cmpint (xdp_dbus_documents_get_version (documents), ==, 5);
}

int
Expand All @@ -871,6 +903,7 @@ main (int argc, char **argv)
g_test_add_func ("/db/recursive_doc", test_recursive_doc);
g_test_add_func ("/db/create_docs", test_create_docs);
g_test_add_func ("/db/add_named", test_add_named);
g_test_add_func ("/db/get_real_path", test_get_real_path);

global_setup ();

Expand Down
Loading