rootless: create storage.conf when it doesn't exist
@@ -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
