Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing build information for version if not embedded with build script #701

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions init_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func isDir(dir string) error {
// In reverse mode, we create .gocryptfs.reverse.conf and the directory does
// not need to be empty.
func initDir(args *argContainer) {
initGIT()

var err error
if args.reverse {
_, err = os.Stat(args.config)
Expand Down
48 changes: 48 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/debug"
"strconv"
"strings"

Expand Down Expand Up @@ -36,6 +37,51 @@ var BuildDate = "0000-00-00"
// raceDetector is set to true by race.go if we are compiled with "go build -race"
var raceDetector bool

func initGIT() {
bi, ok := debug.ReadBuildInfo()
if !ok {
return
}
if strings.HasPrefix(GitVersion, `[`) {
GitVersion = bi.Main.Version
var gitDate string
var gitDirty bool
for _, item := range bi.Settings {
switch item.Key {
case "vcs.revision":
GitVersion = item.Value
case "vcs.time":
gitDate = item.Value
gitDate = strings.Map(func(r rune) rune {
switch {
case r >= '0' && r <= '9':
return r
default:
return -1
}
}, gitDate)
case "vcs.modified":
gitDirty, _ = strconv.ParseBool(item.Value)
}
}
if len(gitDate) > 0 {
GitVersion = gitDate + "-" + GitVersion
}
if gitDirty {
GitVersion = GitVersion + " (dirty)"
}
}
const fuseModule = `github.com/hanwen/go-fuse/v2`

if strings.HasPrefix(GitVersionFuse, `[`) {
for _, item := range bi.Deps {
if item.Path == fuseModule {
GitVersionFuse = item.Version
}
}
}
}

// loadConfig loads the config file `args.config` and decrypts the masterkey,
// or gets via the `-masterkey` or `-zerokey` command line options, if specified.
func loadConfig(args *argContainer) (masterkey []byte, cf *configfile.ConfFile, err error) {
Expand Down Expand Up @@ -140,6 +186,8 @@ func changePassword(args *argContainer) {
// printVersion prints a version string like this:
// gocryptfs v1.7-32-gcf99cfd; go-fuse v1.0.0-174-g22a9cb9; 2019-05-12 go1.12 linux/amd64
func printVersion() {
initGIT()

var tagsSlice []string
if stupidgcm.BuiltWithoutOpenssl {
tagsSlice = append(tagsSlice, "without_openssl")
Expand Down