Drop duplicate code for general.same_owner

This commit is contained in:
Daniele Rondina 2020-05-30 16:51:10 +02:00
parent 341293c403
commit 1d8a6174bb
2 changed files with 5 additions and 9 deletions

View File

@ -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"))

View File

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