mirror of
https://github.com/containers/podman.git
synced 2025-05-31 15:42:48 +08:00
rootless: create libpod.conf when it doesn't exist
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -264,6 +264,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
|
|
||||||
configPath := ConfigPath
|
configPath := ConfigPath
|
||||||
foundConfig := true
|
foundConfig := true
|
||||||
|
rootlessConfigPath := ""
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
if runtime.config.SignaturePolicyPath == "" {
|
if runtime.config.SignaturePolicyPath == "" {
|
||||||
@ -272,7 +273,10 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
runtime.config.SignaturePolicyPath = newPath
|
runtime.config.SignaturePolicyPath = newPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configPath = filepath.Join(home, ".config/containers/libpod.conf")
|
|
||||||
|
rootlessConfigPath = filepath.Join(home, ".config/containers/libpod.conf")
|
||||||
|
|
||||||
|
configPath = rootlessConfigPath
|
||||||
if _, err := os.Stat(configPath); err != nil {
|
if _, err := os.Stat(configPath); err != nil {
|
||||||
foundConfig = false
|
foundConfig = false
|
||||||
}
|
}
|
||||||
@ -317,6 +321,22 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
if err := makeRuntime(runtime); err != nil {
|
if err := makeRuntime(runtime); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !foundConfig && rootlessConfigPath != "" {
|
||||||
|
os.MkdirAll(filepath.Dir(rootlessConfigPath), 0755)
|
||||||
|
file, err := os.OpenFile(rootlessConfigPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||||
|
if err != nil && !os.IsExist(err) {
|
||||||
|
return nil, errors.Wrapf(err, "cannot open file %s", rootlessConfigPath)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
defer file.Close()
|
||||||
|
enc := toml.NewEncoder(file)
|
||||||
|
if err := enc.Encode(runtime.config); err != nil {
|
||||||
|
os.Remove(rootlessConfigPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return runtime, nil
|
return runtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user