[glib/gfile-colons] gfile: Fallback to local path for unknown schemes
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gfile-colons] gfile: Fallback to local path for unknown schemes
- Date: Mon, 17 Dec 2018 12:25:40 +0000 (UTC)
commit dc9314fe317bf1b587cef2e0ca04592ef422cf69
Author: Ondrej Holy <oholy redhat com>
Date: Mon Dec 17 12:49:32 2018 +0100
gfile: Fallback to local path for unknown schemes
g_file_new_for_cmd_path() doesn't handle files with colons ideally:
$ touch foo:bar
$ gio info foo:bar
gio: foo:///bar: The specified location is not supported
Just a note that "./foo:bar", "~/foo:bar" or "file:///foo:bar" works
properly. With this patch, the file info is shown even for "foo:bar"
when "foo" isn't supported scheme.
Side-effect of this patch is that operations will fail with "No such
file or directory" if the local file doesn't exist as well instead of
"The specified location is not supported" (ie. with G_IO_ERROR_NOT_FOUND
instead of G_IO_ERROR_NOT_SUPPORTED)...
https://gitlab.gnome.org/GNOME/glib/issues/1623
gio/gfile.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index a5709a4cc..87c792da7 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -6611,30 +6611,29 @@ g_file_new_build_filename (const gchar *first_element,
return file;
}
-static gboolean
-is_valid_scheme_character (char c)
-{
- return g_ascii_isalnum (c) || c == '+' || c == '-' || c == '.';
-}
-
-/* Following RFC 2396, valid schemes are built like:
- * scheme = alpha *( alpha | digit | "+" | "-" | "." )
- */
static gboolean
has_valid_scheme (const char *uri)
{
- const char *p;
-
- p = uri;
+ const gchar * const *supported_schemes;
+ char *scheme;
+ gboolean is_valid;
+ int i;
- if (!g_ascii_isalpha (*p))
+ scheme = g_uri_parse_scheme (uri);
+ if (scheme == NULL)
return FALSE;
- do {
- p++;
- } while (is_valid_scheme_character (*p));
+ is_valid = FALSE;
+ supported_schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+ for (i = 0; supported_schemes[i] != NULL; i++)
+ if (g_ascii_strcasecmp (supported_schemes[i], scheme) == 0)
+ {
+ is_valid = TRUE;
+ break;
+ }
+ g_free (scheme);
- return *p == ':';
+ return is_valid;
}
static GFile *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]