-
Notifications
You must be signed in to change notification settings - Fork 49
Use XDG_CACHE_HOME. #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use XDG_CACHE_HOME. #175
Conversation
Thanks for doing such a thorough job. I've got a few comments and will do a review to discuss. |
contrib/gtktheme/jgmenu-gtktheme.py
Outdated
@@ -56,9 +56,11 @@ def process_line(line): | |||
setconfig("color_title_border", rgb2hex(line)) | |||
|
|||
def cache(themename): | |||
""" save the theme-name to ~/.cache/jgmenu/.last-gtktheme """ | |||
""" save the theme-name to XDG_CACHE_HOME/jgmenu/.last-gtktheme """ | |||
from xdg.BaseDirectory import xdg_cache_home |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing from xdg crashes for me - I obviously do not have the xdg module installed
In order to avoid creating work for distro maintainers (@johnraff ??) I prefer going manual on this one.
Any chance of manually using XDG_CACHE_HOME
if set/non-empty or else use ~/.cache
Traceback (most recent call last):
File "/home/johan/tmp/jgmenu/./contrib/gtktheme/jgmenu-gtktheme.py", line 106, in <module>
main()
File "/home/johan/tmp/jgmenu/./contrib/gtktheme/jgmenu-gtktheme.py", line 74, in main
cache(themename)
File "/home/johan/tmp/jgmenu/./contrib/gtktheme/jgmenu-gtktheme.py", line 60, in cache
from xdg.BaseDirectory import xdg_cache_home
ModuleNotFoundError: No module named 'xdg'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XDG_CACHE_HOME is unset by default in Debian, so a test to only use that envvar if it is set, otherwise reverting to the default $HOME/.cache, would be desirable IMO.
Most of these XDG envvars seem to be unset by default in fact - the user is only expected to set them if they want to use a custom value.
src/cache.c
Outdated
@@ -136,11 +138,18 @@ static void cache_init(void) | |||
die("cache.c: icon_{theme,size} needs to be set"); | |||
cache_location = xmalloc(sizeof(struct sbuf)); | |||
sbuf_init(cache_location); | |||
sbuf_cpy(cache_location, CACHE_LOCATION); | |||
if (access(xdg_cache_home, F_OK) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest: #define DEFAULT_CACHE_LOCATION="~/.cache"
and then
if (xdg_cache_home && *xdg_cache_home) {
sbuf_cpy(cache_location, xdg_cache_home)
} else {
sbuf_cpy(cache_location, DEFAULT_CACHE_LOCATION)
}
sbuf_addstr(cache_location, "jgmenu/icons")
sbuf_expand_tilde.... and so on...
src/icon.c
Outdated
@@ -39,6 +38,8 @@ static struct list_head icon_cache; | |||
|
|||
static struct sbuf icon_theme; | |||
|
|||
extern struct sbuf *cache_location; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed above, I prefer to remove this extern
in favor of a cache_get_dir()
. It's just tidier and seems less like using global variables.
Thanks for the suggestions, I took them into consideration in a second patch. |
Codecov Report
@@ Coverage Diff @@
## master #175 +/- ##
=======================================
Coverage 38.78% 38.78%
=======================================
Files 8 8
Lines 856 856
=======================================
Hits 332 332
Misses 524 524 Continue to review full report at Codecov.
|
Improved the patch. |
Thanks. I'll have a look tomorrow if that's okay. |
I think we could simplify this even further 😄 I suggest the following (although have not tried putting it into code):
That way you can get rid of
Also, in cache_get_dir() you call access() to check for the existance of |
I'm happy to get rid of the following
That would simplify things ever more 😃 |
Good idea, I made some tests and it works fine.
I don't understand here, because we need to test if XDG_CACHE_HOME is set or not. |
I prefer to keep it in case we forgot something and removes it later. |
You can test if the variable is unset and/or empty the the code below - without trying to access the file:
So in our case I'd suggest:
If C is not the language you normally code in I can explain further if helpful 😄 |
👍 |
ok I didn't know about that, thanks. |
cache_icon_get_dir() leaks memory if called more than once - which is the case with the patch. I suggest doing the allocation in If you think it's tidier, it could be broken out into a separate function
There is no need to do anything else in there... the variable |
Closes #174.