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

Add method for retrieving XDG config directory #2211

Closed
wants to merge 6 commits into from
Closed

Conversation

TadCordle
Copy link
Contributor

@TadCordle TadCordle commented Jan 3, 2020

Part of #2193. Adds methods for retrieving the XDG_CONFIG_HOME directory, which will hold update-check-related files.

The full paths are:

  • Linux: $HOME/.config/google-cloud-tools-java/jib/
  • Mac: $HOME/Library/Preferences/Google/Jib/
  • Windows: %LOCALAPPDATA%\Google\Jib\Config

One potential issue is that this may end up overlapping with the base image cache directory on windows, so if someone clears their cache without being careful, they may also delete their update check config accidentally.

@TadCordle TadCordle requested a review from a team January 3, 2020 21:03
Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

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

Your point on Windows is a fair one. From what I found, people advocate for a %LOCALAPPDATA%/Vendor/App/<tempLocation>. We should probably also allow checking for settings in their roaming profile in %APPDATA% too.

And the macOS cache directory really should be Library/Caches. Plus we're exporting our org structure by using google-cloud-tools-java, since Chrome uses Google/Chrome (on macOS at least).

String rawOsName = properties.getProperty("os.name");
String osName = rawOsName.toLowerCase(Locale.ENGLISH);

if (osName.contains("linux")) {
Copy link
Member

Choose a reason for hiding this comment

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

We're now duplicating some of this platform-testing logic. Is it worth extracting into separate getOs(properties) method that returns the platform type? (I wish the JRE already provided this.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be a good idea if we ever need it more. But I think with how little logic it actually is, only duplicating in 2 places isn't so bad.

@TadCordle
Copy link
Contributor Author

And the macOS cache directory really should be Library/Caches

Yeah, I wonder if we should think about a way of moving the cache without breaking users.

@loosebazooka
Copy link
Member

loosebazooka commented Jan 6, 2020

I don't think we'd break anyone except those that have some code to auto clear cache. We could do something like: Identify if an old cache exist -- tell the user to delete it

If we do think we should do this, we should do it before 2.0.0

@TadCordle
Copy link
Contributor Author

Filed #2216

@TadCordle
Copy link
Contributor Author

Since we're thinking about changing the cache directory on different platforms, I'll update this PR so the getConfigHome returns the full path to the config for each platform and not just the home (e.g. $XDG_CONFIG_HOME/google-cloud-tools-java/jib rather than just $XDG_CONFIG_HOME). Then maybe make the cache changes in another PR.

*
* <p>For Linux, this is {@code $HOME/.config/google-cloud-tools-java/jib/}.
*
* <p>For Windows, this is {@code %LOCALAPPDATA%\Google\Jib/}.
Copy link
Member

Choose a reason for hiding this comment

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

...\Google\Jib\ (instead of the trailing /)

*/
@VisibleForTesting
static Path getConfigHome(Properties properties, Map<String, String> environment) {
Path windowsSubDirectory = JIB_SUBDIRECTORY_OTHER.resolve("Config");
Copy link
Member

Choose a reason for hiding this comment

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

Why not having windowsSubDirectory as a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's different for cache and config.

LOGGER.warning(applicationSupport + " does not exist");
return xdgPath.resolve(JIB_SUBDIRECTORY_OTHER);
}
return applicationSupport.resolve(JIB_SUBDIRECTORY_OTHER);
Copy link
Member

@chanseokoh chanseokoh Jan 7, 2020

Choose a reason for hiding this comment

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

Looks like this structure is being repeated.

if (linux) {
   return path.resolve(JIB_SUBDIRECTORY_LINUX);
} else if (windows) {
   return path.resolve(windowsSubDirectory);
} else /* if (mac) */ {
   return path.resolve(JIB_SUBDIRECTORY_OTHER);
}

Perhaps this logic can be a separate method, like getConfigHome(getBaseConfigHome(...)) (whatever suitable method names)? If this is indeed repeated, I think factoring this out will make the code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll give it a try.

@TadCordle
Copy link
Contributor Author

Closing in favor of #2218

@TadCordle TadCordle closed this Jan 7, 2020
@TadCordle TadCordle deleted the xdg-config branch January 7, 2020 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants