diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-10-21 22:02:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-21 22:02:57 +0200 |
commit | d2591a54335424263374a919d485712e5b8aa093 (patch) | |
tree | 342678abd4e02bee73a987017e1acfe04fb0d41e | |
parent | d3520de6338dd1bce2dd1d51847e064e5299f63e (diff) | |
parent | fa9982b87ece21baafa08e0c17ca935ce29d7022 (diff) | |
download | podman-d2591a54335424263374a919d485712e5b8aa093.tar.gz podman-d2591a54335424263374a919d485712e5b8aa093.tar.bz2 podman-d2591a54335424263374a919d485712e5b8aa093.zip |
Merge pull request #4309 from giuseppe/write-storage-overrides
rootless: write storage overrides to the conf file
-rw-r--r-- | libpod/runtime.go | 31 | ||||
-rw-r--r-- | pkg/util/utils.go | 2 |
2 files changed, 19 insertions, 14 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index 107e8e3d0..8f145a809 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -509,6 +509,17 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. return nil, err } + // storage.conf + storageConfFile, err := storage.DefaultConfigFile(rootless.IsRootless()) + if err != nil { + return nil, err + } + + createStorageConfFile := false + if _, err := os.Stat(storageConfFile); os.IsNotExist(err) { + createStorageConfFile = true + } + defRunConf, err := defaultRuntimeConfig() if err != nil { return nil, err @@ -683,27 +694,21 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options .. } if rootless.IsRootless() && configPath == "" { - configPath, err := getRootlessConfigPath() - if err != nil { - return nil, err - } - - // storage.conf - storageConfFile, err := storage.DefaultConfigFile(rootless.IsRootless()) - if err != nil { - return nil, err - } - if _, err := os.Stat(storageConfFile); os.IsNotExist(err) { + if createStorageConfFile { if err := util.WriteStorageConfigFile(&runtime.config.StorageConfig, storageConfFile); err != nil { return nil, errors.Wrapf(err, "cannot write config file %s", storageConfFile) } } + configPath, err := getRootlessConfigPath() + if err != nil { + return nil, err + } if configPath != "" { - if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil { + if err := os.MkdirAll(filepath.Dir(configPath), 0711); err != nil { return nil, err } - file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) if err != nil && !os.IsExist(err) { return nil, errors.Wrapf(err, "cannot open file %s", configPath) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 0190b106d..d9a84e4e5 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -318,7 +318,7 @@ func WriteStorageConfigFile(storageOpts *storage.StoreOptions, storageConf strin if err := os.MkdirAll(filepath.Dir(storageConf), 0755); err != nil { return err } - storageFile, err := os.OpenFile(storageConf, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + storageFile, err := os.OpenFile(storageConf, os.O_RDWR|os.O_TRUNC, 0600) if err != nil { return errors.Wrapf(err, "cannot open %s", storageConf) } |