-
Notifications
You must be signed in to change notification settings - Fork 46
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
Feature/xdg base dir 2 #68
Feature/xdg base dir 2 #68
Conversation
e699b7b
to
4ae7de2
Compare
4ae7de2
to
ce184f9
Compare
ce184f9
to
f8d8c28
Compare
Hi, thanks for opening this. I haven't had a chance to test yet, but this appears like it would be backwards-breaking in that new versions of Packer will look in a new place and error if the XDG_CACHE_HOME env var exists, but the config file isn't there. I think to preserve backwards compatability it would be better to first check for the config in the XDG_CACHE_HOME and then fall back to checking the old path if nothing is discovered in XDG_CACHE_HOME. |
@SwampDragons I updated PR to check for XDG_CONFIG_HOME env car and for packer configuration there before defaulting back to old location. I'm assuming for the cache it does not matter the location as it's a cache. Please let me know if there's anything I should change and if there is a way to automate the testing of this. |
@teddylear bad update,
I think that you must check if old config dir exists and in this case use it, if not, use XDG. |
@SwampDragons I just want to confirm the behavior that we want here. Do we want the behavior listed on the issue that @ogarcia is suggesting with:
Or the behavior I believe your last comment suggests which is:
I'm assuming for the cache we do not mind where this is placed as it's a cache. Please let me know how to proceed. |
@teddylear you forgot one step:
With this implementation, the new users have XDG, and old ones can delete default location or move current config to XDG to have it. |
I think either mine as you restated it, or ogarcia's work. I'd originally skipped the "check home, then xdg" because I figure if users have a packer config in the xdg-set location it's intentional and should be used, but I can see the benefit of keeping pure backwards compat. |
@SwampDragons the main reason of perform check before is that all Linux/MacOS/Derivatives users are using XDG because is a standard (even if the In the other hand, using your approach for a user who was not configuration, if the app need to create something in its config directory will use default dir instead of |
I have updated with @ogarcia suggestion. Please let me know if there is anything to update or change. |
@teddylear mutch better! But you must fix
And must be:
Or use same logic that |
@ogarcia I believe I have updated with the desired logic. |
packer/cache_config_unix.go
Outdated
defaultConfigFileDir = filepath.Join(xdgCacheHome, "packer") | ||
} else { | ||
homeDir := os.Getenv("HOME") | ||
defaultConfigFileDir = filepath.Join(homeDir, ".cache") |
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.
You miss add packer here.
defaultConfigFileDir = filepath.Join(homeDir, ".cache", "packer")
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.
Updated for cache and config.
pathing/config_file_unix.go
Outdated
log.Printf("Old default config directory found: %s", dir) | ||
} else if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" { | ||
log.Printf("Detected xdg config directory from env var: %s", xdgConfigHome) | ||
dir = xdgConfigHome |
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.
Here is miss the packer too
dir = filepath.Join(xdgConfigHome, "packer")
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.
Updated
…DG_CONFIG_HOME/packer
@teddylear Great work! IMHO it's ready to merge 😉 |
@SwampDragons This is ready to review, please let me know if you have any ideas around automating tests for this. |
sorry, I'm slammed. I'll try to take a look soon. |
// | ||
// CachePath can error in case it cannot find the cwd. | ||
// When the directory is not absolute, CachePath will try to make a | ||
// a cache depending on the operating system. | ||
// |
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.
👋🏼
Could you please update the examples down here in this list depending on the OS ? That would make it easier for me. 🙂
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.
Updated.
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.
Super awesome, thanks.
packer/cache_test.go
Outdated
"testing" | ||
) | ||
|
||
func TestCachePath(t *testing.T) { |
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.
Why removing the tests ? I think it would be better to update them.
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 mentioned above, I'm having issues with creating tests with each path being different depending on the OS. If you have any examples of how to do this I would be glad to update as I tried to update the tests in place but hit a wall making them work for without needing to know the OS.
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.
Because the behaviors differ between OS, you will have to create tests that test things under unix and under windows. One way to fix this would be to check using runtime.GOOS == "windows"
, may be the table tests could be different depending on the os type ?
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.
Updated to make different test files depending on OS similar to the OS specific cache and config files.
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.
Super good ! Thanks.
Co-authored-by: Adrien Delorme <azr@users.noreply.github.com>
Co-authored-by: Adrien Delorme <azr@users.noreply.github.com>
comments. Adding comment for how the cache configuration works.
@azr Addressed previous comments. Please let me know if there is anything else to updates. |
// reset env | ||
packerCacheDir := os.Getenv("PACKER_CACHE_DIR") | ||
os.Setenv("PACKER_CACHE_DIR", "") | ||
defer func() { | ||
os.Setenv("PACKER_CACHE_DIR", packerCacheDir) | ||
}() | ||
|
||
xdgCacheHomeDir := os.Getenv("XDG_CACHE_HOME") | ||
os.Setenv("XDG_CACHE_HOME", "") | ||
defer func() { | ||
os.Setenv("XDG_CACHE_HOME", xdgCacheHomeDir) | ||
}() |
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.
Super nice !
// For Unix: | ||
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir() => "$HOME/cache/packer" | ||
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "$HOME/cache/packer/foo" | ||
// PACKER_CACHE_DIR="bar", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "./bar/foo | ||
// PACKER_CACHE_DIR="/home/there", XDG_CONFIG_HOME="", Default_config CacheDir("foo", "bar") => "/home/there/foo/bar |
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.
I like these new examples !
What will Default_config
stand for here ?
Do you think we should add something for XDG_CONFIG_HOME
too ?
// For Unix: | |
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir() => "$HOME/cache/packer" | |
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "$HOME/cache/packer/foo" | |
// PACKER_CACHE_DIR="bar", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "./bar/foo | |
// PACKER_CACHE_DIR="/home/there", XDG_CONFIG_HOME="", Default_config CacheDir("foo", "bar") => "/home/there/foo/bar | |
// For Unix: | |
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir() => "$HOME/cache/packer" | |
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "$HOME/cache/packer/foo" | |
// PACKER_CACHE_DIR="bar", XDG_CONFIG_HOME="", Default_config CacheDir("foo") => "./bar/foo | |
// PACKER_CACHE_DIR="/home/there", XDG_CONFIG_HOME="", Default_config CacheDir("foo", "bar") => "/home/there/foo/bar | |
// PACKER_CACHE_DIR="", XDG_CONFIG_HOME="/home/there", Default_config CacheDir("foo", "bar") => "/home/there/foo/bar |
Super awesome, thanks for bearing with us @teddylear, I just want to say that this LGTM in terms of code and I just had a question/suggestion on docs. |
Thanks for this! |
Setting the 'PACKER_CONFIG_DIR
and
PACKER_CONFIG_DIR` to use the default XDG spec for unix systems. Not sure of the best way of testing these changes as they are operating system specific for the paths. Because of this I removed tests for cache directory as they changed depending on the operating system. If you have any advice for how to add tests for these please let me know!Addresses: hashicorp/packer#9007