Re: g_build_filename and members
- From: Alexander Larsson <alexl redhat com>
- To: Morten Welinder <mwelinder gmail com>
- Cc: gtk-devel-list <gtk-devel-list gnome org>
- Subject: Re: g_build_filename and members
- Date: Mon, 07 Jan 2008 11:45:41 +0100
On Sun, 2008-01-06 at 18:50 -0500, Morten Welinder wrote:
> On Jan 6, 2008 3:43 PM, Mikael Hermansson <mike tielie gmail com> wrote:
> > Hmm just saw that g_build_filename does not work for GIO Uris
> >
> > its simply strips away separator for example:
> >
> > g_build_filename("file:///", g_get_home_dir(), "foobar.txt", NULL)
> >
> > will be:
> >
> > file:/home/user/foobar.txt
>
> It's hard to see how any other result could be right. You are, after all,
> telling it that you have a directory called "file:".
Yeah, i think this is just a misunderstanding of what filenames and URIs
are. They are not the same, and any use of g_build_filename (that is not
extremely careful an limited) is just plain wrong. For instance, when
creating URIs you have to escape filenames.
> Does gio properly handle the difference between "file://", "file:///",
> and "file:////"? (Relative filename, absolute filename, and absolute
> filename in alternate space respectively.)
This is also kind of a weird question. GIO handles GFiles which is an
abstract reference to a file (kinda like a filename or a uri).
Construction of these is done from a filename OR a uri, and you need to
know what sort of entity you have.
Well, thats not the whole truth actually. There are four constructors:
GFile * g_file_new_for_path (const char *path);
This creates a GFile object from a filename. If it is not an absolue
path, cwd will be prepended. So, if you pass in "file:///foo" when /tmp,
the file will reference the file /tmp/file:/foo.
GFile * g_file_new_for_uri (const char *uri);
This creates a GFile from a uri. If you hand it a broken uri it will
still return some kind of GFile, but all calls to it will return in
errors. (Similar to passing a broken uri string to the actual file
operations.)
GFile * g_file_new_for_commandline_arg (const char *arg);
This tries to be "smart" and guess if the argument is a path, a uri, or
a relative path. Its bound to get things wrong in some corner cases,
because there is no way to always know what the user meant, but it
mostly works.
GFile * g_file_parse_name (const char *parse_name);
This creates a GFile from a parse name returned from
g_file_get_parse_name(). A parse name is a utf8-only string that you can
roundtrip in a UI and get the same GFile back. Its either an absolute
filename that correctly roundtrips in g_filename_to/from_utf8() or an
IRI (which is a URI, but where characters in the URI that when are
unescaped are proper UTF8 these are left unescaped).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]