Skip to content

Commit

Permalink
Try harder to find the host path for the documents
Browse files Browse the repository at this point in the history
When the access to the directory is provided by the portal (like
browser download directory) the stored files in the directory
are not found by xdp_get_real_path_for_doc_path and /run/user/...
path is opened instead of host path by the OpenFile or OpenDirectory portal.
  • Loading branch information
xhorak committed Jan 15, 2025
1 parent 1c902cc commit f2371db
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,38 @@ app_exists (const char *app_id)
return (info != NULL);
}

static char *
get_host_path_for_document_path (const char* document_path,
XdpAppInfo* app_info)
{
char *host_path = xdp_get_real_path_for_doc_path (document_path,
app_info);
GList *path_parts = NULL;
/* Try harder when still getting /run/user path, the document portal
could provide directory instead of file or subdirectory. */
while (g_str_has_prefix (host_path, "/run/user"))
{
g_autofree char *dirname = g_path_get_dirname (host_path);
path_parts = g_list_prepend (path_parts,
g_path_get_basename (host_path));
g_free (host_path);
host_path = xdp_get_real_path_for_doc_path (dirname, app_info);
}

if (path_parts)
{
g_autoptr (GPathBuf) path_buf = g_path_buf_new_from_path (host_path);
for (GList *p = path_parts; p != NULL; p = p->next)
{
g_path_buf_push (path_buf, p->data);
}
g_free (host_path);
host_path = g_path_buf_to_path (path_buf);
g_list_free_full (path_parts, g_free);
}
return host_path;
}

static void
handle_open_in_thread_func (GTask *task,
gpointer source_object,
Expand Down Expand Up @@ -688,7 +720,7 @@ handle_open_in_thread_func (GTask *task,

if (path != NULL)
{
host_path = xdp_get_real_path_for_doc_path (path, request->app_info);
host_path = get_host_path_for_document_path (path, request->app_info);
if (host_path)
{
g_debug ("OpenFile: translating path value '%s' to host path '%s'", path, host_path);
Expand Down Expand Up @@ -724,7 +756,8 @@ handle_open_in_thread_func (GTask *task,

if (open_dir)
{
g_autofree char *real_path = xdp_get_real_path_for_doc_path (path, request->app_info);
g_autofree char *real_path = get_host_path_for_document_path (path,
request->app_info);
/* Try opening the directory via the file manager interface, then
fall back to a plain URI open */
g_autoptr(GError) local_error = NULL;
Expand Down

0 comments on commit f2371db

Please sign in to comment.