diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2018-11-13 09:57:46 +0100 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2018-11-19 12:11:06 +0100 |
commit | 937eb8413c24392e6c2d5818bfa2ddddf8e84b95 (patch) | |
tree | 8ea30a8112a6e39147dd69953523214055ac0b3d /pkg/util | |
parent | a6aca6d106192a577ea1f2b1c0d82ddb5c73c2bc (diff) | |
download | podman-937eb8413c24392e6c2d5818bfa2ddddf8e84b95.tar.gz podman-937eb8413c24392e6c2d5818bfa2ddddf8e84b95.tar.bz2 podman-937eb8413c24392e6c2d5818bfa2ddddf8e84b95.zip |
rootless: create storage.conf when it doesn't exist
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'pkg/util')
-rw-r--r-- | pkg/util/utils.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 3b43489b2..c5ba38b9f 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -9,6 +9,7 @@ import ( "strings" "syscall" + "github.com/BurntSushi/toml" "github.com/containers/image/types" "github.com/containers/libpod/pkg/rootless" "github.com/containers/storage" @@ -296,6 +297,18 @@ func GetDefaultStoreOptions() (storage.StoreOptions, error) { storageConf := filepath.Join(os.Getenv("HOME"), ".config/containers/storage.conf") if _, err := os.Stat(storageConf); err == nil { 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 |