Re: g_build_filename and members



On Sun, 2008-01-06 at 21:43 +0100, Mikael Hermansson 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
> 
> The File:/ gvfs backend will accept this but if we pass:
> 
> g_build_filename("sftp://hostname";, "/home/user/", "foobar.txt", NULL)
> 
> it will fail because gvfs sftp backend dont like
> sftp:/hostname/home/user/foobar.txt
> 
> instead it will have sftp://hostname/home/....
> 
> I dont know whish is correct but its seems to me there always should be
> two DIR_SEPARATORS at the begining in URIS?
> 
> maybe there should be an g_build_uri? or similar?

Handling uri strings, with all that involves wrt escaping and whatnot is
very hard to get right. It lead to no end of problems in gnome-vfs. In
fact, this mail itself shows what kind of things people do to URIs that
is just not correct.

So, in gio all handling of URIs as strings has been removed from the
API, and URIs themselves are only used as a serialized form for things
like DnD, saving in preferences, etc. 

If you really need to build a uri for the files you list above you
should use:

dir = g_file_new_for_path(g_get_home_dir())
file = g_file_get_child(dir, "foobar.txt")
uri = g_file_get_uri (file);

base = g_file_new_for_uri("sftp://hostname/";)
dir = g_file_resolve_relative_path(base, "home/user")
file = g_file_get_child (dir, "foobar.txt")
uri = g_file_get_uri (file);

The last one could avoid the last row by putting foobar.txt in the
relative path, but i wanted to do the exact copy of your code.

Normally you should not need to construct the uri in most cases, as the
"file" variable is what you use in all gio calls to do i/o to the file.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]