diff --git a/cmd/root.go b/cmd/root.go index 052d6394..ba95bfc2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -159,17 +159,13 @@ func init() { pflags.StringP("logfile", "l", config.LuetCfg.GetLogging().Path, "Logfile path. Empty value disable log to file.") - sameOwner := false - u, err := user.Current() - // os/user doesn't work in from scratch environments + // os/user doesn't work in from scratch environments. + // Check if i can retrieve user informations. + _, err := user.Current() if err != nil { Warning("failed to retrieve user identity:", err.Error()) - sameOwner = true } - if u != nil && u.Uid == "0" { - sameOwner = true - } - pflags.Bool("same-owner", sameOwner, "Maintain same owner on uncompress.") + pflags.Bool("same-owner", config.LuetCfg.GetGeneral().SameOwner, "Maintain same owner on uncompress.") pflags.Int("concurrency", runtime.NumCPU(), "Concurrency") config.LuetCfg.Viper.BindPFlag("logging.color", pflags.Lookup("color")) diff --git a/pkg/config/config.go b/pkg/config/config.go index 950361e0..695020ad 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -231,7 +231,7 @@ func GenDefault(viper *v.Viper) { u, err := user.Current() // os/user doesn't work in from scratch environments - if err != nil || u.Uid == "0" { + if err != nil || (u != nil && u.Uid == "0") { viper.SetDefault("general.same_owner", true) } else { viper.SetDefault("general.same_owner", false)