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

documents: Add support for remote files #822

Closed
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
10 changes: 10 additions & 0 deletions src/documents.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ register_document (const char *uri,
g_autofree char *doc_id = NULL;
g_auto(GStrv) doc_ids = NULL;
g_autofree char *path = NULL;
g_autofree char *translated_uri = NULL;
g_autofree char *basename = NULL;
g_autofree char *dirname = NULL;
GUnixFDList *fd_list = NULL;
Expand All @@ -78,6 +79,15 @@ register_document (const char *uri,

file = g_file_new_for_uri (uri);
path = g_file_get_path (file);
#if G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) >= G_ENCODE_VERSION (2, 66)
if (path == NULL)
{
g_object_unref (file);
translated_uri = xdp_transform_remote_uri_into_local (uri);
file = g_file_new_for_uri (translated_uri);
path = g_file_get_path (file);
}
#endif
basename = g_path_get_basename (path);
dirname = g_path_get_dirname (path);

Expand Down
53 changes: 53 additions & 0 deletions src/xdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2349,3 +2349,56 @@ xdp_validate_serialized_icon (GVariant *v,

return TRUE;
}

#if G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) >= G_ENCODE_VERSION (2, 66)
gchar *
xdp_transform_remote_uri_into_local (const gchar *uri)
{
g_autofree gchar *pathtext = NULL;
g_autofree gchar *fuse_mountpoint = NULL;
gchar *uristring = NULL;
g_autoptr(GUri) file_uri = NULL;
g_autoptr(GString) gvfs_folder = NULL;

file_uri = g_uri_parse (uri, G_URI_FLAGS_NONE, NULL);
if ((file_uri == NULL) || (0 == g_strcmp0 (g_uri_get_scheme (file_uri), "file")) || (g_uri_get_host (file_uri) == NULL))
{
return g_strdup(uri);
}
if (0 == g_strcmp0 (g_get_user_runtime_dir (), g_get_user_cache_dir ()))
fuse_mountpoint = g_build_filename (g_get_home_dir(), ".gvfs", NULL);
else
fuse_mountpoint = g_build_filename (g_get_user_runtime_dir(), "gvfs", NULL);
gvfs_folder = g_string_new ("");
g_string_printf (gvfs_folder,
"%s:host=%s",
g_uri_get_scheme (file_uri),
g_uri_get_host (file_uri));
if (g_uri_get_port (file_uri) != -1)
{
g_string_append_printf (gvfs_folder,
",port=%d",
g_uri_get_port (file_uri));
}
if (g_uri_get_user (file_uri) != NULL)
{
g_string_append_printf (gvfs_folder,
",user=%s",
g_uri_get_user (file_uri));
}
pathtext = g_build_filename (fuse_mountpoint,
gvfs_folder->str,
g_uri_get_path (file_uri),
NULL);
uristring = g_uri_join (G_URI_FLAGS_NONE,
"file",
NULL,
NULL,
-1,
pathtext,
NULL,
NULL);

return uristring;
}
#endif
6 changes: 6 additions & 0 deletions src/xdp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ gboolean xdp_has_path_prefix (const char *str,
/* exposed for the benefit of tests */
int _xdp_parse_cgroup_file (FILE *f,
gboolean *is_snap);

#if G_ENCODE_VERSION (GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION) >= G_ENCODE_VERSION (2, 66)
gchar *
xdp_transform_remote_uri_into_local (const gchar *uri);
#endif

#ifdef HAVE_LIBSYSTEMD
char *_xdp_parse_app_id_from_unit_name (const char *unit);
#endif