Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Use XDG directory for cache #5787

Closed
wants to merge 2 commits into from
Closed

Use XDG directory for cache #5787

wants to merge 2 commits into from

Conversation

valeth
Copy link

@valeth valeth commented Jun 18, 2017

What was the end-user problem that led to this PR?

Bundler was storing user cache in the user's home directory.
Issue: #4333

What is your fix for the problem, implemented in this PR?

Store cache in XDG_CACHE_HOME if ~/.bundle/cache does not exist.
Otherwise continue to use the legacy directory.

Falls back to ~/.bundle/cache if the directory exists.
@colby-swandale
Copy link
Member

Thanks for opening a PR and helping make Bundler better 🎉. This PR is missing tests, we will need some before we considering merging this.

@valeth
Copy link
Author

valeth commented Jun 19, 2017

Added tests for xdg_home and user_cache methods.

Still not that experienced with rspec, so any improvements are welcome.

end

before(:each) do
ENV.delete("XDG_CACHE_HOME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be necessary, the spec helper already resets ENV before each test

@indirect
Copy link
Member

@valeth can you provide your reasoning for why this PR is an improvement?

Today, all possible state that Bundler could write fall either into an application at .bundle or the user's home directory at .bundle. The config files are stored completely symmetrically, at .bundle/config. Cache created by Bundler is easy to find and easy to delete if needed, thanks to everything being inside the same directory.

Why would using XDG directories to scatter Bundler-created files across many directories be an improvement?

@colby-swandale
Copy link
Member

ping @valeth

@valeth
Copy link
Author

valeth commented Jun 28, 2017

@indirect
I think it is an improvement because it keeps the user's cache files in one place. So if the use wants to delete all cached data for his applications he just needs to delete one single directory, instead of digging through many directories for every program he wants to clear the cache for.

It would also make backing up configurations easier (if this would be expanded to also handle the configuration file), because you only need to backup one directory to save all your configuration.

Git uses a similar approach, they use the file at $XDG_CONFIG_HOME/git/config if it exists or look for ~/.gitconfig otherwise.

@indirect
Copy link
Member

@valeth I can understand the argument, but I don't think I'm convinced by it. Very few popular open-source utilities support XDG for either cache or config. Very few users set $XDG_CONFIG_HOME, and very few users ask for XDG support. In the 7 years since Bundler 1.0 was released, I only remember 2-3 requests for XDG support, which makes me think this feature will add complexity for everyone while benefiting almost no one.

I'm open to the possibility of allowing the user_bundle_path to be configured via an environment variable, but I don't think XDG-specific support is a good use of our extremely limited maintenance time.

@valeth
Copy link
Author

valeth commented Jun 28, 2017

Making the bundle path configurable would be good enough for me, as long as I can stash the files somewhere that isn't my home directory I'm fine with it.

@valeth valeth closed this Jun 28, 2017
bundlerbot added a commit that referenced this pull request Sep 18, 2017
Allow user to override ~/.bundle with environment variables

### What was the end-user problem that led to this PR?

As in #4333, users wanted a way to make Bundler respect the XDG specification.

### What was your diagnosis of the problem?

The directory `~/.bundle` was hard-coded and could not be configured.

### What is your fix for the problem, implemented in this PR?

Allow users to configure `~/.bundle` and its relevant sub-directories by setting environment variables. The environment variables and their fallbacks are as follows:

| variable | fallback if unset |
|---|---|
| `BUNDLE_USER_HOME` | `$HOME/.bundle` |
| `BUNDLE_USER_CACHE`  | `$BUNDLE_USER_HOME/cache` |
| `BUNDLE_USER_CONFIG` | `$BUNDLE_USER_HOME/config` |
| `BUNDLE_USER_PLUGIN` | `$BUNDLE_USER_HOME/plugin` |

### Why did you choose this fix out of the possible options?

Unlike #5787, This solution is not specific to the XDG specification. Users have all kinds of setups, and this is a very general system for allowing them to configure their development machines however they need. It tries to keep all files created by Bundler in the same place (as per #5787 (comment)), but allows the user to override that convention _if they really want to and they know what they are doing_.

If they want to use XDG for everything, they can do it by explicitly setting the `BUNDLE_USER_*` variables to the equivalent `XDG_DATA_*`. If they just want to get `.bundle` out of their home directory, they can do it by setting `BUNDLE_USER_HOME` and don't have to mess with the more specific env variables if they don't want to.

To me, this solution strikes the right balance between "fine-grained control for power users" and "simple, sane defaults for everyone else".

Please let me know if my tests can be improved. My only Ruby experience so far has been writing Homebrew formulas and configuring Jekyll, so I'm sure I have a lot to learn.
colby-swandale pushed a commit that referenced this pull request Oct 9, 2018
Allow user to override ~/.bundle with environment variables

### What was the end-user problem that led to this PR?

As in #4333, users wanted a way to make Bundler respect the XDG specification.

### What was your diagnosis of the problem?

The directory `~/.bundle` was hard-coded and could not be configured.

### What is your fix for the problem, implemented in this PR?

Allow users to configure `~/.bundle` and its relevant sub-directories by setting environment variables. The environment variables and their fallbacks are as follows:

| variable | fallback if unset |
|---|---|
| `BUNDLE_USER_HOME` | `$HOME/.bundle` |
| `BUNDLE_USER_CACHE`  | `$BUNDLE_USER_HOME/cache` |
| `BUNDLE_USER_CONFIG` | `$BUNDLE_USER_HOME/config` |
| `BUNDLE_USER_PLUGIN` | `$BUNDLE_USER_HOME/plugin` |

### Why did you choose this fix out of the possible options?

Unlike #5787, This solution is not specific to the XDG specification. Users have all kinds of setups, and this is a very general system for allowing them to configure their development machines however they need. It tries to keep all files created by Bundler in the same place (as per #5787 (comment)), but allows the user to override that convention _if they really want to and they know what they are doing_.

If they want to use XDG for everything, they can do it by explicitly setting the `BUNDLE_USER_*` variables to the equivalent `XDG_DATA_*`. If they just want to get `.bundle` out of their home directory, they can do it by setting `BUNDLE_USER_HOME` and don't have to mess with the more specific env variables if they don't want to.

To me, this solution strikes the right balance between "fine-grained control for power users" and "simple, sane defaults for everyone else".

Please let me know if my tests can be improved. My only Ruby experience so far has been writing Homebrew formulas and configuring Jekyll, so I'm sure I have a lot to learn.

(cherry picked from commit e6cc7a2)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants