Check if GID is already the group if so no need to chown

This commit is contained in:
Laurence 2023-07-26 10:47:12 +01:00
parent 9136f02d4c
commit c7cef1773e
No known key found for this signature in database
GPG key ID: B053BEE3478E8FEF

View file

@ -9,6 +9,7 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"unicode"
"github.com/AlecAivazis/survey/v2"
@ -400,8 +401,12 @@ func checkGroups(forceYes *bool) (*user.Group, error) {
if err != nil {
return dockerGroup, fmt.Errorf("unable to convert group ID to int: %s", err)
}
if err := os.Chown(csConfig.DbConfig.DbPath, 0, intID); err != nil {
return dockerGroup, fmt.Errorf("unable to chown sqlite db file '%s': %s", csConfig.DbConfig.DbPath, err)
if stat, err := os.Stat(csConfig.DbConfig.DbPath); err == nil {
if uint32(intID) != stat.Sys().(*syscall.Stat_t).Gid {
if err := os.Chown(csConfig.DbConfig.DbPath, 0, intID); err != nil {
return dockerGroup, fmt.Errorf("unable to chown sqlite db file '%s': %s", csConfig.DbConfig.DbPath, err)
}
}
}
return dockerGroup, nil
}