mirror of https://github.com/containers/podman.git
Merge pull request #1806 from giuseppe/rootless-create-default-files
rootless: create user conf files when they don't exist
This commit is contained in:
commit
64a29e383b
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,11 @@ func GetRegistries() ([]string, error) {
|
||||||
func GetInsecureRegistries() ([]string, error) {
|
func GetInsecureRegistries() ([]string, error) {
|
||||||
registryConfigPath := ""
|
registryConfigPath := ""
|
||||||
|
|
||||||
|
if rootless.IsRootless() {
|
||||||
if _, err := os.Stat(userRegistriesFile); err == nil {
|
if _, err := os.Stat(userRegistriesFile); err == nil {
|
||||||
registryConfigPath = userRegistriesFile
|
registryConfigPath = userRegistriesFile
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
envOverride := os.Getenv("REGISTRIES_CONFIG_PATH")
|
envOverride := os.Getenv("REGISTRIES_CONFIG_PATH")
|
||||||
if len(envOverride) > 0 {
|
if len(envOverride) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,15 @@ func SecretMountsWithUIDGID(mountLabel, containerWorkingDir, mountFile, mountPre
|
||||||
mountFiles = append(mountFiles, []string{OverrideMountsFile, DefaultMountsFile}...)
|
mountFiles = append(mountFiles, []string{OverrideMountsFile, DefaultMountsFile}...)
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
mountFiles = append([]string{UserOverrideMountsFile}, mountFiles...)
|
mountFiles = append([]string{UserOverrideMountsFile}, mountFiles...)
|
||||||
|
_, err := os.Stat(UserOverrideMountsFile)
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
os.MkdirAll(filepath.Dir(UserOverrideMountsFile), 0755)
|
||||||
|
if f, err := os.Create(UserOverrideMountsFile); err != nil {
|
||||||
|
logrus.Warnf("could not create file %s: %v", UserOverrideMountsFile, err)
|
||||||
|
} else {
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mountFiles = append(mountFiles, mountFile)
|
mountFiles = append(mountFiles, mountFile)
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/containers/image/types"
|
"github.com/containers/image/types"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
|
|
@ -296,6 +297,18 @@ func GetDefaultStoreOptions() (storage.StoreOptions, error) {
|
||||||
storageConf := filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf")
|
storageConf := filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf")
|
||||||
if _, err := os.Stat(storageConf); err == nil {
|
if _, err := os.Stat(storageConf); err == nil {
|
||||||
storage.ReloadConfigurationFile(storageConf, &storageOpts)
|
storage.ReloadConfigurationFile(storageConf, &storageOpts)
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
os.MkdirAll(filepath.Dir(storageConf), 0755)
|
||||||
|
file, err := os.OpenFile(storageConf, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return storageOpts, errors.Wrapf(err, "cannot open %s", storageConf)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
enc := toml.NewEncoder(file)
|
||||||
|
if err := enc.Encode(storageOpts); err != nil {
|
||||||
|
os.Remove(storageConf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return storageOpts, nil
|
return storageOpts, nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue