Skip to content

Commit

Permalink
Merge pull request #411 from sylabs/master
Browse files Browse the repository at this point in the history
Merge additional fix to release-3.9 for 3.9.0-rc.3
  • Loading branch information
dtrudg authored Nov 5, 2021
2 parents 55255c7 + 4da1548 commit 88d2c53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ This is a _release candidate_ for SingularityCE 3.9.0
concurrent downloads by default, and is configurable in `singularity.conf` or
via environment variables.

### Bug fixes

- Ensure invalid values passed to `config global --set` cannot lead to an empty
configuration file being written.

## v3.9.0-rc.2 \[2021-10-28\]

This is a _release candidate_ for SingularityCE 3.9.0
Expand Down
27 changes: 19 additions & 8 deletions internal/app/singularity/config_global_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
package singularity

import (
"bytes"
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -38,27 +40,36 @@ func contains(slice []string, val string) bool {
}

func generateConfig(path string, directives singularityconf.Directives, dry bool) error {
out := os.Stdout
// Generate the config structure from our directives
c, err := singularityconf.GetConfig(directives)
if err != nil {
return fmt.Errorf("configuration directive invalid: %w", err)
}

// Write a config file to our in memory buffer
newConfig := new(bytes.Buffer)
if err := singularityconf.Generate(newConfig, "", c); err != nil {
return fmt.Errorf("while generating configuration from template: %w", err)
}

// Dry run = write to Stdout
out := os.Stdout
// Not dry run = create / overwrite existing file, now we know we have valid content
if !dry {
unix.Umask(0)

flags := os.O_CREATE | os.O_TRUNC | unix.O_NOFOLLOW | os.O_RDWR
nf, err := os.OpenFile(path, flags, 0o644)
if err != nil {
return fmt.Errorf("while creating configuration file %s: %s", path, err)
return fmt.Errorf("while creating configuration file %s: %w", path, err)
}
defer nf.Close()
out = nf
}

c, err := singularityconf.GetConfig(directives)
_, err = io.Copy(out, newConfig)
if err != nil {
return err
}

if err := singularityconf.Generate(out, "", c); err != nil {
return fmt.Errorf("while generating configuration from template: %s", err)
return fmt.Errorf("while writing configuration file %s: %w", path, err)
}

return nil
Expand Down

0 comments on commit 88d2c53

Please sign in to comment.