Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
e1cf5abd
Commit
e1cf5abd
authored
Jun 17, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't depend on os/user anymore, which requires cgo
parent
39cd5736
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
10 deletions
+103
-10
configfile.go
configfile.go
+9
-0
configfile_unix.go
configfile_unix.go
+45
-0
configfile_windows.go
configfile_windows.go
+37
-0
packer.go
packer.go
+12
-10
No files found.
configfile.go
0 → 100644
View file @
e1cf5abd
package
main
// ConfigFile returns the default path to the configuration file. On
// Unix-like systems this is the ".packerconfig" file in the home directory.
// On Windows, this is the "packer.config" file in the application data
// directory.
func
ConfigFile
()
(
string
,
error
)
{
return
configFile
()
}
configfile_unix.go
0 → 100644
View file @
e1cf5abd
// +build darwin freebsd linux netbsd openbsd
package
main
import
(
"bytes"
"errors"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func
configFile
()
(
string
,
error
)
{
dir
,
err
:=
configDir
()
if
err
!=
nil
{
return
""
,
err
}
return
filepath
.
Join
(
dir
,
".packerconfig"
),
nil
}
func
configDir
()
(
string
,
error
)
{
// First prefer the HOME environmental variable
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
log
.
Printf
(
"Detected home directory from env var: %s"
,
home
)
return
home
,
nil
}
// If that fails, try the shell
var
stdout
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"sh"
,
"-c"
,
"eval echo ~$USER"
)
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
err
}
result
:=
strings
.
TrimSpace
(
stdout
.
String
())
if
result
==
""
{
return
""
,
errors
.
New
(
"blank output"
)
}
return
result
,
nil
}
configfile_windows.go
0 → 100644
View file @
e1cf5abd
// +build windows
package
main
import
(
"path/filepath"
"syscall"
"unsafe"
)
var
(
shell
=
syscall
.
MustLoadDLL
(
"Shell32.dll"
)
getFolderPath
=
shell
.
MustFindProc
(
"SHGetFolderPathW"
)
)
const
CSIDL_APPDATA
=
26
func
configFile
()
(
string
,
error
)
{
dir
,
err
:=
configDir
()
if
err
!=
nil
{
return
""
,
err
}
return
filepath
.
Join
(
dir
,
"packer.config"
),
nil
}
func
configDir
()
(
string
,
error
)
{
b
:=
make
([]
uint16
,
syscall
.
MAX_PATH
)
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx
r
,
_
,
err
:=
getFolderPath
.
Call
(
0
,
CSIDL_APPDATA
,
0
,
0
,
uintptr
(
unsafe
.
Pointer
(
&
b
[
0
])))
if
uint32
(
r
)
!=
0
{
return
""
,
err
}
return
syscall
.
UTF16ToString
(
b
),
nil
}
packer.go
View file @
e1cf5abd
...
...
@@ -9,8 +9,6 @@ import (
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"runtime"
)
...
...
@@ -82,19 +80,23 @@ func loadConfig() (*config, error) {
}
mustExist
:=
true
configFile
:=
os
.
Getenv
(
"PACKER_CONFIG"
)
if
configFile
==
""
{
u
,
err
:=
user
.
Current
()
configFilePath
:=
os
.
Getenv
(
"PACKER_CONFIG"
)
if
configFilePath
==
""
{
var
err
error
configFilePath
,
err
=
configFile
()
mustExist
=
false
if
err
!=
nil
{
return
nil
,
err
log
.
Printf
(
"Error detecing default config file path: %s"
,
err
)
}
}
configFile
=
filepath
.
Join
(
u
.
HomeDir
,
".packerconfig"
)
mustExist
=
false
if
configFilePath
==
""
{
return
&
config
,
nil
}
log
.
Printf
(
"Attempting to open config file: %s"
,
configFile
)
f
,
err
:=
os
.
Open
(
configFile
)
log
.
Printf
(
"Attempting to open config file: %s"
,
configFile
Path
)
f
,
err
:=
os
.
Open
(
configFile
Path
)
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
return
nil
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment