Skip to content

Commit

Permalink
Extract isReproducibleBuild() function
Browse files Browse the repository at this point in the history
Signed-off-by: Witek Bedyk <witold.bedyk@suse.com>
  • Loading branch information
witekest committed Aug 1, 2023
1 parent bde52e1 commit c9958f6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/build.go
Expand Up @@ -210,28 +210,32 @@ func getBuildDate() time.Time {
}

func HostFunc() string {
if os.Getenv(sourceDateEpoch) == "" {
if isReproducibleBuild() {
return "reproducible"
} else {
hostname, err := os.Hostname()
if err != nil {
return "unknown-host"
} else {
return hostname
}
} else {
return "reproducible"
}
}

// UserFunc returns the current username.
func UserFunc() (interface{}, error) {
if os.Getenv(sourceDateEpoch) == "" {
if isReproducibleBuild() {
return "reproducible", nil
} else {
// os/user.Current() doesn't always work without CGO
return shellOutput("whoami"), nil
} else {
return "reproducible", nil
}
}

func isReproducibleBuild() bool {
return !(os.Getenv(sourceDateEpoch) == "")
}

// RepoPathFunc returns the repository path.
func RepoPathFunc() interface{} {
return config.Repository.Path
Expand Down

0 comments on commit c9958f6

Please sign in to comment.