summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2019-03-17 10:44:04 +0100
committerGiuseppe Scrivano <gscrivan@redhat.com>2019-03-17 10:45:51 +0100
commit232b46a3741267d8dd77a81196699d551c7a682e (patch)
tree3a79d335893864476a619f459131b6c3bbeb6c3d /libpod/runtime.go
parentea0b36bcbb047634944f8fe9693db03bdf7c6a90 (diff)
downloadpodman-232b46a3741267d8dd77a81196699d551c7a682e.tar.gz
podman-232b46a3741267d8dd77a81196699d551c7a682e.tar.bz2
podman-232b46a3741267d8dd77a81196699d551c7a682e.zip
utils: split generation and writing of storage.conf
split the generation for the default storage.conf and when we write it if not existing for a rootless user. This is necessary because during the startup we might be overriding the default configuration through --storage-driver and --storage-opt, that would not be written down to the storage.conf file we generated. Closes: https://github.com/containers/libpod/issues/2659 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go30
1 files changed, 20 insertions, 10 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index f7ca6b135..b3b75d791 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -505,17 +505,27 @@ func newRuntimeFromConfig(userConfigPath string, options ...RuntimeOption) (runt
return nil, errors.Wrapf(err, "error configuring runtime")
}
}
- 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 rootlessConfigPath != "" {
+ // storage.conf
+ storageConfFile := util.StorageConfigFile()
+ if _, err := os.Stat(storageConfFile); os.IsNotExist(err) {
+ if err := util.WriteStorageConfigFile(&runtime.config.StorageConfig, storageConfFile); err != nil {
+ return nil, errors.Wrapf(err, "cannot write config file %s", storageConfFile)
+ }
}
- if err == nil {
- defer file.Close()
- enc := toml.NewEncoder(file)
- if err := enc.Encode(runtime.config); err != nil {
- os.Remove(rootlessConfigPath)
+
+ if !foundConfig {
+ 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)
+ }
}
}
}