Browse Source

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

Laurence 2 years ago
parent
commit
c7cef1773e
1 changed files with 7 additions and 2 deletions
  1. 7 2
      cmd/crowdsec-cli/dashboard.go

+ 7 - 2
cmd/crowdsec-cli/dashboard.go

@@ -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
 }