After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 659104 - Stop using ~/.gnome2 for data
Stop using ~/.gnome2 for data
Status: RESOLVED FIXED
Product: gnome-dictionary
Classification: Core
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gnome-dictionary-maint
gnome-dictionary-maint
: 522817 (view as bug list)
Depends on:
Blocks: 523057
 
 
Reported: 2011-09-15 00:57 UTC by Antono Vasiljev
Modified: 2012-02-23 15:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
use XDG_DATA_HOME for data (1.26 KB, patch)
2011-09-15 00:57 UTC, Antono Vasiljev
needs-work Details | Review
Use XDG layout for configs (11.15 KB, patch)
2012-01-04 12:31 UTC, Antono Vasiljev
needs-work Details | Review
Second attempt (6.18 KB, patch)
2012-01-05 03:35 UTC, Antono Vasiljev
reviewed Details | Review
Updated patch (6.52 KB, patch)
2012-01-15 19:10 UTC, Antono Vasiljev
reviewed Details | Review
XDG Directories, updated patch (7.26 KB, patch)
2012-01-16 14:02 UTC, Antono Vasiljev
committed Details | Review

Description Antono Vasiljev 2011-09-15 00:57:39 UTC
Created attachment 196571 [details] [review]
use XDG_DATA_HOME for data

Attached small patch to fix this in gnome-dictionary
Comment 1 Cosimo Cecchi 2011-09-15 02:01:26 UTC
Review of attachment 196571 [details] [review]:

Hi, thanks for the patch, I inlined some comments.

Anyway, it looks like that directory is used to store user-added dictionary sources, so should some kind of migration be used here?

::: gnome-dictionary/src/gdict-app.c
@@ +231,3 @@
   gtk_init (argc, argv);
 
+  g_set_prgname ("gnome-dictionary");

This should already have been done automatically by gtk_init().

::: gnome-dictionary/src/gdict-common.c
@@ +46,3 @@
 
+  retval = g_build_filename (g_get_user_data_dir (),
+			     g_get_prgname (),

Maybe you can just use "gnome-dictionary" here instead of g_get_prgname() anyway.
Comment 2 Antono Vasiljev 2011-09-15 02:11:22 UTC
g_get_prgname used in order to keep things DRY. probably can be dropped or replaced by macro.

Yes, migration is something we should provide with this change.
Do You have ideas how to implement it right way? 

I see 2 options here:

1) make it part of gnome-dictionary binary (implement in c)
2) make shell script wrapper that will perform migration if needed
Comment 3 Antono Vasiljev 2012-01-04 12:31:35 UTC
Created attachment 204562 [details] [review]
Use XDG layout for configs

i've updated the patch. Migration of old data implemented this time.
Comment 4 Emmanuele Bassi (:ebassi) 2012-01-04 18:47:06 UTC
Review of attachment 204562 [details] [review]:

there is *a lot* of whitespace fixes in this patch - it makes reading it and commenting harder. please, resist the urge to fix whitespace - feel free to attach another patch that does just that.

::: src/gdict-common.c
@@ +86,3 @@
+
+  /* move configs from pre-XDG directory to right place */
+  if (g_file_test (old_data_dir_name, G_FILE_TEST_IS_DIR))

don't use g_file_test() to protect g_rename(): it's inherently racy.

just g_rename() the old test directory to the new one, and catch the ENOEXIST error.

see also: http://blogs.gnome.org/ebassi/2006/07/24/ride-on-a-white-horse/

@@ +126,3 @@
+  gdict_migrate_configs ();
+
+  if (!g_file_test (config_dir_name, G_FILE_TEST_IS_DIR))

same as above: just use g_mkdir_with_parents() and check against EEXIST.
Comment 5 Antono Vasiljev 2012-01-04 21:12:45 UTC
Hello, Emmanuele.

On whitespace. You can just use git diff -w

- cut -
  -w, --ignore-all-space
     Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.
- cut -

On g_file_test. I can change the logic as you suggested in your blog post if it is totally necessary condition to accept the patch. Otherwise i don't see the point to make defensive coding where it's not really necessary. I cannot imagine where someone creates directory after we checked it with g_file_test... in any case result is the same - error message and call to exit().

we only can save one call to stat(). as for me it's false economy koz it doesent make code more readable. kinda premature optimization.
Comment 6 Emmanuele Bassi (:ebassi) 2012-01-04 23:08:40 UTC
(In reply to comment #5)

> On whitespace. You can just use git diff -w

I know that - but the review system on Bugzilla doesn't. and I generally don't like intermixing completely unrelated whitespace fixes in a commit.

> On g_file_test. I can change the logic as you suggested in your blog post if it
> is totally necessary condition to accept the patch. Otherwise i don't see the
> point to make defensive coding where it's not really necessary. I cannot
> imagine where someone creates directory after we checked it with g_file_test...
> in any case result is the same - error message and call to exit().
> 
> we only can save one call to stat(). as for me it's false economy koz it
> doesent make code more readable. kinda premature optimization.

avoiding inherent races is not "premature optimization", especially since the code already does the right thing elsewhere. and yes: I consider this a prerequisite for the patch to be accepted.

I appreciate the patch, obviously, but I'd also appreciate if I didn't have to do further work to fix it after committing it. :-)
Comment 7 Antono Vasiljev 2012-01-05 03:35:20 UTC
Created attachment 204656 [details] [review]
Second attempt

No whitespace changes and no g_file_test
Comment 8 Antono Vasiljev 2012-01-15 17:33:24 UTC
bump
Comment 9 Emmanuele Bassi (:ebassi) 2012-01-15 18:05:48 UTC
Review of attachment 204656 [details] [review]:

looks way better, aside from a couple of points.

::: src/gdict-common.c
@@ +77,3 @@
+
+gboolean
+  retval = g_build_filename (g_get_user_config_dir (),

I doubt "vodi" is a valid C type.

@@ +104,3 @@
+    }
+
+

the "success" and "error" labels are pretty much redundant.

I'd use a boolean variable, and unify the code paths.
Comment 10 Antono Vasiljev 2012-01-15 19:10:07 UTC
Created attachment 205308 [details] [review]
Updated patch

Removed labels
vodi -> void in header
Comment 11 Emmanuele Bassi (:ebassi) 2012-01-16 10:59:16 UTC
Review of attachment 205308 [details] [review]:

::: src/gdict-common.c
@@ +100,3 @@
+          g_free (old_data_dir_name);
+
+  old_data_dir_name = gdict_get_old_data_dir ();

not exactly what I meant; you could declare a "gboolean res = TRUE;" variable, use something like this:

  res = FALSE;

in the error path, and below you could unconditionally free the strings and return the boolean value.

anyway, looks good.

@@ +131,3 @@
+
+            g_free (config_dir_name);
+          g_free (config_dir_name);

same as above, really - though, again, it looks good.

::: src/gdict-source-dialog.c
@@ +346,3 @@
     }
       
   name = g_strdup_printf ("%s.desktop", gdict_source_get_name (source));

this one could be changed to:

  name = g_strconcat (gdict_source_get_name (source), ".desktop", NULL);

as a "drive by" change.

@@ +348,2 @@
   name = g_strdup_printf ("%s.desktop", gdict_source_get_name (source));
+  filename = g_build_filename (gdict_get_config_dir(),

get_config_dir() returns a newly allocated string: you should use a separate variable to store it, and then call g_free() - otherwise, you're leaking a string.

alternatively, gdict_get_config_dir() could store the string statically, and return a const char*. it would be a one-off allocation, and it would avoid hitting the allocator every time we ask for the configuration directory.

@@ +437,3 @@
     }
       
   name = g_strdup_printf ("%s.desktop", gdict_source_get_name (source));

same as above, g_strconcat() would be better.

@@ +439,3 @@
   name = g_strdup_printf ("%s.desktop", gdict_source_get_name (source));
+
+  filename = g_build_filename (gdict_get_config_dir(),

same as above, you're leaking the string returned by gdict_get_config_dir().
Comment 12 Antono Vasiljev 2012-01-16 14:02:47 UTC
Created attachment 205363 [details] [review]
XDG Directories, updated patch
Comment 13 Emmanuele Bassi (:ebassi) 2012-01-16 14:58:24 UTC
Review of attachment 205363 [details] [review]:

looks good to me
Comment 14 Antono Vasiljev 2012-01-17 14:57:13 UTC
Any chance to see this in git master?
Comment 15 Matthias Clasen 2012-02-13 19:17:38 UTC
Its marked acn, so you should feel encouraged to commit it.
Comment 16 Antono Vasiljev 2012-02-14 14:11:30 UTC
What do i need to get commit right to this repository?
Comment 17 André Klapper 2012-02-23 10:24:38 UTC
Comment on attachment 205363 [details] [review]
XDG Directories, updated patch

Committed: http://git.gnome.org/browse/gnome-dictionary/commit/?id=63c5af12646a00cedbce0fe35e0f936822593325
Comment 18 Javier Jardón (IRC: jjardon) 2012-02-23 15:17:20 UTC
*** Bug 522817 has been marked as a duplicate of this bug. ***