GNOME Bugzilla – Bug 444087
Update ephy to use glib's g_get_user_special_dir()
Last modified: 2007-07-10 22:15:52 UTC
From IRC: <dieguito> should we update Bastien's work on xdg user dirs to use glib's new g_get_user_special_dir() ? bgo #432651 <chpe> yes :) (#if GLIB_CHECK_VERSION (2, 11, 3) of course)
Made this: Index: lib/ephy-file-helpers.c =================================================================== --- lib/ephy-file-helpers.c (revision 7067) +++ lib/ephy-file-helpers.c (working copy) @@ -224,12 +224,22 @@ ephy_file_downloads_dir_from_xdg (void) { const char *home_dir; char *downloads_dir; + const char *downloads_tmp; + g_print("saaa\n"); /* We use getenv to exactly match the default output * from xdg_user_dir_lookup, otherwise we might have a * mismatch in the string comparison below */ home_dir = getenv ("HOME"); + #if GLIB_CHECK_VERSION (2, 11, 3) + g_print("glib dirs\n"); + downloads_tmp = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD); + downloads_dir = g_strdup (downloads_tmp); + #else downloads_dir = xdg_user_dir_lookup ("DOWNLOAD"); + #endif + + g_print("downloads_dir = %s\n", downloads_dir); /* No home directory, it will use /tmp then */ if (home_dir == NULL) But Ephy locks on g_get_user_special_dir. First I thought it was because of the const/char thing, so I added that g_strdup. No use, still locks.
Depends on Bug #444121.
Created attachment 89431 [details] [review] A new try. What about this one?. I'm not so sure it's correctly done but at least now it doesn't crash :). I'm g_strdup'ing the string returned by glib since according to docs it belongs to glib. Also I changed the last if to: if (downloads_dir && strcmp (downloads_dir, home_dir) == 0) because otherwise it crashed, seems to me because it was freeing a NULL and if my limited C knowledge is not betraying me, that's not a good idea.
+#if GLIB_CHECK_VERSION (2, 11, 3) +#else #if !GLIB_... + downloads_tmp = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD); + downloads_dir = g_strdup (downloads_tmp); You can just directly strdup it, no need for the _tmp var. + if (downloads_dir && strcmp (downloads_dir, home_dir) == 0) { g_free (downloads_dir); I just saw a pre-existing bug here (not introduced by your patch): xdg_user_dir_lookup returns a strdup'd string which you must free with free but not with g_free, while g_get_user_special_dir uses g_strdup which is compatible with g_free but not with free...
Created attachment 91223 [details] [review] Fixed the bug mentioned by chpe Should this be enough?
I think the two |return user_dir;| statements in xdg_use_dir_lookup need the same treatment. With that fixed, ok to commit, thanks!
Actually let's just remove xdg_user_dir_lookup completely and just use the glib thing.
Fixed in svn.