Handle errors from os/user

We use it to generate defaults, if error is found, we imply preserve
permissions
This commit is contained in:
Ettore Di Giacinto
2020-04-11 20:05:56 +02:00
parent 0fe2a8c950
commit f987ee9fa0
2 changed files with 10 additions and 7 deletions

View File

@@ -133,12 +133,14 @@ func init() {
pflags.BoolP("debug", "d", false, "verbose output")
pflags.Bool("fatal", false, "Enables Warnings to exit")
u, err := user.Current()
if err != nil {
Fatal("failed to retrieve user identity:", err.Error())
}
sameOwner := false
if u.Uid == "0" {
u, err := user.Current()
// os/user doesn't work in from scratch environments
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.")