GNOME Bugzilla – Bug 763344
g_get_user_runtime_dir(): ensure directory exists
Last modified: 2017-10-24 09:58:27 UTC
If the XDG_RUNTIME_DIR environment variable is set, we are being told by the OS that this directory exists and is appropriately configured already. In the fallback case of ~/.cache/, however, the directory may not yet exist. Rework the logic of this function a little so that we only check for the environment variable once. If it is not set, we will fall back to the cache directory, and mkdir() it to make sure that it exists. Meanwhile, remove a statement from the reference documentation that promises a warning in this case (which has never been true) and replace it with a statement that applications can rely on the directory existing. This change prevents each user of this API from having to check for the directory for themselves; an example of that can be seen in bug 763274.
Created attachment 323436 [details] [review] g_get_user_runtime_dir(): ensure directory exists
Review of attachment 323436 [details] [review]: Looks OK to me, just one random comment that isn't a problem. ::: glib/gutils.c @@ +1342,3 @@ + { + /* No need to strdup this one since it is valid forever. */ + dir = g_get_user_cache_dir (); This one grabs a mutex, and while holding that calls g_get_home_dir() which is also inside a GOnce, which calls g_get_user_database_entry() which is *also* inside a GOnce... I can't think of a situation where it'd be a real world problem but I think at some point things would be simpler if we just had a static _gutils_init_global_state() that did all of this.
(In reply to Colin Walters from comment #2) > I can't think of a situation where it'd be a real world problem but I think > at some point things would be simpler if we just had a static > _gutils_init_global_state() that did all of this. We used to have that, but I changed it since it meant that calling a function like g_get_user_cache_dir() also did things like parsing /etc/passwd to find out the user's realname. I think that nesting onces like this is not really a problem... and not really a source of any amount of complexity. Thanks for the review.
Attachment 323436 [details] pushed as 7c6141a - g_get_user_runtime_dir(): ensure directory exists
*** Bug 743836 has been marked as a duplicate of this bug. ***