From 2ce6cc3240b2a267c6fb285fb51d1fb85acda433 Mon Sep 17 00:00:00 2001 From: Bert Baron Date: Tue, 20 Jun 2017 11:11:58 +0200 Subject: [PATCH] Makefile and version information --- Makefile | 6 +++++- main.go | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 2ef8787..8acb8c6 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ all: clean linux +VERSION=`git describe --tags --always --dirty)` +BUILD_TIME=`date +%FT%T%z` +LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}" + init: go get ./... linux: init - GOOS=linux GOARCH=amd64 go build -o btrdedup . + GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o btrdedup . clean: -rm -f btrdedup diff --git a/main.go b/main.go index 488e82d..999780e 100644 --- a/main.go +++ b/main.go @@ -20,10 +20,15 @@ const ( minSize int64 = 4 * 1024 ) +var ( + version = "undefined" + buildTime = "unknown" +) + type context struct { pathstore storage.PathStorage - stats *storage.Statistics - state storage.DedupInterface + stats *storage.Statistics + state storage.DedupInterface } // readDirNames reads the directory named by dirname @@ -168,14 +173,14 @@ func submitForDedup(ctx context, files []*storage.FileInformation, noact bool) { filenames[i] = ctx.pathstore.FilePath(file.Path) } if sameOffset { - log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files)-1) + log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files) - 1) return } if !noact { - log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files)-1) + log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files) - 1) Dedup(filenames, 0, uint64(size)) } else { - log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files)-1) + log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files) - 1) } } @@ -255,6 +260,7 @@ func main() { fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE-OR-DIR]...\n", os.Args[0]) flag.PrintDefaults() } + showVersion := flag.Bool("version", false, "show version information and exits") noact := flag.Bool("noact", false, "if provided, the tool will only scan and log results, but not actually deduplicate") lowmem := flag.Bool("lowmem", false, "if provided, the tool will use much less memory by using temporary files and the external sort command") nopb := flag.Bool("nopb", false, "if provided, the tool will not show the progress bar") @@ -262,6 +268,11 @@ func main() { memprofile := flag.String("memprofile", "", "write memory profile to this file") flag.Parse() + if *showVersion { + fmt.Printf("btrdedup version '%s' built at '%s'\n", version, buildTime) + return + } + if *cpuprofile != "" { f, err := os.Create((*cpuprofile) + ".prof") if err != nil {