1
0
Fork 0
mirror of https://github.com/Mic92/sops-nix.git synced 2024-12-14 11:57:52 +00:00

fix(darwin): RuntimeDir trailing slash

In later versions of macOS (e.g. Ventura), the command used to get a
runtime directory (e.g. `getconf DARWIN_USER_TEMP_DIR`) returns a
trailing slash.

When using a configuration like:

```
sops.defaultSecretsMountPoint = "%r/secrets.d";
```

The final path is going to contain a double slash in the suffix of the
path, an example:

```
/var/<random>/<hash>//secrets.d
```

This commit ensures that the runtime dir will get the trailing '/'
character removed.
This commit is contained in:
Roman Gonzalez 2023-06-21 12:48:31 -07:00 committed by mergify[bot]
parent 4ce3cc3428
commit 2ff6973350

View file

@ -15,13 +15,13 @@ import (
)
func RuntimeDir() (string, error) {
// TODO this could be garbage collected on a 3d basis
out, err := exec.Command("getconf", "DARWIN_USER_TEMP_DIR").Output()
// TODO this could be garbage collected on a 3d basis
out, err := exec.Command("getconf", "DARWIN_USER_TEMP_DIR").Output()
rundir := strings.TrimRight(string(out[:]), " \t\n")
if err != nil {
return "", fmt.Errorf("Cannot get DARWIN_USER_TEMP_DIR: %v", err)
return "", fmt.Errorf("Cannot get DARWIN_USER_TEMP_DIR: %v", err)
}
return rundir, nil
return strings.TrimSuffix(rundir, "/"), nil
}
func SecureSymlinkChown(symlinkToCheck string, expectedTarget string, owner, group int) error {