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 747770 - g-ir-scanner ignoring cache env variable
g-ir-scanner ignoring cache env variable
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: g-ir-scanner
1.44.x
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-04-13 09:55 UTC by Alexander Puls
Modified: 2015-06-19 22:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
scanner: honor XDG_CACHE_HOME (1013 bytes, patch)
2015-04-19 18:28 UTC, Dieter Verfaillie
accepted-commit_now Details | Review
scanner: add "XDG Base Directory" functions (4.68 KB, patch)
2015-04-20 20:04 UTC, Dieter Verfaillie
reviewed Details | Review
scanner: add "XDG Base Directory" functions (4.68 KB, patch)
2015-04-20 20:08 UTC, Dieter Verfaillie
none Details | Review
scanner: add "XDG Base Directory" functions (5.92 KB, patch)
2015-06-09 19:56 UTC, Dieter Verfaillie
none Details | Review
scanner: add "XDG Base Directory" functions (7.27 KB, patch)
2015-06-19 21:26 UTC, Dieter Verfaillie
accepted-commit_now Details | Review

Description Alexander Puls 2015-04-13 09:55:32 UTC
g-ir-scanner ignoring ${XDG_CACHE_HOME} when called as non-root user, instead creating ~/.cache no matter what.
Comment 1 Dieter Verfaillie 2015-04-19 18:28:57 UTC
Created attachment 301943 [details] [review]
scanner: honor XDG_CACHE_HOME

We already use XDG_DATA_DIRS for .gir files lookup
so we might as well honor XDG_CACHE_HOME instead
of hardcoding ~/.cache.
Comment 2 Colin Walters 2015-04-20 15:07:21 UTC
Review of attachment 301943 [details] [review]:

Looks fine, though I would add a comment like "This is Python reimplementation of `g_get_user_cache_dir()` because g-i can't depend on GLib via introspection; if any changes are made to that function they'll need to be copied here".
Comment 3 Dieter Verfaillie 2015-04-20 20:04:29 UTC
Created attachment 302024 [details] [review]
scanner: add "XDG Base Directory" functions

(In reply to Colin Walters from comment #2)
> Looks fine, though I would add a comment like "This is Python
> reimplementation of `g_get_user_cache_dir()` because g-i can't depend on
> GLib via introspection; if any changes are made to that function they'll
> need to be copied here".

This applies on top of attachment #304319 [details] and extracts the cache
and data dir lookup code into documented get_user_cache_dir() and
get_system_data_dirs() functions.

Note that previously, the data dirs code did not fall
back to '/usr/local/share:/usr/share' when the XDG_DATA_DIRS
environment variable was either not set or empty, as required
by the XDG Base Directory Specification. Not sure if this
was just forgotten or an intentional omission...
Comment 4 Dieter Verfaillie 2015-04-20 20:08:29 UTC
Created attachment 302025 [details] [review]
scanner: add "XDG Base Directory" functions

ahum, now with correct data dir fallback order...
Comment 5 Dieter Verfaillie 2015-04-20 20:22:34 UTC
Nope, the patch from comment #3 was actually correct. Sorry for the noise :/
Comment 6 Emmanuele Bassi (:ebassi) 2015-06-08 12:17:36 UTC
Review of attachment 302024 [details] [review]:

::: giscanner/transformer.py
@@ +179,3 @@
+        data_dirs.append(DATADIR)
+        if os.name != 'nt':
+            data_dirs.append('/usr/share')

Should get_system_data_dirs() already contain /usr/share? You're adding it twice. In case of an override from some environment-tweaking script like jhbuild, then you probably still want to add /usr/local/share as well.

::: giscanner/utils.py
@@ +226,3 @@
+    if homedir is not None and os.path.exists(homedir):
+        cachedir = os.path.join(homedir, '.cache')
+    '''

Isn't this a bit of a race?

The correct way would be to try and create the directory, and if it fails because it exists already, then handle that gracefully.
Comment 7 Dieter Verfaillie 2015-06-09 19:56:43 UTC
Created attachment 304891 [details] [review]
scanner: add "XDG Base Directory" functions

(In reply to Emmanuele Bassi (:ebassi) from comment #6)
> Review of attachment 302024 [details] [review] [review]:
> 
> ::: giscanner/transformer.py
> @@ +179,3 @@
> +        data_dirs.append(DATADIR)
> +        if os.name != 'nt':
> +            data_dirs.append('/usr/share')
> 
> Should get_system_data_dirs() already contain /usr/share? You're adding it
> twice. In case of an override from some environment-tweaking script like
> jhbuild, then you probably still want to add /usr/local/share as well.

The original code this this, so I kept it around in an overabundance of carefulness.
Added a comment to that effect.
 
> ::: giscanner/utils.py
> @@ +226,3 @@
> +    if homedir is not None and os.path.exists(homedir):
> +        cachedir = os.path.join(homedir, '.cache')
> +    '''
> 
> Isn't this a bit of a race?
> 
> The correct way would be to try and create the directory, and if it fails
> because it exists already, then handle that gracefully.

Reworked a bit to address your concern.
Comment 8 Dieter Verfaillie 2015-06-19 21:26:49 UTC
Created attachment 305714 [details] [review]
scanner: add "XDG Base Directory" functions

Extract cache and data dir lookup code into documented
get_user_cache_dir() and get_system_data_dirs() functions.

Note that previously, the data dirs code did not fall
back to '/usr/local/share:/usr/share' when the XDG_DATA_DIRS
environment variable was either not set or empty, as required
by the XDG Base Directory Specification.
Comment 9 Colin Walters 2015-06-19 22:18:32 UTC
Review of attachment 305714 [details] [review]:

Looks OK to me.
Comment 10 Dieter Verfaillie 2015-06-19 22:36:12 UTC
(In reply to Colin Walters from comment #9)
> Review of attachment 305714 [details] [review] [review]:
> 
> Looks OK to me.

Both patches pushed. Thanks for the review Emmanuele and Colin.