-
Notifications
You must be signed in to change notification settings - Fork 59
Feature/xdg base dir 2 #68
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
Changes from 8 commits
f8d8c28
50d37c5
0155950
2d18051
e436960
1fae0aa
655a261
beaa322
1aee4ae
60ef4e6
281eb19
31918db
006be29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // +build darwin freebsd linux netbsd openbsd solaris | ||
|
|
||
| package packer | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| func getDefaultCacheDir() string { | ||
| var defaultConfigFileDir string | ||
|
|
||
| if xdgCacheHome := os.Getenv("XDG_CACHE_HOME"); xdgCacheHome != "" { | ||
| defaultConfigFileDir = filepath.Join(xdgCacheHome, "packer") | ||
| } else { | ||
|
teddylear marked this conversation as resolved.
Outdated
|
||
| homeDir := os.Getenv("HOME") | ||
| defaultConfigFileDir = filepath.Join(homeDir, ".cache") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You miss add packer here. defaultConfigFileDir = filepath.Join(homeDir, ".cache", "packer")
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated for cache and config. |
||
| } | ||
|
|
||
| return defaultConfigFileDir | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // +build windows | ||
|
|
||
| package packer | ||
|
|
||
| const ( | ||
| defaultConfigFile = "packer_cache" | ||
| ) | ||
|
|
||
| func getDefaultCacheDir() string { | ||
| return defaultConfigFile | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,42 @@ | |
|
|
||
| package pathing | ||
|
|
||
| import ( | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultConfigFile = ".packerconfig" | ||
| defaultConfigDir = ".packer.d" | ||
| ) | ||
|
|
||
| func configDir() (path string, err error) { | ||
| var dir string | ||
| homedir := os.Getenv("HOME") | ||
| if homedir == "" { | ||
| return "", err | ||
| } | ||
|
azr marked this conversation as resolved.
|
||
| if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" { | ||
| log.Printf("Detected config directory from env var: %s", cd) | ||
| dir = filepath.Join(cd, defaultConfigDir) | ||
| } else if hasDefaultConfigFileLocation(homedir) { | ||
| dir = filepath.Join(homedir, defaultConfigDir) | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. Here is miss the packer too dir = filepath.Join(xdgConfigHome, "packer")
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| } else { | ||
| dir = filepath.Join(homedir, ".config") | ||
| } | ||
|
|
||
| return dir, nil | ||
| } | ||
|
|
||
| func hasDefaultConfigFileLocation(homedir string) bool { | ||
| if _, err := os.Stat(filepath.Join(homedir, defaultConfigDir)); err != nil { | ||
| return false | ||
| } | ||
| return true | ||
| } | ||
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.