diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-11-19 08:44:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-19 08:44:57 -0800 |
commit | 64a29e383bb1c12b94a3f6f6be4538f9758d7fb9 (patch) | |
tree | f840ae31f0cb6c7d9ea6579e0b778fe58dd609b2 /pkg/util/utils.go | |
parent | 4eecc8cf70728d733aa8d1c948093d9ae4a334df (diff) | |
parent | 027d6ca6de3644414ee1f847d161184d027e4137 (diff) | |
download | podman-64a29e383bb1c12b94a3f6f6be4538f9758d7fb9.tar.gz podman-64a29e383bb1c12b94a3f6f6be4538f9758d7fb9.tar.bz2 podman-64a29e383bb1c12b94a3f6f6be4538f9758d7fb9.zip |
Merge pull request #1806 from giuseppe/rootless-create-default-files
rootless: create user conf files when they don't exist
Diffstat (limited to 'pkg/util/utils.go')
-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 |