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

Support XDG_DATA_HOME #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Support XDG_DATA_HOME #168

wants to merge 1 commit into from

Conversation

jjcarstens
Copy link
Contributor

Resolves #120

@fhunleth
Copy link
Contributor

I wouldn't expect us to dump Nerves hub files into the root of $XDG_DATA_HOME or am I misreading?

@jjcarstens
Copy link
Contributor Author

Ooo. Right. I need to make a subdir

@jjcarstens jjcarstens force-pushed the data-home branch 2 times, most recently from f1b23de to 035a308 Compare December 22, 2020 19:08
@jjcarstens
Copy link
Contributor Author

Fixed. Its following the pattern of Nerves a bit. We can be more aggressive in following XDG standard here if we want as to not default .nerves-hub, or make that for a bigger release like we have done in other places. I'm indifferent.

@fhunleth
Copy link
Contributor

I think that Nerves suffers from XDG_DATA_HOME apathy: we know it's the right thing to do, but no one cares enough to change it, and it is a breaking change to people who have XDG_DATA_HOME defined. I almost wonder if we've painted ourselves into a corner and if someone already has a ~/.nerves-hub directory that we should use it to avoid confusing them. Or give them a warning and tell them to type mv ~/.nerves-hub $XDG_DATA_HOME/nerves-hub. Ugh.

@jjcarstens
Copy link
Contributor Author

Okay, I think I like how this is working. Application and env var get precedence. If it comes to the default and ~/.nerves-hub exists but the default doesn't, then it will fail with an error to give a chance for quick migration.

The only other thing to consider is if we want to travers XDG_DATA_DIRS looking for our possible config and attempt to use that. I feel like this might be a bit overkill, but...maybe thats more complete for the standard?

def home_dir() do
from_config = Application.get_env(:nerves_hub_cli, :home_dir)
from_env = System.get_env("NERVES_HUB_HOME")
xdg_home_nh = :filename.basedir(:user_data, "nerves-hub", %{os: :linux})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
xdg_home_nh = :filename.basedir(:user_data, "nerves-hub", %{os: :linux})
xdg_home_nh = :filename.basedir(:user_data, "nerves-hub")

It seems like we should trust whatever basedir tells us that we should use for storing data so that this does the right thing on OSX. I "think" that renaming the variables to remove the XDG and updating the error text to refer to this as the user data directory below is what's needed to make this generic.

I.e., the same logic can still be used:

  1. Use Application.get_env(:nerves_hub_cli, :home_dir)
  2. Use $NERVES_HUB_HOME
  3. If ~/.nerves-hub and not the :user_data location, tell the user to move the directory
  4. Use the :user_data location

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

Successfully merging this pull request may close these issues.

Follow XDG specification for config/settings storage
2 participants