summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2018-12-17 12:49:32 +0100
committerOndrej Holy <oholy@redhat.com>2018-12-17 13:24:49 +0100
commitdc9314fe317bf1b587cef2e0ca04592ef422cf69 (patch)
tree828eaf6dda3189d90b2c79a3e2f7a8874bd5b896
parent0f508c7b89250a99984719afef948dea363d7996 (diff)
downloadglib-gfile-colons.tar.gz
gfile: Fallback to local path for unknown schemesgfile-colons
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
-rw-r--r--gio/gfile.c33
1 files 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
@@ -6612,29 +6612,28 @@ g_file_new_build_filename (const gchar *first_element,
}
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 *