mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Merge pull request #4309 from giuseppe/write-storage-overrides
rootless: write storage overrides to the conf file
This commit is contained in:
@ -509,6 +509,17 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
|
|||||||
return nil, err
|
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()
|
defRunConf, err := defaultRuntimeConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -683,27 +694,21 @@ func newRuntimeFromConfig(ctx context.Context, userConfigPath string, options ..
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rootless.IsRootless() && configPath == "" {
|
if rootless.IsRootless() && configPath == "" {
|
||||||
configPath, err := getRootlessConfigPath()
|
if createStorageConfFile {
|
||||||
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 err := util.WriteStorageConfigFile(&runtime.config.StorageConfig, storageConfFile); err != nil {
|
if err := util.WriteStorageConfigFile(&runtime.config.StorageConfig, storageConfFile); err != nil {
|
||||||
return nil, errors.Wrapf(err, "cannot write config file %s", storageConfFile)
|
return nil, errors.Wrapf(err, "cannot write config file %s", storageConfFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configPath, err := getRootlessConfigPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if configPath != "" {
|
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
|
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) {
|
if err != nil && !os.IsExist(err) {
|
||||||
return nil, errors.Wrapf(err, "cannot open file %s", configPath)
|
return nil, errors.Wrapf(err, "cannot open file %s", configPath)
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ func WriteStorageConfigFile(storageOpts *storage.StoreOptions, storageConf strin
|
|||||||
if err := os.MkdirAll(filepath.Dir(storageConf), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(storageConf), 0755); err != nil {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "cannot open %s", storageConf)
|
return errors.Wrapf(err, "cannot open %s", storageConf)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user