Skip to content

Commit 2ce6cc3

Browse files
committed
Makefile and version information
1 parent fe3d14d commit 2ce6cc3

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
all: clean linux
22

3+
VERSION=`git describe --tags --always --dirty)`
4+
BUILD_TIME=`date +%FT%T%z`
5+
LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
6+
37
init:
48
go get ./...
59

610
linux: init
7-
GOOS=linux GOARCH=amd64 go build -o btrdedup .
11+
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o btrdedup .
812

913
clean:
1014
-rm -f btrdedup

main.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ const (
2020
minSize int64 = 4 * 1024
2121
)
2222

23+
var (
24+
version = "undefined"
25+
buildTime = "unknown"
26+
)
27+
2328
type context struct {
2429
pathstore storage.PathStorage
25-
stats *storage.Statistics
26-
state storage.DedupInterface
30+
stats *storage.Statistics
31+
state storage.DedupInterface
2732
}
2833

2934
// readDirNames reads the directory named by dirname
@@ -168,14 +173,14 @@ func submitForDedup(ctx context, files []*storage.FileInformation, noact bool) {
168173
filenames[i] = ctx.pathstore.FilePath(file.Path)
169174
}
170175
if sameOffset {
171-
log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files)-1)
176+
log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files) - 1)
172177
return
173178
}
174179
if !noact {
175-
log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files)-1)
180+
log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files) - 1)
176181
Dedup(filenames, 0, uint64(size))
177182
} else {
178-
log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files)-1)
183+
log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files) - 1)
179184
}
180185
}
181186

@@ -255,13 +260,19 @@ func main() {
255260
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE-OR-DIR]...\n", os.Args[0])
256261
flag.PrintDefaults()
257262
}
263+
showVersion := flag.Bool("version", false, "show version information and exits")
258264
noact := flag.Bool("noact", false, "if provided, the tool will only scan and log results, but not actually deduplicate")
259265
lowmem := flag.Bool("lowmem", false, "if provided, the tool will use much less memory by using temporary files and the external sort command")
260266
nopb := flag.Bool("nopb", false, "if provided, the tool will not show the progress bar")
261267
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
262268
memprofile := flag.String("memprofile", "", "write memory profile to this file")
263269
flag.Parse()
264270

271+
if *showVersion {
272+
fmt.Printf("btrdedup version '%s' built at '%s'\n", version, buildTime)
273+
return
274+
}
275+
265276
if *cpuprofile != "" {
266277
f, err := os.Create((*cpuprofile) + ".prof")
267278
if err != nil {

0 commit comments

Comments
 (0)