Skip to content
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

Cache path resolution not optimal: setting cachepath should have priority on the default XDG_CACHE_HOME #843

Open
Oxalin opened this issue Sep 28, 2024 · 3 comments

Comments

@Oxalin
Copy link

Oxalin commented Sep 28, 2024

Current situation

According to the README:
"CachePath (default: ~/.cache)
Path to package cache location. Will be overridden by --xdg-cache-home argument or environment variable XDG_CACHE_HOME, if set."

The actual cache path resolution order is then as follow:

  1. Command line options (--xdg-cache-home)
  2. Environment variables (XDG_CACHE_HOME)
  3. Config setting (cachepath = ..)

This leads to a situation where CachePath is mostly never used, unless XDG_CACHE_HOME is unset.

Proposed change

  1. Command line options (--xdg-cache-home)
  2. Config setting (cachepath = ..)
  3. Environment variables (XDG_CACHE_HOME)

This proposition invert the priority given to XDG_CACHE_HOME with the one given to cachepath.

Reasoning

Under Linux, the XDG_CACHE_HOME is a global variable that is used to set a default base cache path for any and all applications requiring a default path. Since it is set by default, it should be used as a last resort if no other option, either by a config file or a command line option, is set. As it is right now, any value given to cachepath in the config file is never used unless XDG_CACHE_HOME is unset.

Specifying a variable in a config file should be seen as a way to divert from the default XDG_CACHE_HOME value for a given application. Thus, any CachePath value set in the config file should be used over XDG_CACHE_HOME.

Lastly, using the command line option should be treated as a special case where the user wants to use a different path in a specific situation or context (a specific package may need a lot of space, where it will exceed the available space left in a home partition. For example, the cosmic-session package is used to build many sub-packages and the resulting build folder takes).

Using this reasoning, pikaur should:

  • Prioritize the command line option --xdg-cache-home. To be noted: this command line option could/should be renamed to something else, because setting this option for pikaur has nothing to do from that point with the environment variable XDG_CACHE_HOME; it would be better to use a name like "cache-path" or something similar for the command line option;
  • If no command line option is used, it should use the cachepath variable set in its config file;
  • If the cachepath variable is empty, it should use the XDG_CACHE_HOME variable;
  • If XDG_CACHE_HOME is not set (it shouldn't happen, but we may never know), it should use a hardcoded/default value (which could be ~/.cache/).
@actionless
Copy link
Owner

CC @samuel-jimenez

@actionless
Copy link
Owner

@Oxalin feel free to fix it yourself if Samuel wouldn't get back in a while

@Oxalin
Copy link
Author

Oxalin commented Oct 2, 2024

Yes, I'm pretty sure how/where to fix it, but I'm encountering a problem building the code. I've found a bug that I'll fix at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants